5

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?

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
Jron
  • 51
  • 1
  • 3
  • Why use the EventHub for this instead of Azure Service Bus? Do you expect a very high throughput? Have you read http://microsoftintegration.guru/2015/03/03/azure-event-hubs-vs-azure-messaging/ and https://stackoverflow.com/questions/28183020/looking-for-clarity-on-event-hubs-vs-topics-in-azure-service-bus? – Peter Bons Jun 08 '17 at 14:45

1 Answers1

11

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.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • Would you care to elaborate a bit on this? Competing consumers are not a property of EH as far as I know. – Martin Wickman Mar 24 '21 at 09:39
  • You can have server A and server B connecting to the same consumer group of the same event hub. Each of them will take a lock of some partitions and will process events from those partitions. If server A dies, server B will eventually take over its partitions. – Mikhail Shilkov Mar 24 '21 at 09:58