Search in sources :

Example 1 with ToRuleEngineNotificationMsg

use of org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg in project thingsboard by thingsboard.

the class DefaultTbClusterService method pushNotificationToRuleEngine.

@Override
public void pushNotificationToRuleEngine(String serviceId, FromDeviceRpcResponse response, TbQueueCallback callback) {
    TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceId);
    log.trace("PUSHING msg: {} to:{}", response, tpi);
    FromDeviceRPCResponseProto.Builder builder = FromDeviceRPCResponseProto.newBuilder().setRequestIdMSB(response.getId().getMostSignificantBits()).setRequestIdLSB(response.getId().getLeastSignificantBits()).setError(response.getError().isPresent() ? response.getError().get().ordinal() : -1);
    response.getResponse().ifPresent(builder::setResponse);
    ToRuleEngineNotificationMsg msg = ToRuleEngineNotificationMsg.newBuilder().setFromDeviceRpcResponse(builder).build();
    producerProvider.getRuleEngineNotificationsMsgProducer().send(tpi, new TbProtoQueueMsg<>(response.getId(), msg), callback);
    toRuleEngineNfs.incrementAndGet();
}
Also used : TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo) ToRuleEngineNotificationMsg(org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg) FromDeviceRPCResponseProto(org.thingsboard.server.gen.transport.TransportProtos.FromDeviceRPCResponseProto)

Example 2 with ToRuleEngineNotificationMsg

use of org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg in project thingsboard by thingsboard.

the class DefaultTbClusterService method broadcast.

private void broadcast(ComponentLifecycleMsg msg) {
    byte[] msgBytes = encodingService.encode(msg);
    TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> toRuleEngineProducer = producerProvider.getRuleEngineNotificationsMsgProducer();
    Set<String> tbRuleEngineServices = new HashSet<>(partitionService.getAllServiceIds(ServiceType.TB_RULE_ENGINE));
    EntityType entityType = msg.getEntityId().getEntityType();
    if (entityType.equals(EntityType.TENANT) || entityType.equals(EntityType.TENANT_PROFILE) || entityType.equals(EntityType.DEVICE_PROFILE) || entityType.equals(EntityType.API_USAGE_STATE) || (entityType.equals(EntityType.DEVICE) && msg.getEvent() == ComponentLifecycleEvent.UPDATED) || entityType.equals(EntityType.EDGE)) {
        TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> toCoreNfProducer = producerProvider.getTbCoreNotificationsMsgProducer();
        Set<String> tbCoreServices = partitionService.getAllServiceIds(ServiceType.TB_CORE);
        for (String serviceId : tbCoreServices) {
            TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceId);
            ToCoreNotificationMsg toCoreMsg = ToCoreNotificationMsg.newBuilder().setComponentLifecycleMsg(ByteString.copyFrom(msgBytes)).build();
            toCoreNfProducer.send(tpi, new TbProtoQueueMsg<>(msg.getEntityId().getId(), toCoreMsg), null);
            toCoreNfs.incrementAndGet();
        }
        // No need to push notifications twice
        tbRuleEngineServices.removeAll(tbCoreServices);
    }
    for (String serviceId : tbRuleEngineServices) {
        TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceId);
        ToRuleEngineNotificationMsg toRuleEngineMsg = ToRuleEngineNotificationMsg.newBuilder().setComponentLifecycleMsg(ByteString.copyFrom(msgBytes)).build();
        toRuleEngineProducer.send(tpi, new TbProtoQueueMsg<>(msg.getEntityId().getId(), toRuleEngineMsg), null);
        toRuleEngineNfs.incrementAndGet();
    }
}
Also used : EntityType(org.thingsboard.server.common.data.EntityType) ToCoreNotificationMsg(org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg) TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo) ToRuleEngineNotificationMsg(org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg) TbProtoQueueMsg(org.thingsboard.server.queue.common.TbProtoQueueMsg) ByteString(com.google.protobuf.ByteString) HashSet(java.util.HashSet)

Example 3 with ToRuleEngineNotificationMsg

use of org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg in project thingsboard by thingsboard.

the class DefaultTbRuleEngineConsumerService method handleNotification.

@Override
protected void handleNotification(UUID id, TbProtoQueueMsg<ToRuleEngineNotificationMsg> msg, TbCallback callback) throws Exception {
    ToRuleEngineNotificationMsg nfMsg = msg.getValue();
    if (nfMsg.getComponentLifecycleMsg() != null && !nfMsg.getComponentLifecycleMsg().isEmpty()) {
        handleComponentLifecycleMsg(id, nfMsg.getComponentLifecycleMsg());
        callback.onSuccess();
    } else if (nfMsg.hasFromDeviceRpcResponse()) {
        TransportProtos.FromDeviceRPCResponseProto proto = nfMsg.getFromDeviceRpcResponse();
        RpcError error = proto.getError() > 0 ? RpcError.values()[proto.getError()] : null;
        FromDeviceRpcResponse response = new FromDeviceRpcResponse(new UUID(proto.getRequestIdMSB(), proto.getRequestIdLSB()), proto.getResponse(), error);
        tbDeviceRpcService.processRpcResponseFromDevice(response);
        callback.onSuccess();
    } else {
        log.trace("Received notification with missing handler");
        callback.onSuccess();
    }
}
Also used : FromDeviceRpcResponse(org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse) ToRuleEngineNotificationMsg(org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg) RpcError(org.thingsboard.server.common.data.rpc.RpcError) UUID(java.util.UUID)

Aggregations

ToRuleEngineNotificationMsg (org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg)3 TopicPartitionInfo (org.thingsboard.server.common.msg.queue.TopicPartitionInfo)2 ByteString (com.google.protobuf.ByteString)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 EntityType (org.thingsboard.server.common.data.EntityType)1 RpcError (org.thingsboard.server.common.data.rpc.RpcError)1 FromDeviceRpcResponse (org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse)1 FromDeviceRPCResponseProto (org.thingsboard.server.gen.transport.TransportProtos.FromDeviceRPCResponseProto)1 ToCoreNotificationMsg (org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg)1 TbProtoQueueMsg (org.thingsboard.server.queue.common.TbProtoQueueMsg)1