Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Event Hub multiple recipients

I have a server which will need to send messages to several clients to let the clients know that something needs to be done.

I am trying to achieve this by using Azure Event Hub.

I use the following code to send the message:

await eventHubClient.SendAsync(
    new EventData(Encoding.UTF8.GetBytes(String.Format("Message {0}, {1}", i, sMessage))), 
    "1")
    .ConfigureAwait(continueOnCapturedContext: false);
await eventHubClient.CloseAsync();

I use two WPF application as listeners which will create the listener at startup and will save the EventProcessorHost in a private variable.

When I send a message it's random which of the listeners will process the message.

Is is possible to send messages to multiple recipients with Azure Event Hub?

like image 246
Jron Avatar asked Jun 08 '17 08:06

Jron


People also ask

What is consumer group in event hub?

A consumer group is a view (state, position, or offset) of an entire event hub. Consumer groups enable multiple consuming applications to each have a separate view of the event stream, and to read the stream independently at their own pace and with their own offsets.

What is a partition in event hub?

A partition is an ordered sequence of events that is held in an event hub. As newer events arrive, they are added to the end of this sequence. A partition can be thought of as a “commit log.” Event Hubs retains data for a configured retention time that applies across all partitions in the event hub.

How do I create a consumer group in event hub?

Once inside the Event Hub, there should be a "CONSUMER GROUPS" tab at the top, click on that. Once inside, in the navy blue footer, there should be a "create" button which will let you create a new consumer group.


1 Answers

You need to put each listener to a separate Consumer Group.

Listeners of the same consumer group are "Competing Consumers", i.e. the first one who takes a lock on an event hub partition wins.

like image 140
Mikhail Shilkov Avatar answered Oct 02 '22 11:10

Mikhail Shilkov