当前位置: 首页>>代码示例>>Java>>正文


Java DeviceClient类代码示例

本文整理汇总了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;
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:26,代码来源:AzureMQTTSender.java

示例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);
	}
}
 
开发者ID:Esri,项目名称:performance-test-harness-for-geoevent,代码行数:37,代码来源:AzureIoTHubProducer.java


注:本文中的com.microsoft.azure.iothub.DeviceClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。