Search in sources :

Example 6 with RuleEngineException

use of org.thingsboard.server.common.msg.queue.RuleEngineException in project thingsboard by thingsboard.

the class RuleChainActorMessageProcessor method onTellNext.

private void onTellNext(TbMsg msg, boolean useRuleNodeIdFromMsg) {
    try {
        checkComponentStateActive(msg);
        RuleNodeId targetId = useRuleNodeIdFromMsg ? msg.getRuleNodeId() : null;
        RuleNodeCtx targetCtx;
        if (targetId == null) {
            targetCtx = firstNode;
            msg = msg.copyWithRuleChainId(entityId);
        } else {
            targetCtx = nodeActors.get(targetId);
        }
        if (targetCtx != null) {
            log.trace("[{}][{}] Pushing message to target rule node", entityId, targetId);
            pushMsgToNode(targetCtx, msg, NA_RELATION_TYPE);
        } else {
            log.trace("[{}][{}] Rule node does not exist. Probably old message", entityId, targetId);
            msg.getCallback().onSuccess();
        }
    } catch (RuleNodeException rne) {
        msg.getCallback().onFailure(rne);
    } catch (Exception e) {
        msg.getCallback().onFailure(new RuleEngineException(e.getMessage()));
    }
}
Also used : RuleNodeException(org.thingsboard.server.common.msg.queue.RuleNodeException) RuleEngineException(org.thingsboard.server.common.msg.queue.RuleEngineException) RuleNodeException(org.thingsboard.server.common.msg.queue.RuleNodeException) RuleEngineException(org.thingsboard.server.common.msg.queue.RuleEngineException) RuleNodeId(org.thingsboard.server.common.data.id.RuleNodeId)

Example 7 with RuleEngineException

use of org.thingsboard.server.common.msg.queue.RuleEngineException in project thingsboard by thingsboard.

the class DefaultTbRuleEngineConsumerService method submitMessage.

void submitMessage(TbRuleEngineQueueConfiguration configuration, TbRuleEngineConsumerStats stats, TbMsgPackProcessingContext ctx, UUID id, TbProtoQueueMsg<ToRuleEngineMsg> msg) {
    log.trace("[{}] Creating callback for topic {} message: {}", id, configuration.getName(), msg.getValue());
    ToRuleEngineMsg toRuleEngineMsg = msg.getValue();
    TenantId tenantId = TenantId.fromUUID(new UUID(toRuleEngineMsg.getTenantIdMSB(), toRuleEngineMsg.getTenantIdLSB()));
    TbMsgCallback callback = prometheusStatsEnabled ? new TbMsgPackCallback(id, tenantId, ctx, stats.getTimer(tenantId, SUCCESSFUL_STATUS), stats.getTimer(tenantId, FAILED_STATUS)) : new TbMsgPackCallback(id, tenantId, ctx);
    try {
        if (toRuleEngineMsg.getTbMsg() != null && !toRuleEngineMsg.getTbMsg().isEmpty()) {
            forwardToRuleEngineActor(configuration.getName(), tenantId, toRuleEngineMsg, callback);
        } else {
            callback.onSuccess();
        }
    } catch (Exception e) {
        callback.onFailure(new RuleEngineException(e.getMessage()));
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleEngineException(org.thingsboard.server.common.msg.queue.RuleEngineException) UUID(java.util.UUID) QueueToRuleEngineMsg(org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg) ToRuleEngineMsg(org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg) TbMsgCallback(org.thingsboard.server.common.msg.queue.TbMsgCallback) RuleEngineException(org.thingsboard.server.common.msg.queue.RuleEngineException)

Example 8 with RuleEngineException

use of org.thingsboard.server.common.msg.queue.RuleEngineException in project thingsboard by thingsboard.

the class TbAbstractTransformNode method transformSuccess.

protected void transformSuccess(TbContext ctx, TbMsg msg, List<TbMsg> msgs) {
    if (msgs != null && !msgs.isEmpty()) {
        if (msgs.size() == 1) {
            ctx.tellSuccess(msgs.get(0));
        } else {
            TbMsgCallbackWrapper wrapper = new MultipleTbMsgsCallbackWrapper(msgs.size(), new TbMsgCallback() {

                @Override
                public void onSuccess() {
                    ctx.ack(msg);
                }

                @Override
                public void onFailure(RuleEngineException e) {
                    ctx.tellFailure(msg, e);
                }
            });
            msgs.forEach(newMsg -> ctx.enqueueForTellNext(newMsg, "Success", wrapper::onSuccess, wrapper::onFailure));
        }
    } else {
        ctx.tellNext(msg, FAILURE);
    }
}
Also used : RuleEngineException(org.thingsboard.server.common.msg.queue.RuleEngineException) TbMsgCallback(org.thingsboard.server.common.msg.queue.TbMsgCallback)

Aggregations

RuleEngineException (org.thingsboard.server.common.msg.queue.RuleEngineException)8 UUID (java.util.UUID)2 ToString (lombok.ToString)2 TbEntityActorId (org.thingsboard.server.actors.TbEntityActorId)2 RuleNodeId (org.thingsboard.server.common.data.id.RuleNodeId)2 TenantId (org.thingsboard.server.common.data.id.TenantId)2 TbMsg (org.thingsboard.server.common.msg.TbMsg)2 QueueToRuleEngineMsg (org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg)2 RuleNodeException (org.thingsboard.server.common.msg.queue.RuleNodeException)2 TbMsgCallback (org.thingsboard.server.common.msg.queue.TbMsgCallback)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 TbRelationTypes (org.thingsboard.rule.engine.api.TbRelationTypes)1 ActorSystemContext (org.thingsboard.server.actors.ActorSystemContext)1