added rabbitmq queue arguments
This commit is contained in:
parent
2ad4ddf1fb
commit
283ad27cb5
@ -566,6 +566,12 @@ queue:
|
|||||||
automatic_recovery_enabled: "${TB_QUEUE_RABBIT_MQ_AUTOMATIC_RECOVERY_ENABLED:false}"
|
automatic_recovery_enabled: "${TB_QUEUE_RABBIT_MQ_AUTOMATIC_RECOVERY_ENABLED:false}"
|
||||||
connection_timeout: "${TB_QUEUE_RABBIT_MQ_CONNECTION_TIMEOUT:60000}"
|
connection_timeout: "${TB_QUEUE_RABBIT_MQ_CONNECTION_TIMEOUT:60000}"
|
||||||
handshake_timeout: "${TB_QUEUE_RABBIT_MQ_HANDSHAKE_TIMEOUT:10000}"
|
handshake_timeout: "${TB_QUEUE_RABBIT_MQ_HANDSHAKE_TIMEOUT:10000}"
|
||||||
|
queue-properties:
|
||||||
|
rule-engine: "${TB_QUEUE_RABBIT_MQ_RE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
core: "${TB_QUEUE_RABBIT_MQ_CORE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
transport-api: "${TB_QUEUE_RABBIT_MQ_TA_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
notifications: "${TB_QUEUE_RABBIT_MQ_NOTIFICATIONS_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
js-executor: "${TB_QUEUE_RABBIT_MQ_JE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
partitions:
|
partitions:
|
||||||
hash_function_name: "${TB_QUEUE_PARTITIONS_HASH_FUNCTION_NAME:murmur3_128}"
|
hash_function_name: "${TB_QUEUE_PARTITIONS_HASH_FUNCTION_NAME:murmur3_128}"
|
||||||
virtual_nodes_size: "${TB_QUEUE_PARTITIONS_VIRTUAL_NODES_SIZE:16}"
|
virtual_nodes_size: "${TB_QUEUE_PARTITIONS_VIRTUAL_NODES_SIZE:16}"
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import org.thingsboard.server.queue.TbQueueRequestTemplate;
|
|||||||
import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate;
|
import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate;
|
||||||
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
||||||
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
||||||
|
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
||||||
import org.thingsboard.server.queue.sqs.TbAwsSqsAdmin;
|
import org.thingsboard.server.queue.sqs.TbAwsSqsAdmin;
|
||||||
@ -47,8 +48,10 @@ public class AwsSqsTransportQueueFactory implements TbTransportQueueFactory {
|
|||||||
private final TbQueueTransportApiSettings transportApiSettings;
|
private final TbQueueTransportApiSettings transportApiSettings;
|
||||||
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
||||||
private final TbAwsSqsSettings sqsSettings;
|
private final TbAwsSqsSettings sqsSettings;
|
||||||
|
private final TbQueueCoreSettings coreSettings;
|
||||||
private final TbServiceInfoProvider serviceInfoProvider;
|
private final TbServiceInfoProvider serviceInfoProvider;
|
||||||
|
|
||||||
|
private final TbQueueAdmin coreAdmin;
|
||||||
private final TbQueueAdmin transportApiAdmin;
|
private final TbQueueAdmin transportApiAdmin;
|
||||||
private final TbQueueAdmin notificationAdmin;
|
private final TbQueueAdmin notificationAdmin;
|
||||||
|
|
||||||
@ -56,12 +59,15 @@ public class AwsSqsTransportQueueFactory implements TbTransportQueueFactory {
|
|||||||
TbQueueTransportNotificationSettings transportNotificationSettings,
|
TbQueueTransportNotificationSettings transportNotificationSettings,
|
||||||
TbAwsSqsSettings sqsSettings,
|
TbAwsSqsSettings sqsSettings,
|
||||||
TbServiceInfoProvider serviceInfoProvider,
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
|
TbQueueCoreSettings coreSettings,
|
||||||
TbAwsSqsQueueAttributes sqsQueueAttributes) {
|
TbAwsSqsQueueAttributes sqsQueueAttributes) {
|
||||||
this.transportApiSettings = transportApiSettings;
|
this.transportApiSettings = transportApiSettings;
|
||||||
this.transportNotificationSettings = transportNotificationSettings;
|
this.transportNotificationSettings = transportNotificationSettings;
|
||||||
this.sqsSettings = sqsSettings;
|
this.sqsSettings = sqsSettings;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
|
this.coreSettings = coreSettings;
|
||||||
|
|
||||||
|
this.coreAdmin = new TbAwsSqsAdmin(sqsSettings, sqsQueueAttributes.getCoreAttributes());
|
||||||
this.transportApiAdmin = new TbAwsSqsAdmin(sqsSettings, sqsQueueAttributes.getTransportApiAttributes());
|
this.transportApiAdmin = new TbAwsSqsAdmin(sqsSettings, sqsQueueAttributes.getTransportApiAttributes());
|
||||||
this.notificationAdmin = new TbAwsSqsAdmin(sqsSettings, sqsQueueAttributes.getNotificationsAttributes());
|
this.notificationAdmin = new TbAwsSqsAdmin(sqsSettings, sqsQueueAttributes.getNotificationsAttributes());
|
||||||
}
|
}
|
||||||
@ -94,7 +100,7 @@ public class AwsSqsTransportQueueFactory implements TbTransportQueueFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbAwsSqsProducerTemplate<>(transportApiAdmin, sqsSettings, transportApiSettings.getRequestsTopic());
|
return new TbAwsSqsProducerTemplate<>(coreAdmin, sqsSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -105,6 +111,9 @@ public class AwsSqsTransportQueueFactory implements TbTransportQueueFactory {
|
|||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
private void destroy() {
|
private void destroy() {
|
||||||
|
if (coreAdmin != null) {
|
||||||
|
coreAdmin.destroy();
|
||||||
|
}
|
||||||
if (transportApiAdmin != null) {
|
if (transportApiAdmin != null) {
|
||||||
transportApiAdmin.destroy();
|
transportApiAdmin.destroy();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,9 +32,9 @@ import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
|||||||
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
||||||
import org.thingsboard.server.queue.memory.InMemoryTbQueueConsumer;
|
import org.thingsboard.server.queue.memory.InMemoryTbQueueConsumer;
|
||||||
import org.thingsboard.server.queue.memory.InMemoryTbQueueProducer;
|
import org.thingsboard.server.queue.memory.InMemoryTbQueueProducer;
|
||||||
|
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
||||||
import org.thingsboard.server.queue.sqs.TbAwsSqsAdmin;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnExpression("'${queue.type:null}'=='in-memory' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')")
|
@ConditionalOnExpression("'${queue.type:null}'=='in-memory' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')")
|
||||||
@ -43,13 +43,16 @@ public class InMemoryTbTransportQueueFactory implements TbTransportQueueFactory
|
|||||||
private final TbQueueTransportApiSettings transportApiSettings;
|
private final TbQueueTransportApiSettings transportApiSettings;
|
||||||
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
||||||
private final TbServiceInfoProvider serviceInfoProvider;
|
private final TbServiceInfoProvider serviceInfoProvider;
|
||||||
|
private final TbQueueCoreSettings coreSettings;
|
||||||
|
|
||||||
public InMemoryTbTransportQueueFactory(TbQueueTransportApiSettings transportApiSettings,
|
public InMemoryTbTransportQueueFactory(TbQueueTransportApiSettings transportApiSettings,
|
||||||
TbQueueTransportNotificationSettings transportNotificationSettings,
|
TbQueueTransportNotificationSettings transportNotificationSettings,
|
||||||
TbServiceInfoProvider serviceInfoProvider) {
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
|
TbQueueCoreSettings coreSettings) {
|
||||||
this.transportApiSettings = transportApiSettings;
|
this.transportApiSettings = transportApiSettings;
|
||||||
this.transportNotificationSettings = transportNotificationSettings;
|
this.transportNotificationSettings = transportNotificationSettings;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
|
this.coreSettings = coreSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,7 +89,7 @@ public class InMemoryTbTransportQueueFactory implements TbTransportQueueFactory
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new InMemoryTbQueueProducer<>(transportApiSettings.getRequestsTopic());
|
return new InMemoryTbQueueProducer<>(coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -28,8 +28,10 @@ import org.thingsboard.server.queue.common.TbProtoJsQueueMsg;
|
|||||||
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
||||||
import org.thingsboard.server.queue.discovery.PartitionService;
|
import org.thingsboard.server.queue.discovery.PartitionService;
|
||||||
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
||||||
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqAdmin;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqConsumerTemplate;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqConsumerTemplate;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqProducerTemplate;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqProducerTemplate;
|
||||||
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqQueueArguments;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqSettings;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings;
|
import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings;
|
||||||
@ -37,6 +39,8 @@ import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
|||||||
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration;
|
import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq' && '${service.type:null}'=='monolith'")
|
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq' && '${service.type:null}'=='monolith'")
|
||||||
public class RabbitMqMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEngineQueueFactory {
|
public class RabbitMqMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEngineQueueFactory {
|
||||||
@ -48,7 +52,12 @@ public class RabbitMqMonolithQueueFactory implements TbCoreQueueFactory, TbRuleE
|
|||||||
private final TbQueueTransportApiSettings transportApiSettings;
|
private final TbQueueTransportApiSettings transportApiSettings;
|
||||||
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
||||||
private final TbRabbitMqSettings rabbitMqSettings;
|
private final TbRabbitMqSettings rabbitMqSettings;
|
||||||
private final TbQueueAdmin admin;
|
|
||||||
|
private final TbQueueAdmin coreAdmin;
|
||||||
|
private final TbQueueAdmin ruleEngineAdmin;
|
||||||
|
private final TbQueueAdmin jsExecutorAdmin;
|
||||||
|
private final TbQueueAdmin transportApiAdmin;
|
||||||
|
private final TbQueueAdmin notificationAdmin;
|
||||||
|
|
||||||
public RabbitMqMonolithQueueFactory(PartitionService partitionService, TbQueueCoreSettings coreSettings,
|
public RabbitMqMonolithQueueFactory(PartitionService partitionService, TbQueueCoreSettings coreSettings,
|
||||||
TbQueueRuleEngineSettings ruleEngineSettings,
|
TbQueueRuleEngineSettings ruleEngineSettings,
|
||||||
@ -56,7 +65,7 @@ public class RabbitMqMonolithQueueFactory implements TbCoreQueueFactory, TbRuleE
|
|||||||
TbQueueTransportApiSettings transportApiSettings,
|
TbQueueTransportApiSettings transportApiSettings,
|
||||||
TbQueueTransportNotificationSettings transportNotificationSettings,
|
TbQueueTransportNotificationSettings transportNotificationSettings,
|
||||||
TbRabbitMqSettings rabbitMqSettings,
|
TbRabbitMqSettings rabbitMqSettings,
|
||||||
TbQueueAdmin admin) {
|
TbRabbitMqQueueArguments queueArguments) {
|
||||||
this.partitionService = partitionService;
|
this.partitionService = partitionService;
|
||||||
this.coreSettings = coreSettings;
|
this.coreSettings = coreSettings;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
@ -64,73 +73,97 @@ public class RabbitMqMonolithQueueFactory implements TbCoreQueueFactory, TbRuleE
|
|||||||
this.transportApiSettings = transportApiSettings;
|
this.transportApiSettings = transportApiSettings;
|
||||||
this.transportNotificationSettings = transportNotificationSettings;
|
this.transportNotificationSettings = transportNotificationSettings;
|
||||||
this.rabbitMqSettings = rabbitMqSettings;
|
this.rabbitMqSettings = rabbitMqSettings;
|
||||||
this.admin = admin;
|
|
||||||
|
this.coreAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getCoreArgs());
|
||||||
|
this.ruleEngineAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getRuleEngineArgs());
|
||||||
|
this.jsExecutorAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getJsExecutorArgs());
|
||||||
|
this.transportApiAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getTransportApiArgs());
|
||||||
|
this.notificationAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getNotificationsArgs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, transportNotificationSettings.getNotificationsTopic());
|
return new TbRabbitMqProducerTemplate<>(notificationAdmin, rabbitMqSettings, transportNotificationSettings.getNotificationsTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, ruleEngineSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(ruleEngineAdmin, rabbitMqSettings, ruleEngineSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, ruleEngineSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(ruleEngineAdmin, rabbitMqSettings, ruleEngineSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) {
|
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings, ruleEngineSettings.getTopic(),
|
return new TbRabbitMqConsumerTemplate<>(ruleEngineAdmin, rabbitMqSettings, ruleEngineSettings.getTopic(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings,
|
return new TbRabbitMqConsumerTemplate<>(notificationAdmin, rabbitMqSettings,
|
||||||
partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(),
|
partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> createToCoreMsgConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> createToCoreMsgConsumer() {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic(),
|
return new TbRabbitMqConsumerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings,
|
return new TbRabbitMqConsumerTemplate<>(notificationAdmin, rabbitMqSettings,
|
||||||
partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(),
|
partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg>> createTransportApiRequestConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg>> createTransportApiRequestConsumer() {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings, transportApiSettings.getRequestsTopic(),
|
return new TbRabbitMqConsumerTemplate<>(transportApiAdmin, rabbitMqSettings, transportApiSettings.getRequestsTopic(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.TransportApiResponseMsg>> createTransportApiResponseProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.TransportApiResponseMsg>> createTransportApiResponseProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, transportApiSettings.getResponsesTopic());
|
return new TbRabbitMqProducerTemplate<>(transportApiAdmin, rabbitMqSettings, transportApiSettings.getResponsesTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueRequestTemplate<TbProtoJsQueueMsg<JsInvokeProtos.RemoteJsRequest>, TbProtoQueueMsg<JsInvokeProtos.RemoteJsResponse>> createRemoteJsRequestTemplate() {
|
public TbQueueRequestTemplate<TbProtoJsQueueMsg<JsInvokeProtos.RemoteJsRequest>, TbProtoQueueMsg<JsInvokeProtos.RemoteJsResponse>> createRemoteJsRequestTemplate() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
private void destroy() {
|
||||||
|
if (coreAdmin != null) {
|
||||||
|
coreAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (ruleEngineAdmin != null) {
|
||||||
|
ruleEngineAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (jsExecutorAdmin != null) {
|
||||||
|
jsExecutorAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (transportApiAdmin != null) {
|
||||||
|
transportApiAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (notificationAdmin != null) {
|
||||||
|
notificationAdmin.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,13 +34,17 @@ import org.thingsboard.server.queue.common.TbProtoJsQueueMsg;
|
|||||||
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
||||||
import org.thingsboard.server.queue.discovery.PartitionService;
|
import org.thingsboard.server.queue.discovery.PartitionService;
|
||||||
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
||||||
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqAdmin;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqConsumerTemplate;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqConsumerTemplate;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqProducerTemplate;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqProducerTemplate;
|
||||||
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqQueueArguments;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqSettings;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings;
|
import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq' && '${service.type:null}'=='tb-core'")
|
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq' && '${service.type:null}'=='tb-core'")
|
||||||
public class RabbitMqTbCoreQueueFactory implements TbCoreQueueFactory {
|
public class RabbitMqTbCoreQueueFactory implements TbCoreQueueFactory {
|
||||||
@ -51,7 +55,12 @@ public class RabbitMqTbCoreQueueFactory implements TbCoreQueueFactory {
|
|||||||
private final TbQueueTransportApiSettings transportApiSettings;
|
private final TbQueueTransportApiSettings transportApiSettings;
|
||||||
private final PartitionService partitionService;
|
private final PartitionService partitionService;
|
||||||
private final TbServiceInfoProvider serviceInfoProvider;
|
private final TbServiceInfoProvider serviceInfoProvider;
|
||||||
private final TbQueueAdmin admin;
|
|
||||||
|
private final TbQueueAdmin coreAdmin;
|
||||||
|
private final TbQueueAdmin ruleEngineAdmin;
|
||||||
|
private final TbQueueAdmin jsExecutorAdmin;
|
||||||
|
private final TbQueueAdmin transportApiAdmin;
|
||||||
|
private final TbQueueAdmin notificationAdmin;
|
||||||
|
|
||||||
public RabbitMqTbCoreQueueFactory(TbRabbitMqSettings rabbitMqSettings,
|
public RabbitMqTbCoreQueueFactory(TbRabbitMqSettings rabbitMqSettings,
|
||||||
TbQueueCoreSettings coreSettings,
|
TbQueueCoreSettings coreSettings,
|
||||||
@ -59,67 +68,91 @@ public class RabbitMqTbCoreQueueFactory implements TbCoreQueueFactory {
|
|||||||
TbQueueRuleEngineSettings ruleEngineSettings,
|
TbQueueRuleEngineSettings ruleEngineSettings,
|
||||||
PartitionService partitionService,
|
PartitionService partitionService,
|
||||||
TbServiceInfoProvider serviceInfoProvider,
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
TbQueueAdmin admin) {
|
TbRabbitMqQueueArguments queueArguments) {
|
||||||
this.rabbitMqSettings = rabbitMqSettings;
|
this.rabbitMqSettings = rabbitMqSettings;
|
||||||
this.coreSettings = coreSettings;
|
this.coreSettings = coreSettings;
|
||||||
this.transportApiSettings = transportApiSettings;
|
this.transportApiSettings = transportApiSettings;
|
||||||
this.ruleEngineSettings = ruleEngineSettings;
|
this.ruleEngineSettings = ruleEngineSettings;
|
||||||
this.partitionService = partitionService;
|
this.partitionService = partitionService;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
this.admin = admin;
|
|
||||||
|
this.coreAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getCoreArgs());
|
||||||
|
this.ruleEngineAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getRuleEngineArgs());
|
||||||
|
this.jsExecutorAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getJsExecutorArgs());
|
||||||
|
this.transportApiAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getTransportApiArgs());
|
||||||
|
this.notificationAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getNotificationsArgs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, ruleEngineSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(ruleEngineAdmin, rabbitMqSettings, ruleEngineSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic(),
|
return new TbRabbitMqConsumerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings,
|
return new TbRabbitMqConsumerTemplate<>(notificationAdmin, rabbitMqSettings,
|
||||||
partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(),
|
partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> createTransportApiRequestConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> createTransportApiRequestConsumer() {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings, transportApiSettings.getRequestsTopic(),
|
return new TbRabbitMqConsumerTemplate<>(transportApiAdmin, rabbitMqSettings, transportApiSettings.getRequestsTopic(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiResponseProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiResponseProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueRequestTemplate<TbProtoJsQueueMsg<JsInvokeProtos.RemoteJsRequest>, TbProtoQueueMsg<JsInvokeProtos.RemoteJsResponse>> createRemoteJsRequestTemplate() {
|
public TbQueueRequestTemplate<TbProtoJsQueueMsg<JsInvokeProtos.RemoteJsRequest>, TbProtoQueueMsg<JsInvokeProtos.RemoteJsResponse>> createRemoteJsRequestTemplate() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
private void destroy() {
|
||||||
|
if (coreAdmin != null) {
|
||||||
|
coreAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (ruleEngineAdmin != null) {
|
||||||
|
ruleEngineAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (jsExecutorAdmin != null) {
|
||||||
|
jsExecutorAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (transportApiAdmin != null) {
|
||||||
|
transportApiAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (notificationAdmin != null) {
|
||||||
|
notificationAdmin.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,13 +32,17 @@ import org.thingsboard.server.queue.common.TbProtoJsQueueMsg;
|
|||||||
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
||||||
import org.thingsboard.server.queue.discovery.PartitionService;
|
import org.thingsboard.server.queue.discovery.PartitionService;
|
||||||
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
||||||
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqAdmin;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqConsumerTemplate;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqConsumerTemplate;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqProducerTemplate;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqProducerTemplate;
|
||||||
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqQueueArguments;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqSettings;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings;
|
import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration;
|
import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq' && '${service.type:null}'=='tb-rule-engine'")
|
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq' && '${service.type:null}'=='tb-rule-engine'")
|
||||||
public class RabbitMqTbRuleEngineQueueFactory implements TbRuleEngineQueueFactory {
|
public class RabbitMqTbRuleEngineQueueFactory implements TbRuleEngineQueueFactory {
|
||||||
@ -48,55 +52,63 @@ public class RabbitMqTbRuleEngineQueueFactory implements TbRuleEngineQueueFactor
|
|||||||
private final TbServiceInfoProvider serviceInfoProvider;
|
private final TbServiceInfoProvider serviceInfoProvider;
|
||||||
private final TbQueueRuleEngineSettings ruleEngineSettings;
|
private final TbQueueRuleEngineSettings ruleEngineSettings;
|
||||||
private final TbRabbitMqSettings rabbitMqSettings;
|
private final TbRabbitMqSettings rabbitMqSettings;
|
||||||
private final TbQueueAdmin admin;
|
|
||||||
|
private final TbQueueAdmin coreAdmin;
|
||||||
|
private final TbQueueAdmin ruleEngineAdmin;
|
||||||
|
private final TbQueueAdmin jsExecutorAdmin;
|
||||||
|
private final TbQueueAdmin notificationAdmin;
|
||||||
|
|
||||||
public RabbitMqTbRuleEngineQueueFactory(PartitionService partitionService, TbQueueCoreSettings coreSettings,
|
public RabbitMqTbRuleEngineQueueFactory(PartitionService partitionService, TbQueueCoreSettings coreSettings,
|
||||||
TbQueueRuleEngineSettings ruleEngineSettings,
|
TbQueueRuleEngineSettings ruleEngineSettings,
|
||||||
TbServiceInfoProvider serviceInfoProvider,
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
TbRabbitMqSettings rabbitMqSettings,
|
TbRabbitMqSettings rabbitMqSettings,
|
||||||
TbQueueAdmin admin) {
|
TbRabbitMqQueueArguments queueArguments) {
|
||||||
this.partitionService = partitionService;
|
this.partitionService = partitionService;
|
||||||
this.coreSettings = coreSettings;
|
this.coreSettings = coreSettings;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
this.ruleEngineSettings = ruleEngineSettings;
|
this.ruleEngineSettings = ruleEngineSettings;
|
||||||
this.rabbitMqSettings = rabbitMqSettings;
|
this.rabbitMqSettings = rabbitMqSettings;
|
||||||
this.admin = admin;
|
|
||||||
|
this.coreAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getCoreArgs());
|
||||||
|
this.ruleEngineAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getRuleEngineArgs());
|
||||||
|
this.jsExecutorAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getJsExecutorArgs());
|
||||||
|
this.notificationAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getNotificationsArgs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, ruleEngineSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(ruleEngineAdmin, rabbitMqSettings, ruleEngineSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, coreSettings.getTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) {
|
public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings, ruleEngineSettings.getTopic(),
|
return new TbRabbitMqConsumerTemplate<>(ruleEngineAdmin, rabbitMqSettings, ruleEngineSettings.getTopic(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings,
|
return new TbRabbitMqConsumerTemplate<>(notificationAdmin, rabbitMqSettings,
|
||||||
partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(),
|
partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
@ -105,4 +117,20 @@ public class RabbitMqTbRuleEngineQueueFactory implements TbRuleEngineQueueFactor
|
|||||||
public TbQueueRequestTemplate<TbProtoJsQueueMsg<JsInvokeProtos.RemoteJsRequest>, TbProtoQueueMsg<JsInvokeProtos.RemoteJsResponse>> createRemoteJsRequestTemplate() {
|
public TbQueueRequestTemplate<TbProtoJsQueueMsg<JsInvokeProtos.RemoteJsRequest>, TbProtoQueueMsg<JsInvokeProtos.RemoteJsResponse>> createRemoteJsRequestTemplate() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
private void destroy() {
|
||||||
|
if (coreAdmin != null) {
|
||||||
|
coreAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (ruleEngineAdmin != null) {
|
||||||
|
ruleEngineAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (jsExecutorAdmin != null) {
|
||||||
|
jsExecutorAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (notificationAdmin != null) {
|
||||||
|
notificationAdmin.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,12 +30,17 @@ import org.thingsboard.server.queue.TbQueueRequestTemplate;
|
|||||||
import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate;
|
import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate;
|
||||||
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
import org.thingsboard.server.queue.common.TbProtoQueueMsg;
|
||||||
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
||||||
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqAdmin;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqConsumerTemplate;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqConsumerTemplate;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqProducerTemplate;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqProducerTemplate;
|
||||||
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqQueueArguments;
|
||||||
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqSettings;
|
import org.thingsboard.server.queue.rabbitmq.TbRabbitMqSettings;
|
||||||
|
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')")
|
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -43,34 +48,45 @@ public class RabbitMqTransportQueueFactory implements TbTransportQueueFactory {
|
|||||||
private final TbQueueTransportApiSettings transportApiSettings;
|
private final TbQueueTransportApiSettings transportApiSettings;
|
||||||
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
||||||
private final TbRabbitMqSettings rabbitMqSettings;
|
private final TbRabbitMqSettings rabbitMqSettings;
|
||||||
private final TbQueueAdmin admin;
|
|
||||||
private final TbServiceInfoProvider serviceInfoProvider;
|
private final TbServiceInfoProvider serviceInfoProvider;
|
||||||
|
private final TbQueueCoreSettings coreSettings;
|
||||||
|
|
||||||
|
private final TbQueueAdmin coreAdmin;
|
||||||
|
private final TbQueueAdmin ruleEngineAdmin;
|
||||||
|
private final TbQueueAdmin transportApiAdmin;
|
||||||
|
private final TbQueueAdmin notificationAdmin;
|
||||||
|
|
||||||
public RabbitMqTransportQueueFactory(TbQueueTransportApiSettings transportApiSettings,
|
public RabbitMqTransportQueueFactory(TbQueueTransportApiSettings transportApiSettings,
|
||||||
TbQueueTransportNotificationSettings transportNotificationSettings,
|
TbQueueTransportNotificationSettings transportNotificationSettings,
|
||||||
TbRabbitMqSettings rabbitMqSettings,
|
TbRabbitMqSettings rabbitMqSettings,
|
||||||
TbServiceInfoProvider serviceInfoProvider,
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
TbQueueAdmin admin) {
|
TbQueueCoreSettings coreSettings,
|
||||||
|
TbRabbitMqQueueArguments queueArguments) {
|
||||||
this.transportApiSettings = transportApiSettings;
|
this.transportApiSettings = transportApiSettings;
|
||||||
this.transportNotificationSettings = transportNotificationSettings;
|
this.transportNotificationSettings = transportNotificationSettings;
|
||||||
this.rabbitMqSettings = rabbitMqSettings;
|
this.rabbitMqSettings = rabbitMqSettings;
|
||||||
this.admin = admin;
|
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
|
this.coreSettings = coreSettings;
|
||||||
|
|
||||||
|
this.coreAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getCoreArgs());
|
||||||
|
this.ruleEngineAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getRuleEngineArgs());
|
||||||
|
this.transportApiAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getTransportApiArgs());
|
||||||
|
this.notificationAdmin = new TbRabbitMqAdmin(rabbitMqSettings, queueArguments.getNotificationsArgs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiRequestTemplate() {
|
public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiRequestTemplate() {
|
||||||
TbRabbitMqProducerTemplate<TbProtoQueueMsg<TransportApiRequestMsg>> producerTemplate =
|
TbRabbitMqProducerTemplate<TbProtoQueueMsg<TransportApiRequestMsg>> producerTemplate =
|
||||||
new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, transportApiSettings.getRequestsTopic());
|
new TbRabbitMqProducerTemplate<>(transportApiAdmin, rabbitMqSettings, transportApiSettings.getRequestsTopic());
|
||||||
|
|
||||||
TbRabbitMqConsumerTemplate<TbProtoQueueMsg<TransportApiResponseMsg>> consumerTemplate =
|
TbRabbitMqConsumerTemplate<TbProtoQueueMsg<TransportApiResponseMsg>> consumerTemplate =
|
||||||
new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings,
|
new TbRabbitMqConsumerTemplate<>(transportApiAdmin, rabbitMqSettings,
|
||||||
transportApiSettings.getResponsesTopic() + "." + serviceInfoProvider.getServiceId(),
|
transportApiSettings.getResponsesTopic() + "." + serviceInfoProvider.getServiceId(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiResponseMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiResponseMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
|
|
||||||
DefaultTbQueueRequestTemplate.DefaultTbQueueRequestTemplateBuilder
|
DefaultTbQueueRequestTemplate.DefaultTbQueueRequestTemplateBuilder
|
||||||
<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> templateBuilder = DefaultTbQueueRequestTemplate.builder();
|
<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> templateBuilder = DefaultTbQueueRequestTemplate.builder();
|
||||||
templateBuilder.queueAdmin(admin);
|
templateBuilder.queueAdmin(transportApiAdmin);
|
||||||
templateBuilder.requestTemplate(producerTemplate);
|
templateBuilder.requestTemplate(producerTemplate);
|
||||||
templateBuilder.responseTemplate(consumerTemplate);
|
templateBuilder.responseTemplate(consumerTemplate);
|
||||||
templateBuilder.maxPendingRequests(transportApiSettings.getMaxPendingRequests());
|
templateBuilder.maxPendingRequests(transportApiSettings.getMaxPendingRequests());
|
||||||
@ -81,17 +97,33 @@ public class RabbitMqTransportQueueFactory implements TbTransportQueueFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, transportApiSettings.getRequestsTopic());
|
return new TbRabbitMqProducerTemplate<>(transportApiAdmin, rabbitMqSettings, transportApiSettings.getRequestsTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbRabbitMqProducerTemplate<>(admin, rabbitMqSettings, transportApiSettings.getRequestsTopic());
|
return new TbRabbitMqProducerTemplate<>(coreAdmin, rabbitMqSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsConsumer() {
|
||||||
return new TbRabbitMqConsumerTemplate<>(admin, rabbitMqSettings, transportNotificationSettings.getNotificationsTopic() + "." + serviceInfoProvider.getServiceId(),
|
return new TbRabbitMqConsumerTemplate<>(notificationAdmin, rabbitMqSettings, transportNotificationSettings.getNotificationsTopic() + "." + serviceInfoProvider.getServiceId(),
|
||||||
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToTransportMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
msg -> new TbProtoQueueMsg<>(msg.getKey(), ToTransportMsg.parseFrom(msg.getData()), msg.getHeaders()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
private void destroy() {
|
||||||
|
if (coreAdmin != null) {
|
||||||
|
coreAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (ruleEngineAdmin != null) {
|
||||||
|
ruleEngineAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (transportApiAdmin != null) {
|
||||||
|
transportApiAdmin.destroy();
|
||||||
|
}
|
||||||
|
if (notificationAdmin != null) {
|
||||||
|
notificationAdmin.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
|||||||
import org.thingsboard.server.queue.azure.servicebus.TbServiceBusConsumerTemplate;
|
import org.thingsboard.server.queue.azure.servicebus.TbServiceBusConsumerTemplate;
|
||||||
import org.thingsboard.server.queue.azure.servicebus.TbServiceBusProducerTemplate;
|
import org.thingsboard.server.queue.azure.servicebus.TbServiceBusProducerTemplate;
|
||||||
import org.thingsboard.server.queue.azure.servicebus.TbServiceBusSettings;
|
import org.thingsboard.server.queue.azure.servicebus.TbServiceBusSettings;
|
||||||
|
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
||||||
|
|
||||||
@ -41,17 +42,20 @@ public class ServiceBusTransportQueueFactory implements TbTransportQueueFactory
|
|||||||
private final TbServiceBusSettings serviceBusSettings;
|
private final TbServiceBusSettings serviceBusSettings;
|
||||||
private final TbQueueAdmin admin;
|
private final TbQueueAdmin admin;
|
||||||
private final TbServiceInfoProvider serviceInfoProvider;
|
private final TbServiceInfoProvider serviceInfoProvider;
|
||||||
|
private final TbQueueCoreSettings coreSettings;
|
||||||
|
|
||||||
public ServiceBusTransportQueueFactory(TbQueueTransportApiSettings transportApiSettings,
|
public ServiceBusTransportQueueFactory(TbQueueTransportApiSettings transportApiSettings,
|
||||||
TbQueueTransportNotificationSettings transportNotificationSettings,
|
TbQueueTransportNotificationSettings transportNotificationSettings,
|
||||||
TbServiceBusSettings serviceBusSettings,
|
TbServiceBusSettings serviceBusSettings,
|
||||||
TbServiceInfoProvider serviceInfoProvider,
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
|
TbQueueCoreSettings coreSettings,
|
||||||
TbQueueAdmin admin) {
|
TbQueueAdmin admin) {
|
||||||
this.transportApiSettings = transportApiSettings;
|
this.transportApiSettings = transportApiSettings;
|
||||||
this.transportNotificationSettings = transportNotificationSettings;
|
this.transportNotificationSettings = transportNotificationSettings;
|
||||||
this.serviceBusSettings = serviceBusSettings;
|
this.serviceBusSettings = serviceBusSettings;
|
||||||
this.admin = admin;
|
this.admin = admin;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
|
this.coreSettings = coreSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -82,7 +86,7 @@ public class ServiceBusTransportQueueFactory implements TbTransportQueueFactory
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbServiceBusProducerTemplate<>(admin, serviceBusSettings, transportApiSettings.getRequestsTopic());
|
return new TbServiceBusProducerTemplate<>(admin, serviceBusSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -18,24 +18,23 @@ package org.thingsboard.server.queue.rabbitmq;
|
|||||||
import com.rabbitmq.client.Channel;
|
import com.rabbitmq.client.Channel;
|
||||||
import com.rabbitmq.client.Connection;
|
import com.rabbitmq.client.Connection;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.thingsboard.server.queue.TbQueueAdmin;
|
import org.thingsboard.server.queue.TbQueueAdmin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
|
||||||
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq'")
|
|
||||||
public class TbRabbitMqAdmin implements TbQueueAdmin {
|
public class TbRabbitMqAdmin implements TbQueueAdmin {
|
||||||
|
|
||||||
private final TbRabbitMqSettings rabbitMqSettings;
|
private final TbRabbitMqSettings rabbitMqSettings;
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
private final Connection connection;
|
private final Connection connection;
|
||||||
|
private final Map<String, Object> arguments;
|
||||||
|
|
||||||
public TbRabbitMqAdmin(TbRabbitMqSettings rabbitMqSettings) {
|
public TbRabbitMqAdmin(TbRabbitMqSettings rabbitMqSettings, Map<String, Object> arguments) {
|
||||||
this.rabbitMqSettings = rabbitMqSettings;
|
this.rabbitMqSettings = rabbitMqSettings;
|
||||||
|
this.arguments = arguments;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection = rabbitMqSettings.getConnectionFactory().newConnection();
|
connection = rabbitMqSettings.getConnectionFactory().newConnection();
|
||||||
@ -55,7 +54,7 @@ public class TbRabbitMqAdmin implements TbQueueAdmin {
|
|||||||
@Override
|
@Override
|
||||||
public void createTopicIfNotExists(String topic) {
|
public void createTopicIfNotExists(String topic) {
|
||||||
try {
|
try {
|
||||||
channel.queueDeclare(topic, false, false, false, null);
|
channel.queueDeclare(topic, false, false, false, arguments);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Failed to bind queue: [{}]", topic, e);
|
log.error("Failed to bind queue: [{}]", topic, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,98 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2020 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.thingsboard.server.queue.rabbitmq;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ConditionalOnExpression("'${queue.type:null}'=='rabbitmq'")
|
||||||
|
public class TbRabbitMqQueueArguments {
|
||||||
|
@Value("${queue.rabbitmq.queue-properties.core}")
|
||||||
|
private String coreProperties;
|
||||||
|
@Value("${queue.rabbitmq.queue-properties.rule-engine}")
|
||||||
|
private String ruleEngineProperties;
|
||||||
|
@Value("${queue.rabbitmq.queue-properties.transport-api}")
|
||||||
|
private String transportApiProperties;
|
||||||
|
@Value("${queue.rabbitmq.queue-properties.notifications}")
|
||||||
|
private String notificationsProperties;
|
||||||
|
@Value("${queue.rabbitmq.queue-properties.js-executor}")
|
||||||
|
private String jsExecutorProperties;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Map<String, Object> coreArgs;
|
||||||
|
@Getter
|
||||||
|
private Map<String, Object> ruleEngineArgs;
|
||||||
|
@Getter
|
||||||
|
private Map<String, Object> transportApiArgs;
|
||||||
|
@Getter
|
||||||
|
private Map<String, Object> notificationsArgs;
|
||||||
|
@Getter
|
||||||
|
private Map<String, Object> jsExecutorArgs;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() {
|
||||||
|
coreArgs = getArgs(coreProperties);
|
||||||
|
ruleEngineArgs = getArgs(ruleEngineProperties);
|
||||||
|
transportApiArgs = getArgs(transportApiProperties);
|
||||||
|
notificationsArgs = getArgs(notificationsProperties);
|
||||||
|
jsExecutorArgs = getArgs(jsExecutorProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> getArgs(String properties) {
|
||||||
|
Map<String, Object> configs = new HashMap<>();
|
||||||
|
for (String property : properties.split(";")) {
|
||||||
|
int delimiterPosition = property.indexOf(":");
|
||||||
|
String key = property.substring(0, delimiterPosition);
|
||||||
|
String strValue = property.substring(delimiterPosition + 1);
|
||||||
|
configs.put(key, getObjectValue(strValue));
|
||||||
|
}
|
||||||
|
return configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getObjectValue(String str) {
|
||||||
|
if (str.equalsIgnoreCase("true") || str.equalsIgnoreCase("false")) {
|
||||||
|
return Boolean.valueOf(str);
|
||||||
|
} else if (isNumeric(str)) {
|
||||||
|
return getNumericValue(str);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getNumericValue(String str) {
|
||||||
|
if (str.contains(".")) {
|
||||||
|
return Double.valueOf(str);
|
||||||
|
} else {
|
||||||
|
return Long.valueOf(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Pattern PATTERN = Pattern.compile("-?\\d+(\\.\\d+)?");
|
||||||
|
|
||||||
|
public boolean isNumeric(String strNum) {
|
||||||
|
if (strNum == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return PATTERN.matcher(strNum).matches();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -95,6 +95,12 @@ queue:
|
|||||||
automatic_recovery_enabled: "${TB_QUEUE_RABBIT_MQ_AUTOMATIC_RECOVERY_ENABLED:false}"
|
automatic_recovery_enabled: "${TB_QUEUE_RABBIT_MQ_AUTOMATIC_RECOVERY_ENABLED:false}"
|
||||||
connection_timeout: "${TB_QUEUE_RABBIT_MQ_CONNECTION_TIMEOUT:60000}"
|
connection_timeout: "${TB_QUEUE_RABBIT_MQ_CONNECTION_TIMEOUT:60000}"
|
||||||
handshake_timeout: "${TB_QUEUE_RABBIT_MQ_HANDSHAKE_TIMEOUT:10000}"
|
handshake_timeout: "${TB_QUEUE_RABBIT_MQ_HANDSHAKE_TIMEOUT:10000}"
|
||||||
|
queue-properties:
|
||||||
|
rule-engine: "${TB_QUEUE_RABBIT_MQ_RE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
core: "${TB_QUEUE_RABBIT_MQ_CORE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
transport-api: "${TB_QUEUE_RABBIT_MQ_TA_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
notifications: "${TB_QUEUE_RABBIT_MQ_NOTIFICATIONS_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
js-executor: "${TB_QUEUE_RABBIT_MQ_JE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
partitions:
|
partitions:
|
||||||
hash_function_name: "${TB_QUEUE_PARTITIONS_HASH_FUNCTION_NAME:murmur3_128}"
|
hash_function_name: "${TB_QUEUE_PARTITIONS_HASH_FUNCTION_NAME:murmur3_128}"
|
||||||
virtual_nodes_size: "${TB_QUEUE_PARTITIONS_VIRTUAL_NODES_SIZE:16}"
|
virtual_nodes_size: "${TB_QUEUE_PARTITIONS_VIRTUAL_NODES_SIZE:16}"
|
||||||
|
|||||||
@ -96,6 +96,12 @@ queue:
|
|||||||
automatic_recovery_enabled: "${TB_QUEUE_RABBIT_MQ_AUTOMATIC_RECOVERY_ENABLED:false}"
|
automatic_recovery_enabled: "${TB_QUEUE_RABBIT_MQ_AUTOMATIC_RECOVERY_ENABLED:false}"
|
||||||
connection_timeout: "${TB_QUEUE_RABBIT_MQ_CONNECTION_TIMEOUT:60000}"
|
connection_timeout: "${TB_QUEUE_RABBIT_MQ_CONNECTION_TIMEOUT:60000}"
|
||||||
handshake_timeout: "${TB_QUEUE_RABBIT_MQ_HANDSHAKE_TIMEOUT:10000}"
|
handshake_timeout: "${TB_QUEUE_RABBIT_MQ_HANDSHAKE_TIMEOUT:10000}"
|
||||||
|
queue-properties:
|
||||||
|
rule-engine: "${TB_QUEUE_RABBIT_MQ_RE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
core: "${TB_QUEUE_RABBIT_MQ_CORE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
transport-api: "${TB_QUEUE_RABBIT_MQ_TA_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
notifications: "${TB_QUEUE_RABBIT_MQ_NOTIFICATIONS_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
js-executor: "${TB_QUEUE_RABBIT_MQ_JE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
partitions:
|
partitions:
|
||||||
hash_function_name: "${TB_QUEUE_PARTITIONS_HASH_FUNCTION_NAME:murmur3_128}"
|
hash_function_name: "${TB_QUEUE_PARTITIONS_HASH_FUNCTION_NAME:murmur3_128}"
|
||||||
virtual_nodes_size: "${TB_QUEUE_PARTITIONS_VIRTUAL_NODES_SIZE:16}"
|
virtual_nodes_size: "${TB_QUEUE_PARTITIONS_VIRTUAL_NODES_SIZE:16}"
|
||||||
|
|||||||
@ -126,6 +126,12 @@ queue:
|
|||||||
automatic_recovery_enabled: "${TB_QUEUE_RABBIT_MQ_AUTOMATIC_RECOVERY_ENABLED:false}"
|
automatic_recovery_enabled: "${TB_QUEUE_RABBIT_MQ_AUTOMATIC_RECOVERY_ENABLED:false}"
|
||||||
connection_timeout: "${TB_QUEUE_RABBIT_MQ_CONNECTION_TIMEOUT:60000}"
|
connection_timeout: "${TB_QUEUE_RABBIT_MQ_CONNECTION_TIMEOUT:60000}"
|
||||||
handshake_timeout: "${TB_QUEUE_RABBIT_MQ_HANDSHAKE_TIMEOUT:10000}"
|
handshake_timeout: "${TB_QUEUE_RABBIT_MQ_HANDSHAKE_TIMEOUT:10000}"
|
||||||
|
queue-properties:
|
||||||
|
rule-engine: "${TB_QUEUE_RABBIT_MQ_RE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
core: "${TB_QUEUE_RABBIT_MQ_CORE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
transport-api: "${TB_QUEUE_RABBIT_MQ_TA_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
notifications: "${TB_QUEUE_RABBIT_MQ_NOTIFICATIONS_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
|
js-executor: "${TB_QUEUE_RABBIT_MQ_JE_QUEUE_PROPERTIES:x-max-length-bytes:1048576000;x-message-ttl:604800000}"
|
||||||
partitions:
|
partitions:
|
||||||
hash_function_name: "${TB_QUEUE_PARTITIONS_HASH_FUNCTION_NAME:murmur3_128}"
|
hash_function_name: "${TB_QUEUE_PARTITIONS_HASH_FUNCTION_NAME:murmur3_128}"
|
||||||
virtual_nodes_size: "${TB_QUEUE_PARTITIONS_VIRTUAL_NODES_SIZE:16}"
|
virtual_nodes_size: "${TB_QUEUE_PARTITIONS_VIRTUAL_NODES_SIZE:16}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user