public interface PartitionReceiver
A PartitionReceiver
is tied to a ConsumerGroup + EventHub Partition combination.
PartitionReceiver
(i.e., PartitionReceiver.getEpoch != 0) is created, EventHubs service will guarantee only 1 active receiver exists per ConsumerGroup + Partition combo.
This is the recommended approach to create a PartitionReceiver
.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PREFETCH_COUNT |
static int |
MAXIMUM_PREFETCH_COUNT |
static int |
MINIMUM_PREFETCH_COUNT |
static long |
NULL_EPOCH |
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Void> |
close() |
void |
closeSync() |
long |
getEpoch()
Get the epoch value that this receiver is currently using for partition ownership.
|
EventPosition |
getEventPosition()
Get the
EventPosition that corresponds to an EventData which was returned last by the receiver. |
boolean |
getIsOpen()
Determine the current state of the receiver.
|
String |
getPartitionId()
Get EventHubs partition identifier.
|
Duration |
getReceiveTimeout() |
ReceiverRuntimeInformation |
getRuntimeInformation()
Gets the temporal
ReceiverRuntimeInformation for this EventHub partition. |
CompletableFuture<Iterable<EventData>> |
receive(int maxEventCount)
Receive a batch of
EventData 's from an EventHub partition |
default Iterable<EventData> |
receiveSync(int maxEventCount)
Synchronous version of
receive(int) . |
CompletableFuture<Void> |
setReceiveHandler(PartitionReceiveHandler receiveHandler)
Register a receive handler that will be called when an event is available.
|
CompletableFuture<Void> |
setReceiveHandler(PartitionReceiveHandler receiveHandler,
boolean invokeWhenNoEvents)
Register a receive handler that will be called when an event is available.
|
void |
setReceiveTimeout(Duration value) |
static final int MINIMUM_PREFETCH_COUNT
static final int DEFAULT_PREFETCH_COUNT
static final int MAXIMUM_PREFETCH_COUNT
static final long NULL_EPOCH
String getPartitionId()
Duration getReceiveTimeout()
void setReceiveTimeout(Duration value)
boolean getIsOpen()
long getEpoch()
A value of 0 means this receiver is not an epoch-based receiver.
ReceiverRuntimeInformation getRuntimeInformation()
ReceiverRuntimeInformation
for this EventHub partition.
In general, this information is a representation of, where this PartitionReceiver
's end of stream is,
at the time ReceiverRuntimeInformation.getRetrievalTime()
.
This value will not be populated, unless the knob ReceiverOptions.setReceiverRuntimeMetricEnabled(boolean)
is set.
This value will be refreshed every time an EventData
is consumed from PartitionReceiver
.
For ex: if no events have been consumed, then this value is not populated.
EventPosition getEventPosition()
EventPosition
that corresponds to an EventData
which was returned last by the receiver.
This value will not be populated, unless the knob ReceiverOptions.setReceiverRuntimeMetricEnabled(boolean)
is set.
Note that EventPosition object is initialized using SequenceNumber and other parameters are not set and get will return null.
default Iterable<EventData> receiveSync(int maxEventCount) throws EventHubException
receive(int)
.maxEventCount
- maximum number of EventData
's that this call should returnEventData
's from the partition on which this receiver is created. Returns 'null' if no EventData
is present.EventHubException
- if ServiceBus client encountered any unrecoverable/non-transient problems during receive(int)
CompletableFuture<Iterable<EventData>> receive(int maxEventCount)
EventData
's from an EventHub partition
Sample code (sample uses sync version of the api but concept are identical):
EventHubClient client = EventHubClient.createSync("__connection__"); PartitionReceiver receiver = client.createPartitionReceiverSync("ConsumerGroup1", "1"); IterableEventData receivedEvents = receiver.receiveSync(); while (true) { int batchSize = 0; if (receivedEvents != null) { for(EventData receivedEvent: receivedEvents) { System.out.println(String.format("Message Payload: %s", new String(receivedEvent.getBytes(), Charset.defaultCharset()))); System.out.println(String.format("Offset: %s, SeqNo: %s, EnqueueTime: %s", receivedEvent.getSystemProperties().getOffset(), receivedEvent.getSystemProperties().getSequenceNumber(), receivedEvent.getSystemProperties().getEnqueuedTime())); batchSize++; } } System.out.println(String.format("ReceivedBatch Size: %s", batchSize)); receivedEvents = receiver.receiveSync(); }
CompletableFuture<Void> setReceiveHandler(PartitionReceiveHandler receiveHandler)
PartitionReceiveHandler
is a handler that allows user to specify a callback
for event processing and error handling in a receive pump model.receiveHandler
- An implementation of PartitionReceiveHandler
. Setting this handler to null
will stop the receive pump.CompletableFuture<Void> setReceiveHandler(PartitionReceiveHandler receiveHandler, boolean invokeWhenNoEvents)
PartitionReceiveHandler
is a handler that allows user to specify a callback
for event processing and error handling in a receive pump model.receiveHandler
- An implementation of PartitionReceiveHandler
invokeWhenNoEvents
- flag to indicate whether the PartitionReceiveHandler.onReceive(Iterable)
should be invoked when the receive call times outCompletableFuture<Void> close()
void closeSync() throws EventHubException
EventHubException
Copyright © 2019 Microsoft Corporation. All rights reserved.