本文整理汇总了Java中org.eclipse.paho.client.mqttv3.MqttMessage.setId方法的典型用法代码示例。如果您正苦于以下问题:Java MqttMessage.setId方法的具体用法?Java MqttMessage.setId怎么用?Java MqttMessage.setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.paho.client.mqttv3.MqttMessage
的用法示例。
在下文中一共展示了MqttMessage.setId方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDeviceConnect
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public MqttDeliveryFuture onDeviceConnect(final String deviceName, final String deviceType) {
final int msgId = msgIdSeq.incrementAndGet();
ObjectNode node = newNode().put("device", deviceName);
if (!StringUtils.isEmpty(deviceType)) {
node.put("type", deviceType);
}
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
log.info("[{}] Device Connected!", deviceName);
devices.putIfAbsent(deviceName, new DeviceInfo(deviceName, deviceType));
return publishAsync(GATEWAY_CONNECT_TOPIC, msg,
token -> {
log.info("[{}][{}] Device connect event is reported to Thingsboard!", deviceName, msgId);
},
error -> log.warn("[{}][{}] Failed to report device connection!", deviceName, msgId, error));
}
示例2: onDeviceDisconnect
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public Optional<MqttDeliveryFuture> onDeviceDisconnect(String deviceName) {
if (devices.remove(deviceName) != null) {
final int msgId = msgIdSeq.incrementAndGet();
byte[] msgData = toBytes(newNode().put("device", deviceName));
MqttMessage msg = new MqttMessage(msgData);
msg.setId(msgId);
log.info("[{}][{}] Device Disconnected!", deviceName, msgId);
MqttDeliveryFuture future = publishAsync(GATEWAY_DISCONNECT_TOPIC, msg,
token -> {
log.info("[{}][{}] Device disconnect event is delivered!", deviceName, msgId);
},
error -> log.warn("[{}][{}] Failed to report device disconnect!", deviceName, msgId, error));
return Optional.of(future);
} else {
log.debug("[{}] Device was disconnected before. Nothing is going to happened.", deviceName);
return Optional.empty();
}
}
示例3: onDeviceAttributesUpdate
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public MqttDeliveryFuture onDeviceAttributesUpdate(String deviceName, List<KvEntry> attributes) {
final int msgId = msgIdSeq.incrementAndGet();
log.trace("[{}][{}] Updating device attributes: {}", deviceName, msgId, attributes);
checkDeviceConnected(deviceName);
ObjectNode node = newNode();
ObjectNode deviceNode = node.putObject(deviceName);
attributes.forEach(kv -> putToNode(deviceNode, kv));
final int packSize = attributes.size();
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
return publishAsync(GATEWAY_ATTRIBUTES_TOPIC, msg,
token -> {
log.debug("[{}][{}] Device attributes were delivered!", deviceName, msgId);
attributesCount.addAndGet(packSize);
},
error -> log.warn("[{}][{}] Failed to report device attributes!", deviceName, msgId, error));
}
示例4: onDeviceTelemetry
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public MqttDeliveryFuture onDeviceTelemetry(String deviceName, List<TsKvEntry> telemetry) {
final int msgId = msgIdSeq.incrementAndGet();
log.trace("[{}][{}] Updating device telemetry: {}", deviceName, msgId, telemetry);
checkDeviceConnected(deviceName);
ObjectNode node = newNode();
Map<Long, List<TsKvEntry>> tsMap = telemetry.stream().collect(Collectors.groupingBy(v -> v.getTs()));
ArrayNode deviceNode = node.putArray(deviceName);
tsMap.entrySet().forEach(kv -> {
Long ts = kv.getKey();
ObjectNode tsNode = deviceNode.addObject();
tsNode.put("ts", ts);
ObjectNode valuesNode = tsNode.putObject("values");
kv.getValue().forEach(v -> putToNode(valuesNode, v));
});
final int packSize = telemetry.size();
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
return publishAsync(GATEWAY_TELEMETRY_TOPIC, msg,
token -> {
log.debug("[{}][{}] Device telemetry published to Thingsboard!", msgId, deviceName);
telemetryCount.addAndGet(packSize);
},
error -> log.warn("[{}][{}] Failed to publish device telemetry!", deviceName, msgId, error));
}
示例5: onDeviceAttributeRequest
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public void onDeviceAttributeRequest(AttributeRequest request, Consumer<AttributeResponse> listener) {
final int msgId = msgIdSeq.incrementAndGet();
String deviceName = request.getDeviceName();
AttributeRequestKey requestKey = new AttributeRequestKey(request.getRequestId(), request.getDeviceName());
log.trace("[{}][{}] Requesting {} attribute: {}", deviceName, msgId, request.isClientScope() ? "client" : "shared", request.getAttributeKey());
checkDeviceConnected(deviceName);
ObjectNode node = newNode();
node.put("id", request.getRequestId());
node.put("client", request.isClientScope());
node.put("device", request.getDeviceName());
node.put("key", request.getAttributeKey());
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
pendingAttrRequestsMap.put(requestKey, new AttributeRequestListener(request, listener));
publishAsync(GATEWAY_REQUESTS_ATTRIBUTES_TOPIC, msg,
token -> {
log.debug("[{}][{}] Device attributes request was delivered!", deviceName, msgId);
},
error -> {
log.warn("[{}][{}] Failed to report device attributes!", deviceName, msgId, error);
pendingAttrRequestsMap.remove(requestKey);
});
}
示例6: onDeviceRpcResponse
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public void onDeviceRpcResponse(RpcCommandResponse response) {
final int msgId = msgIdSeq.incrementAndGet();
int requestId = response.getRequestId();
String deviceName = response.getDeviceName();
String data = response.getData();
checkDeviceConnected(deviceName);
ObjectNode node = newNode();
node.put("id", requestId);
node.put("device", deviceName);
node.put("data", data);
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
publishAsync(GATEWAY_RPC_TOPIC, msg,
token -> {
log.debug("[{}][{}] RPC response from device was delivered!", deviceName, requestId);
},
error -> {
log.warn("[{}][{}] Failed to report RPC response from device!", deviceName, requestId, error);
});
}
示例7: reportStats
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
private void reportStats() {
if (tbClient == null) {
log.info("Can't report stats because client was not initialized yet!");
return;
}
ObjectNode node = newNode();
node.put("ts", System.currentTimeMillis());
ObjectNode valuesNode = node.putObject("values");
valuesNode.put("devicesOnline", devices.size());
valuesNode.put("attributesUploaded", attributesCount.getAndSet(0));
valuesNode.put("telemetryUploaded", telemetryCount.getAndSet(0));
if (error != null) {
valuesNode.put("latestError", JsonTools.toString(error));
error = null;
}
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgIdSeq.incrementAndGet());
publishAsync(DEVICE_TELEMETRY_TOPIC, msg,
token -> log.info("Gateway statistics {} reported!", node),
error -> log.warn("Failed to report gateway statistics!", error));
}
示例8: onDeviceAttributesUpdate
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public MqttDeliveryFuture onDeviceAttributesUpdate(String deviceName, List<KvEntry> attributes) {
final int msgId = msgIdSeq.incrementAndGet();
log.trace("[{}][{}] Updating device attributes: {}", deviceName, msgId, attributes);
checkDeviceConnected(deviceName);
ObjectNode node = newNode();
ObjectNode deviceNode = node.putObject(deviceName);
attributes.forEach(kv -> JsonTools.putToNode(deviceNode, kv));
final int packSize = attributes.size();
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
return publishAsync(GATEWAY_ATTRIBUTES_TOPIC, msg, token -> {
log.debug("[{}][{}] Device attributes were delivered!", deviceName, msgId);
attributesCount.addAndGet(packSize);
}, error -> log.warn("[{}][{}] Failed to report device attributes!", deviceName, msgId, error));
}
示例9: onDeviceTelemetry
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public MqttDeliveryFuture onDeviceTelemetry(String deviceName, List<TsKvEntry> telemetry) {
final int msgId = msgIdSeq.incrementAndGet();
log.trace("[{}][{}] Updating device telemetry: {}", deviceName, msgId, telemetry);
checkDeviceConnected(deviceName);
ObjectNode node = newNode();
Map<Long, List<TsKvEntry>> tsMap = telemetry.stream().collect(Collectors.groupingBy(v -> v.getTs()));
ArrayNode deviceNode = node.putArray(deviceName);
tsMap.entrySet().forEach(kv -> {
Long ts = kv.getKey();
ObjectNode tsNode = deviceNode.addObject();
tsNode.put("ts", ts);
ObjectNode valuesNode = tsNode.putObject("values");
kv.getValue().forEach(v -> JsonTools.putToNode(valuesNode, v));
});
final int packSize = telemetry.size();
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
return publishAsync(GATEWAY_TELEMETRY_TOPIC, msg, token -> {
log.debug("[{}][{}] Device telemetry published to IoT Platform!", msgId, deviceName);
telemetryCount.addAndGet(packSize);
}, error -> log.warn("[{}][{}] Failed to publish device telemetry!", deviceName, msgId, error));
}
示例10: onDeviceAttributeRequest
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public void onDeviceAttributeRequest(AttributeRequest request, Consumer<AttributeResponse> listener) {
final int msgId = msgIdSeq.incrementAndGet();
String deviceName = request.getDeviceName();
AttributeRequestKey requestKey = new AttributeRequestKey(request.getRequestId(), request.getDeviceName());
log.trace("[{}][{}] Requesting {} attribute: {}", deviceName, msgId, request.isClientScope() ? "client" : "shared",
request.getAttributeKey());
checkDeviceConnected(deviceName);
ObjectNode node = newNode();
node.put("id", request.getRequestId());
node.put("client", request.isClientScope());
node.put("device", request.getDeviceName());
node.put("key", request.getAttributeKey());
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
pendingAttrRequestsMap.put(requestKey, new AttributeRequestListener(request, listener));
publishAsync(GATEWAY_REQUESTS_ATTRIBUTES_TOPIC, msg, token -> {
log.debug("[{}][{}] Device attributes request was delivered!", deviceName, msgId);
}, error -> {
log.warn("[{}][{}] Failed to report device attributes!", deviceName, msgId, error);
pendingAttrRequestsMap.remove(requestKey);
});
}
示例11: onDeviceRpcResponse
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public void onDeviceRpcResponse(RpcCommandResponse response) {
final int msgId = msgIdSeq.incrementAndGet();
int requestId = response.getRequestId();
String deviceName = response.getDeviceName();
String data = response.getData();
checkDeviceConnected(deviceName);
ObjectNode node = newNode();
node.put("id", requestId);
node.put("device", deviceName);
node.put("data", data);
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgId);
publishAsync(GATEWAY_RPC_TOPIC, msg, token -> {
log.debug("[{}][{}] RPC response from device was delivered!", deviceName, requestId);
}, error -> {
log.warn("[{}][{}] Failed to report RPC response from device!", deviceName, requestId, error);
});
}
示例12: reportStats
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
private void reportStats() {
if (tbClient == null) {
log.info("Can't report stats because client was not initialized yet!");
return;
}
ObjectNode node = newNode();
node.put("ts", System.currentTimeMillis());
ObjectNode valuesNode = node.putObject("values");
valuesNode.put("devicesOnline", devices.size());
valuesNode.put("attributesUploaded", attributesCount.getAndSet(0));
valuesNode.put("telemetryUploaded", telemetryCount.getAndSet(0));
if (error != null) {
valuesNode.put("latestError", JsonTools.toString(error));
error = null;
}
MqttMessage msg = new MqttMessage(toBytes(node));
msg.setId(msgIdSeq.incrementAndGet());
publishAsync(DEVICE_TELEMETRY_TOPIC, msg, token -> log.info("Gateway statistics {} reported!", node),
error -> log.warn("Failed to report gateway statistics!", error));
}
示例13: onDeviceConnect
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public MqttDeliveryFuture onDeviceConnect(final String deviceName) {
final int msgId = msgIdSeq.incrementAndGet();
byte[] msgData = toBytes(newNode().put("device", deviceName));
MqttMessage msg = new MqttMessage(msgData);
msg.setId(msgId);
log.info("[{}] Device Connected!", deviceName);
devices.putIfAbsent(deviceName, new DeviceInfo(deviceName));
return publishAsync(GATEWAY_CONNECT_TOPIC, msg, token -> {
log.info("[{}][{}] Device connect event is reported to IoT Platform!", deviceName, msgId);
}, error -> log.warn("[{}][{}] Failed to report device connection!", deviceName, msgId, error));
}
示例14: onDeviceDisconnect
import org.eclipse.paho.client.mqttv3.MqttMessage; //导入方法依赖的package包/类
@Override
public Optional<MqttDeliveryFuture> onDeviceDisconnect(String deviceName) {
if (devices.remove(deviceName) != null) {
final int msgId = msgIdSeq.incrementAndGet();
byte[] msgData = toBytes(newNode().put("device", deviceName));
MqttMessage msg = new MqttMessage(msgData);
msg.setId(msgId);
log.info("[{}][{}] Device Disconnected!", deviceName, msgId);
MqttDeliveryFuture future = publishAsync(GATEWAY_DISCONNECT_TOPIC, msg, token -> {
log.info("[{}][{}] Device disconnect event is delivered!", deviceName, msgId);
}, error -> log.warn("[{}][{}] Failed to report device disconnect!", deviceName, msgId, error));
return Optional.of(future);
} else {
log.debug("[{}] Device was disconnected before. Nothing is going to happened.", deviceName);
return Optional.empty();
}
}