问题
I am trying to get the last enqueued sequence number to track the lag between consumer and producer at the consumer end by leveraging ReceiverRuntimeInformation object provided by PartitionContext when a event is received. However, ReceiverRuntimeInformation object doesn't have the updated values related to that particular partition of an Event Hub, it returns 0. Sample code and log output below:
public class EventProcessor extends IEventProcessorImpl{
@Override
public void onEvents(PartitionContext context, Iterable<EventData> messages) throws Exception {
ReceiverRuntimeInformation rte = context.getRuntimeInformation();
logger.info(rte.getLastEnqueuedOffset() + " * " + rte.getLastEnqueuedSequenceNumber() + " * " + rte.getPartitionId() + " * " + rte.getRetrievalTime());
}
}
Output:
null * 0 * 3 * null
回答1:
This is an opt-in feature. While creating the EventProcessorHost instance, pass in EventProcessorOptions with:
eventProcessorOptions.setReceiverRuntimeMetricEnabled(true);
We designed this as an Opt-in feature - as it adds additional bytes to all EventHub messages received (sdk uses all EventData received on the wire by the client - to transmit this extra information).
Note: Data present in RecieverRuntimeInformation is dynamic and hence can be stale! For instance - ReceiverRuntimeInformation.LastEnqueuedSequenceNumber could change by the time service actually responded back! as there could be new Events on that Partition. To make the data relevant - we added a property named - RetrievalTime - which is actually when the ReceiverRuntimeInformation was retrieved from the service. This can help understand - how stale the value of ReceiverRuntimeInformation is.
来源:https://stackoverflow.com/questions/51823399/azure-event-processor-host-java-library-receiverruntimeinformation-doesnt-hav