use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class TbSqsNode method processException.
private TbMsg processException(TbContext ctx, TbMsg origMsg, Throwable t) {
TbMsgMetaData metaData = origMsg.getMetaData().copy();
metaData.putValue(ERROR, t.getClass() + ": " + t.getMessage());
return ctx.transformMsg(origMsg, origMsg.getType(), origMsg.getOriginator(), metaData, origMsg.getData());
}
use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class TbNodeUtilsTest method testSimpleReplacement.
@Test
public void testSimpleReplacement() {
String pattern = "ABC ${metadata_key} $[data_key]";
TbMsgMetaData md = new TbMsgMetaData();
md.putValue("metadata_key", "metadata_value");
ObjectNode node = JacksonUtil.newObjectNode();
node.put("data_key", "data_value");
TbMsg msg = TbMsg.newMsg("CUSTOM", TenantId.SYS_TENANT_ID, md, JacksonUtil.toString(node));
String result = TbNodeUtils.processPattern(pattern, msg);
Assert.assertEquals("ABC metadata_value data_value", result);
}
use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class TbNodeUtilsTest method testComplexObjectReplacement.
@Test
public void testComplexObjectReplacement() {
String pattern = "ABC ${key} $[key1.key2.key3]";
TbMsgMetaData md = new TbMsgMetaData();
md.putValue("key", "metadata_value");
ObjectNode key2Node = JacksonUtil.newObjectNode();
key2Node.put("key3", "value3");
ObjectNode key1Node = JacksonUtil.newObjectNode();
key1Node.set("key2", key2Node);
ObjectNode node = JacksonUtil.newObjectNode();
node.set("key1", key1Node);
TbMsg msg = TbMsg.newMsg("CUSTOM", TenantId.SYS_TENANT_ID, md, JacksonUtil.toString(node));
String result = TbNodeUtils.processPattern(pattern, msg);
Assert.assertEquals("ABC metadata_value value3", result);
}
use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class TbNodeUtilsTest method testNoReplacement.
@Test
public void testNoReplacement() {
String pattern = "ABC ${metadata_key} $[data_key]";
TbMsgMetaData md = new TbMsgMetaData();
md.putValue("key", "metadata_value");
ObjectNode node = JacksonUtil.newObjectNode();
node.put("key", "data_value");
TbMsg msg = TbMsg.newMsg("CUSTOM", TenantId.SYS_TENANT_ID, md, JacksonUtil.toString(node));
String result = TbNodeUtils.processPattern(pattern, msg);
Assert.assertEquals(pattern, result);
}
use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.
the class TbMsgCountNode method onMsg.
@Override
public void onMsg(TbContext ctx, TbMsg msg) {
if (msg.getType().equals(TB_MSG_COUNT_NODE_MSG) && msg.getId().equals(nextTickId)) {
JsonObject telemetryJson = new JsonObject();
telemetryJson.addProperty(this.telemetryPrefix + "_" + ctx.getServiceId(), messagesProcessed.longValue());
messagesProcessed = new AtomicLong(0);
TbMsgMetaData metaData = new TbMsgMetaData();
metaData.putValue("delta", Long.toString(System.currentTimeMillis() - lastScheduledTs + delay));
TbMsg tbMsg = TbMsg.newMsg(msg.getQueueName(), SessionMsgType.POST_TELEMETRY_REQUEST.name(), ctx.getTenantId(), msg.getCustomerId(), metaData, gson.toJson(telemetryJson));
ctx.enqueueForTellNext(tbMsg, SUCCESS);
scheduleTickMsg(ctx, tbMsg);
} else {
messagesProcessed.incrementAndGet();
ctx.ack(msg);
}
}
Aggregations