本文整理汇总了Java中com.microsoft.azure.iothub.DeviceClient类的典型用法代码示例。如果您正苦于以下问题:Java DeviceClient类的具体用法?Java DeviceClient怎么用?Java DeviceClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeviceClient类属于com.microsoft.azure.iothub包,在下文中一共展示了DeviceClient类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import com.microsoft.azure.iothub.DeviceClient; //导入依赖的package包/类
public boolean sendMessage(byte[] messagePayload) {
logger.debug("Starting IoT Hub distro...");
logger.debug("Beginning IoT Hub setup.");
try {
logger.debug("Azure connect with: " + connectionString);
client = new DeviceClient(connectionString.toString(), IotHubClientProtocol.MQTT);
logger.debug("Successfully created an IoT Hub client.");
client.open();
logger.debug("Opened connection to IoT Hub.");
Message msg = new Message(messagePayload);
msg.setExpiryTime(5000);
Object lockobj = new Object();
EventCallback callback = new EventCallback();
client.sendEventAsync(msg, callback, lockobj);
synchronized (lockobj) {
lockobj.wait();
}
client.close();
logger.debug("Shutting down...");
return true;
} catch (Exception e) {
logger.error("Failure: " + e.toString());
}
return false;
}
示例2: init
import com.microsoft.azure.iothub.DeviceClient; //导入依赖的package包/类
@Override
public void init(Config config) throws TestException
{
super.init(config);
connectionString = config.getPropertyValue("producerConnectionString");
if (connectionString == null)
throw new TestException("Azure Iot Hub event producer ERROR: 'uri' property must be specified");
devices = new Device[deviceCount];
clients = new DeviceClient[deviceCount];
callback = new EventCallback();
IotHubClientProtocol protocol = IotHubClientProtocol.AMQPS;
try
{
for (int i = 0; i < deviceCount; i++)
{
//Device device = getDevice("device-" + i);
String deviceConnectionString = "HostName=esri-simulator-test.azure-devices.net;DeviceId=testdevice1;SharedAccessKey=OWChjfJ9t1+XQKXZArA1wvNliENL+v5VJ4eedeWBmf4=";
// String deviceConnectionString = "HostName=esri-simulator-test.azure-devices.net;DeviceId=" +
// device.getDeviceId() + ";SharedAccessKey=" + device.getPrimaryKey();
DeviceClient client = new DeviceClient(deviceConnectionString, protocol);
client.open();
//devices[i] = device;
clients[i] = client;
}
}
catch (Exception error)
{
throw new TestException(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()), error);
}
}