0

I am using Event Hub, wanted to know which one is better approach to consume events Event Processor Host or Direct Receivers. if one of it is better then why.

Also Can you help me any java code sample github or java Azure SDK to write event consumer.

Does using partitions and consumer groups is better approach?

Peter Bons
  • 26,826
  • 4
  • 50
  • 74
  • There's no one correct answer here; it heavily depends on the application scenarios and workload. If you're unsure, the `EventProcessorClient` is likely the best default choice. Please also be aware that `EventProcessorHost` was a type in the legacy package and replaced by `EventProcessorClient` in the current generation. – Jesse Squire Mar 01 '23 at 15:44

1 Answers1

1

Does using partitions and consumer groups is better approach

No matter how you consume events, you alway have at least one consumer group and at least 2 partitions. It is not optional.

Also Can you help me any java code sample github or java Azure SDK to write event consumer.

Plenty of docs available to get started

I am using Event Hub, wanted to know which one is better approach to consume events Event Processor Host or Direct Receivers. if one of it is better then why.

According to the docs:

For most production scenarios, we recommend that you use the event processor client for reading and processing events. The processor client is intended to provide a robust experience for processing events across all partitions of an event hub in a performant and fault tolerant manner while providing a means to checkpoint its progress. Event processor clients can work cooperatively within the context of a consumer group for a given event hub. Clients will automatically manage distribution and balancing of work as instances become available or unavailable for the group.

Regarding direct consumers:

This method is not recommended for production use; the EventProcessorClient should be used for reading events from all partitions in a production scenario, as it offers a much more robust experience with higher throughput.

When using direct consumers you need to manually do the checkpointing. Using the Processor Host takes that away. Also, load distribution is better handled using the Processor Host

Peter Bons
  • 26,826
  • 4
  • 50
  • 74
  • Clarification: `EventHubConsumerClient` and `EventHubConsumerClientAsync` are perfectly fine for production scenarios when used to read from a single partition. We recommend avoiding the async consumer's `receive` method to read from all partitions in production; it is meant for exploring Event Hubs and offers no performance or fairness guarantees. – Jesse Squire Mar 01 '23 at 15:41