简体   繁体   English

确定Java Azure IoT中心DeviceClient连接状态?

[英]Determining Java Azure IoT Hub DeviceClient connection state?

Is there a way to determine if the client is/isn't connected using the client SDK? 有没有一种方法可以确定是否使用客户端SDK连接了客户端? I see how to do that using the JavaScript and .NET SDKS, but I don't see anything similar in the Java version of DeviceClient. 我看到了如何使用JavaScript和.NET SDKS做到这一点,但是在Java版本的DeviceClient中看不到任何类似的东西。 What am I missing? 我想念什么?

I'm not familiar with Java SDK, but as I know Java SDK does not support event trigger. 我对Java SDK不熟悉,但是据我所知Java SDK不支持事件触发。

I'm afraid you have to check connection state before sending data as official SDK does https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/DeviceClient.java#L250 恐怕您必须像官方SDK一样在发送数据之前检查连接状态https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-client/src/main /java/com/microsoft/azure/sdk/iot/device/DeviceClient.java#L250

Also, Java SDK use loop to receive messages, but not MQTT subscription https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/DeviceClient.java#L197 另外,Java SDK使用循环来接收消息,但不接收MQTT订阅https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-client/src/main/java/ COM /微软/天青/ SDK / IOT /设备/ DeviceClient.java#L197

So maybe you need to handle a schedule to check state as well. 因此,也许您还需要处理时间表以检查状态。

In Java SDK, when you send event, it will be pushed to a waiting list. 在Java SDK中,当您发送事件时,它将被推送到等待列表中。 There is a thread to consume and send message in this list. 此列表中有一个线程可以使用和发送消息。

I tried to close the network connection when the device is sending messages per second. 当设备每秒发送消息时,我试图关闭网络连接。 Since there's a lock on the waiting list, so the consuming thread will be stuck. 由于等待列表上有一个锁,因此使用线程将被卡住。 The message will retain in the waiting list. 该消息将保留在等待列表中。 After the connection is recovered, message in the waiting list will be sent. 恢复连接后,将发送等待列表中的消息。

There isn't a way to get the status of the waiting list. 无法获取等待列表的状态。 Maybe here's a work-around for you requirement, you can maintain a processing counter. 也许这是您所需的解决方法,您可以维护一个处理计数器。 When you send message, increment the counter, and meanwhile you register a callback which will decrement the counter. 发送消息时,请增加计数器,同时注册一个回调,以减少计数器。 You can check the counter to proximately "guess" the connection state. 您可以检查计数器以“猜测”连接状态。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用“ azure-iot-sdk-java”; DeviceClient实例的预期寿命是多少? - With “azure-iot-sdk-java”; What is the expected lifetime of a DeviceClient instance Azure sdk Iot HUB DeviceClient 每 10 分钟重新连接尝试,MQTT,无操作超时,始终在后台尝试,无需 RETRY_EXPIRED - Azure sdk Iot HUB DeviceClient reconnect attempt each 10 minutes, MQTT, no operation timeout, always try in background without RETRY_EXPIRED 使用Java从IoT中心Azure访问数据 - Accses to data from IoT Hub Azure with Java 使用Java Paho连接到Azure IoT中心 - Connect to Azure IoT Hub with Java Paho 带有 IoT 中心触发器的 Java Azure 函数未启动 - Java Azure Function with IoT Hub trigger is not starting Microsoft Azure IoT中心(java)通知“与服务器的连接丢失。 发送消息后,重新连接0次。” - Microsoft Azure IoT hub (java) notifies a “Lost connection to the server. Reconnecting 0 time.” after sending a message Azure IOT集线器上的MQTT:初始化MQTT连接时出错:未授权连接 - MQTT on Azure IOT Hub : Error initializing MQTT connection:Not authorized to connect 无法在Azure IoT中心Java上创建模拟的设备应用程序 - Unable to Create a simulated device app on Azure IoT hub Java Azure IoT中心Java获取设备的流量统计信息 - Azure IoT Hub Java get traffic statistics for a device Azure IoT Hub - 使用 IoT Hub 从 Azure blob 下载文件到 IoT 设备 - Azure IoT Hub - Downloading file from Azure blob using IoT Hub to an IoT device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM