Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support special @latest (end of stream) filter. #89

Merged
merged 2 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,35 @@ public void setInitialOffsetProvider(Function<String, Object> initialOffsetProvi
{
this.initialOffsetProvider = initialOffsetProvider;
}


/***
* A prefab initial offset provider that starts from the first event available.
*
* How to use this initial offset provider: setInitialOffsetProvider(new EventProcessorOptions.StartOfStreamInitialOffsetProvider());
*/
public class StartOfStreamInitialOffsetProvider implements Function<String, Object>
{
@Override
public Object apply(String t)
{
return PartitionReceiver.START_OF_STREAM;
}
}

/***
* A prefab initial offset provider that starts from the next event that becomes available.
*
* How to use this initial offset provider: setInitialOffsetProvider(new EventProcessorOptions.EndOfStreamInitialOffsetProvider());
*/
public class EndOfStreamInitialOffsetProvider implements Function<String, Object>
{
@Override
public Object apply(String t)
{
return PartitionReceiver.END_OF_STREAM;
}
}

/***
* Returns whether the EventProcessorHost will call IEventProcessor.onEvents() with an empty iterable
* when a receive timeout occurs (true) or not (false).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public final class PartitionReceiver extends ClientEntity implements IReceiverSe
*/
public static final String START_OF_STREAM = "-1";

/**
* This is a constant defined to represent the current end of a partition stream in EventHub.
* This can be used as an offset argument in receiver creation to start receiving from the latest
* event, instead of a specific offset or point in time.
*/
public static final String END_OF_STREAM = "@latest";

private final String partitionId;
private final MessagingFactory underlyingFactory;
private final String eventHubName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.time.Instant;
import java.util.Iterator;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;

import org.junit.After;
Expand Down Expand Up @@ -69,6 +70,18 @@ public void testReceiverStartOfStreamFilters() throws ServiceBusException
}
}

@Test()
public void testReceiverLatestFilter() throws ServiceBusException, ExecutionException, InterruptedException
{
offsetReceiver = ehClient.createReceiverSync(cgName, partitionId, PartitionReceiver.END_OF_STREAM, false);
Iterable<EventData> events = offsetReceiver.receiveSync(100);
Assert.assertTrue(events == null);

TestBase.pushEventsToPartition(ehClient, partitionId, 10).get();
events = offsetReceiver.receiveSync(100);
Assert.assertTrue(events != null && events.iterator().hasNext());
}

@Test()
public void testReceiverOffsetInclusiveFilter() throws ServiceBusException
{
Expand Down