Search in sources :

Example 36 with TopicPartitionInfo

use of org.thingsboard.server.common.msg.queue.TopicPartitionInfo 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 37 with TopicPartitionInfo

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

the class DefaultTbClusterService method pushNotificationToCore.

@Override
public void pushNotificationToCore(String serviceId, FromDeviceRpcResponse response, TbQueueCallback callback) {
    TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_CORE, 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);
    ToCoreNotificationMsg msg = ToCoreNotificationMsg.newBuilder().setFromDeviceRpcResponse(builder).build();
    producerProvider.getTbCoreNotificationsMsgProducer().send(tpi, new TbProtoQueueMsg<>(response.getId(), msg), callback);
    toCoreNfs.incrementAndGet();
}
Also used : ToCoreNotificationMsg(org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg) TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo) FromDeviceRPCResponseProto(org.thingsboard.server.gen.transport.TransportProtos.FromDeviceRPCResponseProto)

Example 38 with TopicPartitionInfo

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

the class DefaultTbClusterService method pushMsgToCore.

@Override
public void pushMsgToCore(TenantId tenantId, EntityId entityId, ToCoreMsg msg, TbQueueCallback callback) {
    TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, entityId);
    producerProvider.getTbCoreMsgProducer().send(tpi, new TbProtoQueueMsg<>(UUID.randomUUID(), msg), callback);
    toCoreMsgs.incrementAndGet();
}
Also used : TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo)

Example 39 with TopicPartitionInfo

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

the class DefaultTbClusterService method pushNotificationToTransport.

@Override
public void pushNotificationToTransport(String serviceId, ToTransportMsg response, TbQueueCallback callback) {
    if (serviceId == null || serviceId.isEmpty()) {
        log.trace("pushNotificationToTransport: skipping message without serviceId [{}], (ToTransportMsg) response [{}]", serviceId, response);
        if (callback != null) {
            // callback that message already sent, no useful payload expected
            callback.onSuccess(null);
        }
        return;
    }
    TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_TRANSPORT, serviceId);
    log.trace("PUSHING msg: {} to:{}", response, tpi);
    producerProvider.getTransportNotificationsMsgProducer().send(tpi, new TbProtoQueueMsg<>(UUID.randomUUID(), response), callback);
    toTransportNfs.incrementAndGet();
}
Also used : TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo)

Example 40 with TopicPartitionInfo

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

the class DefaultTbClusterService method pushMsgToCore.

@Override
public void pushMsgToCore(ToDeviceActorNotificationMsg msg, TbQueueCallback callback) {
    TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, msg.getTenantId(), msg.getDeviceId());
    log.trace("PUSHING msg: {} to:{}", msg, tpi);
    byte[] msgBytes = encodingService.encode(msg);
    ToCoreMsg toCoreMsg = ToCoreMsg.newBuilder().setToDeviceActorNotificationMsg(ByteString.copyFrom(msgBytes)).build();
    producerProvider.getTbCoreMsgProducer().send(tpi, new TbProtoQueueMsg<>(msg.getDeviceId().getId(), toCoreMsg), callback);
    toCoreMsgs.incrementAndGet();
}
Also used : ToCoreMsg(org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg) TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo)

Aggregations

TopicPartitionInfo (org.thingsboard.server.common.msg.queue.TopicPartitionInfo)50 ArrayList (java.util.ArrayList)10 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)10 TenantId (org.thingsboard.server.common.data.id.TenantId)7 TbProtoQueueMsg (org.thingsboard.server.queue.common.TbProtoQueueMsg)7 EntityId (org.thingsboard.server.common.data.id.EntityId)6 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)6 UUID (java.util.UUID)5 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Set (java.util.Set)4 PostConstruct (javax.annotation.PostConstruct)4 Slf4j (lombok.extern.slf4j.Slf4j)4 EntityType (org.thingsboard.server.common.data.EntityType)4 DeviceId (org.thingsboard.server.common.data.id.DeviceId)4 ServiceType (org.thingsboard.server.common.msg.queue.ServiceType)4 ToCoreNotificationMsg (org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg)4 ToRuleEngineMsg (org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg)4 ByteString (com.google.protobuf.ByteString)3