azure-eventhubs 和 spring-cloud-azure-eventhubs-stream-binder 有什么区别?

What is the difference between azure-eventhubs and spring-cloud-azure-eventhubs-stream-binder?

我的要求是使用 Spring.

使用 Azure Events Hub 的简单发布-订阅

在查看文档后,我找到了 2 篇演示集成的文章。 One uses azure-eventhubs library and the other uses spring-cloud-azure-eventhubs-stream-binder.

两者有什么区别?

首先请注意,您在 Java 中引用旧版本的文章使用 Azure 事件中心,here 是最新的。

在第一篇文章中,文章向您展示了如何在“经典”java 应用程序中使用事件中心的 Java SDK。

第二篇文章介绍了如何在 Spring Boot Java 应用程序中使用事件中心(Spring Boot 是由 Pivotal 维护的 open-source 框架)。

嗯,我是这样看的。我会说有 3-4 种方法可以做到这一点。您可以使用 Kafka/9093 或 AMQP/5671 连接到 Eventhub。我认为很遗憾没有任何页面对此提供建议:

  1. 首先,最基本的:azure-messaging-eventhubslib。我会把 azure-coreazure-core-amqp 相关。您可以使用 azure-core 连接进行健康检查,例如:EventHubClient.createFromConnectionStringSync(connectionString, Executors.newSingleThreadScheduledExecutor());。此方法为您提供了最大的灵活性,但您将编写更多代码并自行处理配置属性。
  2. 然后,您可能会看到 azure-spring-cloud-starter-eventhubs ,它有一个名为 spring-cloud-starter-azure-eventhubs-kafka 的 kafka 变体。 spring 库 azure-spring-cloud-stream-binder-eventhubs 可能与此有关。这个库需要一个特定的 application.properties 配置(与 #3 不同)。我喜欢这个的一件事是它延迟加载,即使 lib 无法连接,您的 spring-boot 服务也会启动,并且问题会显示在运行状况检查中。
  3. 然后,我们在 #1&#2spring-cloud-azure-eventhubs-stream-binder 中有这个包装器。这个库有自己特定的 application.properties 配置(与 #2 不同)。这有一个内置的健康检查,但我无法让它工作。使用这个,如果无法建立连接来配置 Bean,您的服务将不会启动。
  4. 也许您不想使用上述包装器库之一。在那种情况下,您也可以只使用基本 spring-kafka。我举了个例子:https://github.com/djangofan/kafka-on-azure