1
votes

My requirement is a simple pub-sub using Azure Events Hub using Spring.

Upon checking the documentation, I've found 2 articles which demonstrate the integration. One uses azure-eventhubs library and the other uses spring-cloud-azure-eventhubs-stream-binder.

What is the difference between the two?

2

2 Answers

-1
votes

First be careful that you where referring to an old version of the article to use Azure Event Hubs in Java, here is the most recent one.

In the first one the article shows you how to use the Java SDK for Event Hubs in a "classic" java application.

The second article explain how to use Event Hubs in a Spring Boot Java application (Spring Boot is an open-source framework maintained by Pivotal).

0
votes

Well, I look at it this way. I'd say there are 3-4 ways to do it. You can connect to Eventhubs either as Kafka/9093 or AMQP/5671. I think it is sad that there isn't a page anywhere that gives advice on this:

  1. First, the most basic: azure-messaging-eventhubs lib. I would put azure-core and azure-core-amqp as being related. You could use azure-core to connect for a health check for example: EventHubClient.createFromConnectionStringSync(connectionString, Executors.newSingleThreadScheduledExecutor()); . This method gives you the most flexibility but you will write a little more code and handle configuration properties on your own.
  2. Then, you might see azure-spring-cloud-starter-eventhubs , which has a kafka variant called spring-cloud-starter-azure-eventhubs-kafka. The spring lib azure-spring-cloud-stream-binder-eventhubs might be related to this. This lib expects a particular application.properties config (not the same as #3). One thing I like about this one is that it lazy-loads and your spring-boot service will start even when lib cannot connect, and problem will show in health check.
  3. Then, there is this wrapper around what we have in #1&#2, spring-cloud-azure-eventhubs-stream-binder. This lib has its own particular application.properties config (not the same as #2). This has a health check built-in but I couldn't get it to work. With this one, your service will not start if it can't make a connection to configure the Beans.
  4. Maybe you don't want to use one of the above wrapper libs. In that case, you could just use basic spring-kafka also. I made an example: https://github.com/djangofan/kafka-on-azure