关于你的悬空问题,我在原来的帖子里贴了一个新的答案
Client hangs when calling Azure Event Hub and facing connection error
.
那会解决你的问题
.
现在回到这个问题,首先你应该遵循
latest tutorial
import com.azure.messaging.eventhubs.*;
public class Sender {
public static void main(String[] args) {
final String connectionString = "EVENT HUBS NAMESPACE CONNECTION STRING";
final String eventHubName = "EVENT HUB NAME";
// create a producer using the namespace connection string and event hub name
EventHubProducerClient producer = new EventHubClientBuilder()
.connectionString(connectionString, eventHubName)
.buildProducerClient();
// prepare a batch of events to send to the event hub
EventDataBatch batch = producer.createBatch();
batch.tryAdd(new EventData("First event"));
batch.tryAdd(new EventData("Second event"));
batch.tryAdd(new EventData("Third event"));
batch.tryAdd(new EventData("Fourth event"));
batch.tryAdd(new EventData("Fifth event"));
// send the batch of events to the event hub
producer.send(batch);
// close the producer
producer.close();
}
}
关于OAuth2上的问题,很有可能利用AAD身份验证方法而不是共享访问签名(默认的连接字符串方法)。你可以跟着
this tutorial
对于托管身份方案或
this tutorial
用于自定义基于AAD应用程序的身份验证。
关于OAuth2库的建议,Azure世界的第一方选择是
MSAL
实现无缝集成和支持。
关于用自定义代码编写整个程序的问题,虽然从技术上讲是可行的,但老实说,由于以下原因,在这个庞大的任务上投资是非常不切实际的:
-
-
这将增加您的维护头痛的地狱很多自定义代码只做技术布线,但几乎没有增加任何价值的业务。
-
您几乎可以自己找出任何问题或未来的兼容性。
-
在代码中添加所有低级别的AMQP和OAuth处理将给您的团队增加不必要的负担来掌握它们。
-
……最重要的是,这需要花费金钱和时间:)
使用标准库不仅可以为您节省大量的精力和金钱,而且可以确保可重用性,以及来自创建者和社区的支持。