Search in sources :

Example 61 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbSnsNode 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());
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData)

Example 62 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbKafkaNode method processResponse.

private TbMsg processResponse(TbContext ctx, TbMsg origMsg, RecordMetadata recordMetadata) {
    TbMsgMetaData metaData = origMsg.getMetaData().copy();
    metaData.putValue(OFFSET, String.valueOf(recordMetadata.offset()));
    metaData.putValue(PARTITION, String.valueOf(recordMetadata.partition()));
    metaData.putValue(TOPIC, recordMetadata.topic());
    return ctx.transformMsg(origMsg, origMsg.getType(), origMsg.getOriginator(), metaData, origMsg.getData());
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData)

Example 63 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbMsgGeneratorNode method scheduleTickMsg.

private void scheduleTickMsg(TbContext ctx) {
    log.trace("scheduleTickMsg, config {}", config);
    long curTs = System.currentTimeMillis();
    if (lastScheduledTs == 0L) {
        lastScheduledTs = curTs;
    }
    lastScheduledTs = lastScheduledTs + delay;
    long curDelay = Math.max(0L, (lastScheduledTs - curTs));
    TbMsg tickMsg = ctx.newMsg(ServiceQueue.MAIN, TB_MSG_GENERATOR_NODE_MSG, ctx.getSelfId(), new TbMsgMetaData(), "");
    nextTickId = tickMsg.getId();
    ctx.tellSelf(tickMsg, curDelay);
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) TbMsg(org.thingsboard.server.common.msg.TbMsg)

Example 64 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbMsgDelayNode method onMsg.

@Override
public void onMsg(TbContext ctx, TbMsg msg) {
    if (msg.getType().equals(TB_MSG_DELAY_NODE_MSG)) {
        TbMsg pendingMsg = pendingMsgs.remove(UUID.fromString(msg.getData()));
        if (pendingMsg != null) {
            ctx.enqueueForTellNext(pendingMsg, SUCCESS);
        }
    } else {
        if (pendingMsgs.size() < config.getMaxPendingMsgs()) {
            pendingMsgs.put(msg.getId(), msg);
            TbMsg tickMsg = ctx.newMsg(ServiceQueue.MAIN, TB_MSG_DELAY_NODE_MSG, ctx.getSelfId(), msg.getCustomerId(), new TbMsgMetaData(), msg.getId().toString());
            ctx.tellSelf(tickMsg, getDelay(msg));
            ctx.ack(msg);
        } else {
            ctx.tellFailure(msg, new RuntimeException("Max limit of pending messages reached!"));
        }
    }
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) TbMsg(org.thingsboard.server.common.msg.TbMsg)

Example 65 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbPubSubNode 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());
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData)

Aggregations

TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)89 TbMsg (org.thingsboard.server.common.msg.TbMsg)56 Test (org.junit.Test)49 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)26 Device (org.thingsboard.server.common.data.Device)17 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)17 List (java.util.List)16 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)16 DeviceId (org.thingsboard.server.common.data.id.DeviceId)15 EntityId (org.thingsboard.server.common.data.id.EntityId)15 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)14 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)14 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)14 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)14 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)14 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)14 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)13 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13