@ -22,11 +22,13 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import org.thingsboard.rule.engine.api.RpcError ;
import org.thingsboard.rule.engine.api.RpcError ;
import org.thingsboard.server.actors.ActorSystemContext ;
import org.thingsboard.server.actors.ActorSystemContext ;
import org.thingsboard.server.common.data.id.RuleNodeId ;
import org.thingsboard.server.common.data.id.TenantId ;
import org.thingsboard.server.common.data.id.TenantId ;
import org.thingsboard.server.common.msg.TbActorMsg ;
import org.thingsboard.server.common.msg.TbActorMsg ;
import org.thingsboard.server.common.msg.TbMsg ;
import org.thingsboard.server.common.msg.TbMsg ;
import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg ;
import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg ;
import org.thingsboard.server.common.msg.queue.RuleEngineException ;
import org.thingsboard.server.common.msg.queue.RuleEngineException ;
import org.thingsboard.server.common.msg.queue.RuleNodeInfo ;
import org.thingsboard.server.common.msg.queue.ServiceQueue ;
import org.thingsboard.server.common.msg.queue.ServiceQueue ;
import org.thingsboard.server.common.msg.queue.ServiceType ;
import org.thingsboard.server.common.msg.queue.ServiceType ;
import org.thingsboard.server.common.msg.queue.TbCallback ;
import org.thingsboard.server.common.msg.queue.TbCallback ;
@ -59,6 +61,7 @@ import javax.annotation.PreDestroy;
import java.util.Collections ;
import java.util.Collections ;
import java.util.HashSet ;
import java.util.HashSet ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Optional ;
import java.util.Optional ;
import java.util.Set ;
import java.util.Set ;
import java.util.UUID ;
import java.util.UUID ;
@ -185,6 +188,12 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<
}
}
TbRuleEngineProcessingResult result = new TbRuleEngineProcessingResult ( configuration . getName ( ) , timeout , ctx ) ;
TbRuleEngineProcessingResult result = new TbRuleEngineProcessingResult ( configuration . getName ( ) , timeout , ctx ) ;
if ( timeout ) {
printFirstOrAll ( configuration , ctx , ctx . getPendingMap ( ) , "Timeout" ) ;
}
if ( ! ctx . getFailedMap ( ) . isEmpty ( ) ) {
printFirstOrAll ( configuration , ctx , ctx . getFailedMap ( ) , "Failed" ) ;
}
TbRuleEngineProcessingDecision decision = ackStrategy . analyze ( result ) ;
TbRuleEngineProcessingDecision decision = ackStrategy . analyze ( result ) ;
if ( statsEnabled ) {
if ( statsEnabled ) {
stats . log ( result , decision . isCommit ( ) ) ;
stats . log ( result , decision . isCommit ( ) ) ;
@ -212,6 +221,22 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<
} ) ;
} ) ;
}
}
private void printFirstOrAll ( TbRuleEngineQueueConfiguration configuration , TbMsgPackProcessingContext ctx , Map < UUID , TbProtoQueueMsg < ToRuleEngineMsg > > map , String prefix ) {
boolean printAll = log . isTraceEnabled ( ) ;
log . info ( "{} to process [{}] messages" , prefix , map . size ( ) ) ;
for ( Map . Entry < UUID , TbProtoQueueMsg < ToRuleEngineMsg > > pending : map . entrySet ( ) ) {
ToRuleEngineMsg tmp = pending . getValue ( ) . getValue ( ) ;
TbMsg tmpMsg = TbMsg . fromBytes ( configuration . getName ( ) , tmp . getTbMsg ( ) . toByteArray ( ) , TbMsgCallback . EMPTY ) ;
RuleNodeInfo ruleNodeInfo = ctx . getLastVisitedRuleNode ( pending . getKey ( ) ) ;
if ( printAll ) {
log . trace ( "[{}] {} to process message: {}, Last Rule Node: {}" , new TenantId ( new UUID ( tmp . getTenantIdMSB ( ) , tmp . getTenantIdLSB ( ) ) ) , prefix , tmpMsg , ruleNodeInfo ) ;
} else {
log . info ( "[{}] {} to process message: {}, Last Rule Node: {}" , new TenantId ( new UUID ( tmp . getTenantIdMSB ( ) , tmp . getTenantIdLSB ( ) ) ) , prefix , tmpMsg , ruleNodeInfo ) ;
break ;
}
}
}
@Override
@Override
protected ServiceType getServiceType ( ) {
protected ServiceType getServiceType ( ) {
return ServiceType . TB_RULE_ENGINE ;
return ServiceType . TB_RULE_ENGINE ;