azure - Java SDK 中的 EventHub 'send' 挂起,发送从未发生

标签 azure azure-eventhub

我正在尝试使用示例代码将简单事件发送到 Azure EventHub ( https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-java-get-started-send )。看起来一切顺利,我已经配置完毕,但是当我到达:

 ehClient.sendSync(sendEvent);

代码的一部分,它只是卡在那里,永远不会越过sendAsync方法。我使用的是个人计算机,并且没有运行防火墙。我是否必须在 Azure 中进行一些网络配置才能允许进行这种简单的发送?有人能成功完成这项工作吗?

final ConnectionStringBuilder connStr = new ConnectionStringBuilder()
            .setNamespaceName("mynamespace")
            .setEventHubName("myeventhubname")
            .setSasKeyName("mysaskename")
            .setSasKey("mysaskey");

    final Gson gson = new GsonBuilder().create();
    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    final EventHubClient ehClient = EventHubClient.createSync(connStr.toString(), executorService);

    print("Event Hub Client Created");
    try {
        for (int i = 0; i < 100; i++) {

            String payload = "Message " + Integer.toString(i);
            byte[] payloadBytes = gson.toJson(payload).getBytes(Charset.defaultCharset());
            EventData sendEvent = EventData.create(payloadBytes);

            // HANGS HERE - NEVER GETS PAST THIS CALL
            ehClient.sendSync(sendEvent);

        }

    } finally {
        ehClient.closeSync();
        executorService.shutdown();
    }

最佳答案

尝试使用不同的执行器服务。例如“工作窃取线程”

final ExecutorService executorService = Executors.newWorkStealingPool();

关于azure - Java SDK 中的 EventHub 'send' 挂起,发送从未发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49932019/

相关文章:

azure - 减慢 Azure Function 中的 EventHubTrigger 速度

azure - 如何查找azure静态网站的DNS A记录?

azure - 如何修复 azure PowerShell : "Can not remove tag/tag value because it' s being referenced by other resources. 中的此错误“

azure - 从 Azure Function API 获取数据时出现 CORS 错误

Azure 事件中心 : Offset vs Sequence number

azure - Azure事件中心和多个使用者组

python - U-SQL 与 Python 在 Azure Data Lake 存储中将 JSON 转换为 CSV

azure - 获取子文件夹Azure数据工厂中的所有文件名

azure - 哪些 Azure .NET SDK EventHubClient 实例方法是线程安全的?

c# - 如何在 C# 中为事件中心创建接收器以获取给定时间跨度的消息?