PartitionReceiver 接口
定义
This is a logical representation of receiving from a EventHub partition.
A PartitionReceiver is tied to a ConsumerGroup + EventHub Partition combination.
If an epoch based 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.
Multiple receivers per ConsumerGroup + Partition combo can be created using non-epoch receivers.
public interface PartitionReceiver
字段
DEFAULT_PREFETCH_COUNT | |
MAXIMUM_PREFETCH_COUNT | |
MINIMUM_PREFETCH_COUNT | |
NULL_EPOCH |
方法
close() | |
closeSync() | |
getEpoch() |
Get the epoch value that this receiver is currently using for partition ownership. A value of 0 means this receiver is not an epoch-based receiver.
|
getEventPosition() |
Get the EventPosition that corresponds to an EventData which was returned last by the receiver. This value will not be populated, unless the knob setReceiverRuntimeMetricEnabled(boolean value) is set. Note that EventPosition object is initialized using SequenceNumber and other parameters are not set and get will return null.
|
getPartitionId() |
Get EventHubs partition identifier.
|
getReceiveTimeout() | |
getRuntimeInformation() |
Gets the temporal ReceiverRuntimeInformation for this EventHub partition. In general, this information is a representation of, where this PartitionReceiver's end of stream is, at the time getRetrievalTime(). This value will not be populated, unless the knob setReceiverRuntimeMetricEnabled(boolean value) 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.
|
receive(final int maxEventCount) |
Receive a batch of 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"); Iterable{<}EventData{>} 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(); }
|
receiveSync(final int maxEventCount) |
Synchronous version of receive(final int maxEventCount).
|
setReceiveHandler(final PartitionReceiveHandler receiveHandler) |
Register a receive handler that will be called when an event is available. A PartitionReceiveHandler is a handler that allows user to specify a callback for event processing and error handling in a receive pump model.
|
setReceiveHandler(final PartitionReceiveHandler receiveHandler, final boolean invokeWhenNoEvents) |
Register a receive handler that will be called when an event is available. A PartitionReceiveHandler is a handler that allows user to specify a callback for event processing and error handling in a receive pump model.
|
setReceiveTimeout(Duration value) |