public final class PartitionReceiver extends ClientEntity implements IReceiverSettingsProvider
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 String |
END_OF_STREAM
This is a constant defined to represent the current end of a partition stream in EventHub.
|
static String |
START_OF_STREAM
This is a constant defined to represent the start of a partition stream in EventHub.
|
| Modifier and Type | Method and Description |
|---|---|
org.apache.qpid.proton.amqp.Symbol[] |
getDesiredCapabilities() |
long |
getEpoch()
Get the epoch value that this receiver is currently using for partition ownership.
|
Map<org.apache.qpid.proton.amqp.Symbol,org.apache.qpid.proton.amqp.UnknownDescribedType> |
getFilter(org.apache.qpid.proton.message.Message lastReceivedMessage) |
String |
getPartitionId()
Get EventHubs partition identifier.
|
int |
getPrefetchCount()
Get Prefetch Count configured on the Receiver.
|
Map<org.apache.qpid.proton.amqp.Symbol,Object> |
getProperties() |
Duration |
getReceiveTimeout() |
ReceiverRuntimeInformation |
getRuntimeInformation()
Gets the temporal
ReceiverRuntimeInformation for this EventHub partition. |
CompletableFuture<Void> |
onClose() |
CompletableFuture<Iterable<EventData>> |
receive(int maxEventCount)
Receive a batch of
EventData's from an EventHub partition |
Iterable<EventData> |
receiveSync(int maxEventCount)
Synchronous version of
receive(int). |
void |
setPrefetchCount(int prefetchCount)
Set the number of events that can be pre-fetched and cached at the
PartitionReceiver. |
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) |
close, closeSync, getClientId, getLastKnownError, setClosed, throwIfClosedpublic static final String START_OF_STREAM
public static final String END_OF_STREAM
public final String getPartitionId()
public final int getPrefetchCount()
setPrefetchCount(int)public final Duration getReceiveTimeout()
public void setReceiveTimeout(Duration value)
public final void setPrefetchCount(int prefetchCount)
throws ServiceBusException
PartitionReceiver.
By default the value is 300
prefetchCount - the number of events to pre-fetch. value must be between 10 and 999. Default is 300.ServiceBusException - if setting prefetchCount encounters errorpublic final long getEpoch()
A value of 0 means this receiver is not an epoch-based receiver.
public final 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().public final Iterable<EventData> receiveSync(int maxEventCount) throws ServiceBusException
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.ServiceBusException - if ServiceBus client encountered any unrecoverable/non-transient problems during receive(int)public 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.createFromConnectionStringSync("__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();
}
public 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.public 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 PartitionReceiveHandlerinvokeWhenNoEvents - flag to indicate whether the PartitionReceiveHandler.onReceive(Iterable) should be invoked when the receive call times outpublic CompletableFuture<Void> onClose()
onClose in class ClientEntitypublic Map<org.apache.qpid.proton.amqp.Symbol,org.apache.qpid.proton.amqp.UnknownDescribedType> getFilter(org.apache.qpid.proton.message.Message lastReceivedMessage)
getFilter in interface IReceiverSettingsProviderpublic Map<org.apache.qpid.proton.amqp.Symbol,Object> getProperties()
getProperties in interface IReceiverSettingsProviderpublic org.apache.qpid.proton.amqp.Symbol[] getDesiredCapabilities()
getDesiredCapabilities in interface IReceiverSettingsProviderCopyright © 2017. All rights reserved.