英文:
Azure java SDK - how to read events from an Event Hub?
问题
我有一个带有以下依赖关系的Java应用程序:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.33.0</version>
</dependency>
我需要从事件中心消费事件。我似乎无法找到如何做到这一点。
Azure azure = Azure.configure().withLogLevel(...).authenticate(credentials).withSubscription(subscriptionId);
EventHub eventHub = azure.eventHubs().getByName("?", "?", "?");
//现在怎么办?
英文:
I have a Java app with the following dependency:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.33.0</version>
</dependency>
I need to consume events from an Event Hub. I can't seem to find out how to this.
Azure azure = Azure.configure().withLogLevel(...).authenticate(credentials).withSubscription(subscriptionId);
EventHub eventHub = azure.eventHubs().getByName("?", "?", "?");
//Now what?
答案1
得分: 0
你是否查阅过文档
?您需要创建客户端
EventHubConsumerAsyncClient consumer = new EventHubClientBuilder()
.connectionString("<<特定事件中心实例的连接字符串>>")
.consumerGroup(EventHubClientBuilder.DEFAULT_CONSUMER_GROUP_NAME)
.buildAsyncConsumerClient();
// 从分区ID为"0"的分区接收新增事件。EventPosition指定开始消费事件的位置
consumer.receiveFromPartition("0", EventPosition.latest()).subscribe(event -> {
// 处理每个到达的事件。
});
并使用方法getData();
EventData event = partitionEvent.getData();
英文:
Have you had a look at the docs
? . You need to create the Client
EventHubConsumerAsyncClient consumer = new EventHubClientBuilder()
.connectionString("<< CONNECTION STRING FOR SPECIFIC EVENT HUB INSTANCE >>")
.consumerGroup(EventHubClientBuilder.DEFAULT_CONSUMER_GROUP_NAME)
.buildAsyncConsumerClient();
// Receive newly added events from partition with id "0". EventPosition specifies the position
// within the Event Hub partition to begin consuming events.
consumer.receiveFromPartition("0", EventPosition.latest()).subscribe(event -> {
// Process each event as it arrives.
});
and use the method getData();
EventData event = partitionEvent.getData();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论