PartitionReceiver Interface
public interface 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.
Field Summary
Modifier and Type | Field and Description |
---|---|
static final int | DEFAULT_PREFETCH_COUNT |
static final int | MAXIMUM_PREFETCH_COUNT |
static final int | MINIMUM_PREFETCH_COUNT |
static final long | NULL_EPOCH |
Method Summary
Modifier and Type | Method and Description |
---|---|
abstract
Completable |
close() |
abstract void | closeSync() |
abstract long |
getEpoch()
Get the epoch value that this receiver is currently using for partition ownership. |
abstract
Event |
getEventPosition()
Get the EventPosition that corresponds to an EventData which was returned last by the receiver. |
abstract boolean |
getIsOpen()
Determine the current state of the receiver. |
abstract String |
getPartitionId()
Get Event |
abstract Duration | getReceiveTimeout() |
abstract
Receiver |
getRuntimeInformation()
Gets the temporal ReceiverRuntimeInformation for this Event |
abstract
Completable |
receive(int maxEventCount)
Receive a batch of EventData's from an Event |
default
Iterable<Event |
receiveSync(int maxEventCount)
Synchronous version of #receive. |
abstract
Completable |
setReceiveHandler(PartitionReceiveHandler receiveHandler)
Register a receive handler that will be called when an event is available. |
abstract
Completable |
setReceiveHandler(PartitionReceiveHandler receiveHandler, boolean invokeWhenNoEvents)
Register a receive handler that will be called when an event is available. |
abstract void | setReceiveTimeout(Duration value) |
Field Details
DEFAULT_PREFETCH_COUNT
public static final int DEFAULT_PREFETCH_COUNT
MAXIMUM_PREFETCH_COUNT
public static final int MAXIMUM_PREFETCH_COUNT
MINIMUM_PREFETCH_COUNT
public static final int MINIMUM_PREFETCH_COUNT
NULL_EPOCH
public static final long NULL_EPOCH
Method Details
close
public abstract CompletableFuture
closeSync
getEpoch
public abstract long 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.
Returns:
getEventPosition
public abstract EventPosition 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.
Returns:
getIsOpen
public abstract boolean getIsOpen()
Determine the current state of the receiver.
Returns:
getPartitionId
public abstract String getPartitionId()
Get EventHubs partition identifier.
Returns:
getReceiveTimeout
public abstract Duration getReceiveTimeout()
getRuntimeInformation
public abstract ReceiverRuntimeInformation 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.
Returns:
receive
public abstract CompletableFuture
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 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();
}
Parameters:
Returns:
receiveSync
public default Iterable
Synchronous version of #receive.
Parameters:
Returns:
Throws:
setReceiveHandler
public abstract CompletableFuture
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.
Parameters:
null
will stop the receive pump.
Returns:
setReceiveHandler
public abstract CompletableFuture
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.
Parameters:
Returns:
setReceiveTimeout
public abstract void setReceiveTimeout(Duration value)
Parameters:
Applies to
Azure SDK for Java