created TbPubSubSubscriptionSettings
This commit is contained in:
parent
58d9c313a8
commit
1b9df18c45
@ -543,9 +543,14 @@ queue:
|
|||||||
pubsub:
|
pubsub:
|
||||||
project_id: "${TB_QUEUE_PUBSUB_PROJECT_ID:YOUR_PROJECT_ID}"
|
project_id: "${TB_QUEUE_PUBSUB_PROJECT_ID:YOUR_PROJECT_ID}"
|
||||||
service_account: "${TB_QUEUE_PUBSUB_SERVICE_ACCOUNT:YOUR_SERVICE_ACCOUNT}"
|
service_account: "${TB_QUEUE_PUBSUB_SERVICE_ACCOUNT:YOUR_SERVICE_ACCOUNT}"
|
||||||
ack_deadline: "${TB_QUEUE_PUBSUB_ACK_DEADLINE:30}" #In seconds. If messages wont commit in this time, messages will poll again
|
|
||||||
max_msg_size: "${TB_QUEUE_PUBSUB_MAX_MSG_SIZE:1048576}" #in bytes
|
max_msg_size: "${TB_QUEUE_PUBSUB_MAX_MSG_SIZE:1048576}" #in bytes
|
||||||
max_messages: "${TB_QUEUE_PUBSUB_MAX_MESSAGES:1000}"
|
max_messages: "${TB_QUEUE_PUBSUB_MAX_MESSAGES:1000}"
|
||||||
|
queue-properties:
|
||||||
|
rule-engine: "${TB_QUEUE_PUBSUB_RE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
core: "${TB_QUEUE_PUBSUB_CORE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
transport-api: "${TB_QUEUE_PUBSUB_TA_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
notifications: "${TB_QUEUE_PUBSUB_NOTIFICATIONS_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
js-executor: "${TB_QUEUE_PUBSUB_JE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
service_bus:
|
service_bus:
|
||||||
namespace_name: "${TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME:YOUR_NAMESPACE_NAME}"
|
namespace_name: "${TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME:YOUR_NAMESPACE_NAME}"
|
||||||
sas_key_name: "${TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME:YOUR_SAS_KEY_NAME}"
|
sas_key_name: "${TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME:YOUR_SAS_KEY_NAME}"
|
||||||
|
|||||||
@ -38,6 +38,7 @@ import org.thingsboard.server.queue.pubsub.TbPubSubAdmin;
|
|||||||
import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate;
|
import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate;
|
||||||
import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate;
|
import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate;
|
||||||
import org.thingsboard.server.queue.pubsub.TbPubSubSettings;
|
import org.thingsboard.server.queue.pubsub.TbPubSubSettings;
|
||||||
|
import org.thingsboard.server.queue.pubsub.TbPubSubSubscriptionSettings;
|
||||||
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;
|
||||||
@ -53,88 +54,99 @@ public class PubSubMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEng
|
|||||||
private final TbQueueRuleEngineSettings ruleEngineSettings;
|
private final TbQueueRuleEngineSettings ruleEngineSettings;
|
||||||
private final TbQueueTransportApiSettings transportApiSettings;
|
private final TbQueueTransportApiSettings transportApiSettings;
|
||||||
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
||||||
private final TbQueueAdmin admin;
|
|
||||||
private final PartitionService partitionService;
|
private final PartitionService partitionService;
|
||||||
private final TbServiceInfoProvider serviceInfoProvider;
|
private final TbServiceInfoProvider serviceInfoProvider;
|
||||||
|
|
||||||
|
private final TbQueueAdmin coreAdmin;
|
||||||
|
private final TbQueueAdmin ruleEngineAdmin;
|
||||||
|
private final TbQueueAdmin jsExecutorAdmin;
|
||||||
|
private final TbQueueAdmin transportApiAdmin;
|
||||||
|
private final TbQueueAdmin notificationAdmin;
|
||||||
|
|
||||||
public PubSubMonolithQueueFactory(TbPubSubSettings pubSubSettings,
|
public PubSubMonolithQueueFactory(TbPubSubSettings pubSubSettings,
|
||||||
TbQueueCoreSettings coreSettings,
|
TbQueueCoreSettings coreSettings,
|
||||||
TbQueueRuleEngineSettings ruleEngineSettings,
|
TbQueueRuleEngineSettings ruleEngineSettings,
|
||||||
TbQueueTransportApiSettings transportApiSettings,
|
TbQueueTransportApiSettings transportApiSettings,
|
||||||
TbQueueTransportNotificationSettings transportNotificationSettings,
|
TbQueueTransportNotificationSettings transportNotificationSettings,
|
||||||
PartitionService partitionService,
|
PartitionService partitionService,
|
||||||
TbServiceInfoProvider serviceInfoProvider) {
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
|
TbPubSubSubscriptionSettings pubSubSubscriptionSettings) {
|
||||||
this.pubSubSettings = pubSubSettings;
|
this.pubSubSettings = pubSubSettings;
|
||||||
this.coreSettings = coreSettings;
|
this.coreSettings = coreSettings;
|
||||||
this.ruleEngineSettings = ruleEngineSettings;
|
this.ruleEngineSettings = ruleEngineSettings;
|
||||||
this.transportApiSettings = transportApiSettings;
|
this.transportApiSettings = transportApiSettings;
|
||||||
this.transportNotificationSettings = transportNotificationSettings;
|
this.transportNotificationSettings = transportNotificationSettings;
|
||||||
this.admin = new TbPubSubAdmin(pubSubSettings);
|
|
||||||
this.partitionService = partitionService;
|
this.partitionService = partitionService;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
|
|
||||||
|
this.coreAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getCoreSettings());
|
||||||
|
this.ruleEngineAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getRuleEngineSettings());
|
||||||
|
this.jsExecutorAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getJsExecutorSettings());
|
||||||
|
this.transportApiAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getTransportApiSettings());
|
||||||
|
this.notificationAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getNotificationsSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, transportNotificationSettings.getNotificationsTopic());
|
return new TbPubSubProducerTemplate<>(notificationAdmin, pubSubSettings, transportNotificationSettings.getNotificationsTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(ruleEngineAdmin, pubSubSettings, ruleEngineSettings.getTopic());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(ruleEngineAdmin, pubSubSettings, ruleEngineSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) {
|
public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) {
|
||||||
return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic(),
|
return new TbPubSubConsumerTemplate<>(ruleEngineAdmin, pubSubSettings, 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 TbPubSubConsumerTemplate<>(admin, pubSubSettings,
|
return new TbPubSubConsumerTemplate<>(notificationAdmin, pubSubSettings,
|
||||||
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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() {
|
||||||
return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, coreSettings.getTopic(),
|
return new TbPubSubConsumerTemplate<>(coreAdmin, pubSubSettings, 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 TbPubSubConsumerTemplate<>(admin, pubSubSettings,
|
return new TbPubSubConsumerTemplate<>(notificationAdmin, pubSubSettings,
|
||||||
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 TbPubSubConsumerTemplate<>(admin, pubSubSettings, transportApiSettings.getRequestsTopic(),
|
return new TbPubSubConsumerTemplate<>(transportApiAdmin, pubSubSettings, 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 TbPubSubProducerTemplate<>(admin, pubSubSettings, transportApiSettings.getResponsesTopic());
|
return new TbPubSubProducerTemplate<>(transportApiAdmin, pubSubSettings, transportApiSettings.getResponsesTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -30,6 +30,8 @@ import org.thingsboard.server.queue.TbQueueAdmin;
|
|||||||
import org.thingsboard.server.queue.TbQueueConsumer;
|
import org.thingsboard.server.queue.TbQueueConsumer;
|
||||||
import org.thingsboard.server.queue.TbQueueRequestTemplate;
|
import org.thingsboard.server.queue.TbQueueRequestTemplate;
|
||||||
import org.thingsboard.server.queue.common.TbProtoJsQueueMsg;
|
import org.thingsboard.server.queue.common.TbProtoJsQueueMsg;
|
||||||
|
import org.thingsboard.server.queue.pubsub.TbPubSubAdmin;
|
||||||
|
import org.thingsboard.server.queue.pubsub.TbPubSubSubscriptionSettings;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
||||||
import org.thingsboard.server.queue.TbQueueProducer;
|
import org.thingsboard.server.queue.TbQueueProducer;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
||||||
@ -47,71 +49,79 @@ public class PubSubTbCoreQueueFactory implements TbCoreQueueFactory {
|
|||||||
private final TbPubSubSettings pubSubSettings;
|
private final TbPubSubSettings pubSubSettings;
|
||||||
private final TbQueueCoreSettings coreSettings;
|
private final TbQueueCoreSettings coreSettings;
|
||||||
private final TbQueueTransportApiSettings transportApiSettings;
|
private final TbQueueTransportApiSettings transportApiSettings;
|
||||||
private final TbQueueAdmin admin;
|
|
||||||
private final PartitionService partitionService;
|
private final PartitionService partitionService;
|
||||||
private final TbServiceInfoProvider serviceInfoProvider;
|
private final TbServiceInfoProvider serviceInfoProvider;
|
||||||
|
|
||||||
|
private final TbQueueAdmin coreAdmin;
|
||||||
|
private final TbQueueAdmin jsExecutorAdmin;
|
||||||
|
private final TbQueueAdmin transportApiAdmin;
|
||||||
|
private final TbQueueAdmin notificationAdmin;
|
||||||
|
|
||||||
public PubSubTbCoreQueueFactory(TbPubSubSettings pubSubSettings,
|
public PubSubTbCoreQueueFactory(TbPubSubSettings pubSubSettings,
|
||||||
TbQueueCoreSettings coreSettings,
|
TbQueueCoreSettings coreSettings,
|
||||||
TbQueueTransportApiSettings transportApiSettings,
|
TbQueueTransportApiSettings transportApiSettings,
|
||||||
TbQueueAdmin admin,
|
|
||||||
PartitionService partitionService,
|
PartitionService partitionService,
|
||||||
TbServiceInfoProvider serviceInfoProvider) {
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
|
TbPubSubSubscriptionSettings pubSubSubscriptionSettings) {
|
||||||
this.pubSubSettings = pubSubSettings;
|
this.pubSubSettings = pubSubSettings;
|
||||||
this.coreSettings = coreSettings;
|
this.coreSettings = coreSettings;
|
||||||
this.transportApiSettings = transportApiSettings;
|
this.transportApiSettings = transportApiSettings;
|
||||||
this.admin = admin;
|
|
||||||
this.partitionService = partitionService;
|
this.partitionService = partitionService;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
|
|
||||||
|
this.coreAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getCoreSettings());
|
||||||
|
this.jsExecutorAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getJsExecutorSettings());
|
||||||
|
this.transportApiAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getTransportApiSettings());
|
||||||
|
this.notificationAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getNotificationsSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() {
|
||||||
return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, coreSettings.getTopic(),
|
return new TbPubSubConsumerTemplate<>(coreAdmin, pubSubSettings, 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 TbPubSubConsumerTemplate<>(admin, pubSubSettings,
|
return new TbPubSubConsumerTemplate<>(notificationAdmin, pubSubSettings,
|
||||||
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 TbPubSubConsumerTemplate<>(admin, pubSubSettings, transportApiSettings.getRequestsTopic(),
|
return new TbPubSubConsumerTemplate<>(transportApiAdmin, pubSubSettings, 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 TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -32,9 +32,11 @@ 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.pubsub.TbPubSubAdmin;
|
||||||
import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate;
|
import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate;
|
||||||
import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate;
|
import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate;
|
||||||
import org.thingsboard.server.queue.pubsub.TbPubSubSettings;
|
import org.thingsboard.server.queue.pubsub.TbPubSubSettings;
|
||||||
|
import org.thingsboard.server.queue.pubsub.TbPubSubSubscriptionSettings;
|
||||||
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;
|
||||||
@ -46,59 +48,67 @@ public class PubSubTbRuleEngineQueueFactory implements TbRuleEngineQueueFactory
|
|||||||
private final TbPubSubSettings pubSubSettings;
|
private final TbPubSubSettings pubSubSettings;
|
||||||
private final TbQueueCoreSettings coreSettings;
|
private final TbQueueCoreSettings coreSettings;
|
||||||
private final TbQueueRuleEngineSettings ruleEngineSettings;
|
private final TbQueueRuleEngineSettings ruleEngineSettings;
|
||||||
private final TbQueueAdmin admin;
|
|
||||||
private final PartitionService partitionService;
|
private final PartitionService partitionService;
|
||||||
private final TbServiceInfoProvider serviceInfoProvider;
|
private final TbServiceInfoProvider serviceInfoProvider;
|
||||||
|
|
||||||
|
private final TbQueueAdmin coreAdmin;
|
||||||
|
private final TbQueueAdmin ruleEngineAdmin;
|
||||||
|
private final TbQueueAdmin jsExecutorAdmin;
|
||||||
|
private final TbQueueAdmin notificationAdmin;
|
||||||
|
|
||||||
public PubSubTbRuleEngineQueueFactory(TbPubSubSettings pubSubSettings,
|
public PubSubTbRuleEngineQueueFactory(TbPubSubSettings pubSubSettings,
|
||||||
TbQueueCoreSettings coreSettings,
|
TbQueueCoreSettings coreSettings,
|
||||||
TbQueueRuleEngineSettings ruleEngineSettings,
|
TbQueueRuleEngineSettings ruleEngineSettings,
|
||||||
TbQueueAdmin admin,
|
|
||||||
PartitionService partitionService,
|
PartitionService partitionService,
|
||||||
TbServiceInfoProvider serviceInfoProvider) {
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
|
TbPubSubSubscriptionSettings pubSubSubscriptionSettings) {
|
||||||
this.pubSubSettings = pubSubSettings;
|
this.pubSubSettings = pubSubSettings;
|
||||||
this.coreSettings = coreSettings;
|
this.coreSettings = coreSettings;
|
||||||
this.ruleEngineSettings = ruleEngineSettings;
|
this.ruleEngineSettings = ruleEngineSettings;
|
||||||
this.admin = admin;
|
|
||||||
this.partitionService = partitionService;
|
this.partitionService = partitionService;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
|
|
||||||
|
this.coreAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getCoreSettings());
|
||||||
|
this.ruleEngineAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getRuleEngineSettings());
|
||||||
|
this.jsExecutorAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getJsExecutorSettings());
|
||||||
|
this.notificationAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getNotificationsSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(ruleEngineAdmin, pubSubSettings, ruleEngineSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) {
|
public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) {
|
||||||
return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic(),
|
return new TbPubSubConsumerTemplate<>(ruleEngineAdmin, pubSubSettings, 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 TbPubSubConsumerTemplate<>(admin, pubSubSettings,
|
return new TbPubSubConsumerTemplate<>(notificationAdmin, pubSubSettings,
|
||||||
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()));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,12 +25,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM
|
|||||||
import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg;
|
||||||
import org.thingsboard.server.queue.TbQueueAdmin;
|
import org.thingsboard.server.queue.TbQueueAdmin;
|
||||||
import org.thingsboard.server.queue.TbQueueConsumer;
|
import org.thingsboard.server.queue.TbQueueConsumer;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
|
||||||
import org.thingsboard.server.queue.TbQueueProducer;
|
import org.thingsboard.server.queue.TbQueueProducer;
|
||||||
import org.thingsboard.server.queue.TbQueueRequestTemplate;
|
import org.thingsboard.server.queue.TbQueueRequestTemplate;
|
||||||
import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings;
|
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
|
||||||
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
|
||||||
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;
|
||||||
@ -38,6 +34,11 @@ import org.thingsboard.server.queue.pubsub.TbPubSubAdmin;
|
|||||||
import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate;
|
import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate;
|
||||||
import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate;
|
import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate;
|
||||||
import org.thingsboard.server.queue.pubsub.TbPubSubSettings;
|
import org.thingsboard.server.queue.pubsub.TbPubSubSettings;
|
||||||
|
import org.thingsboard.server.queue.pubsub.TbPubSubSubscriptionSettings;
|
||||||
|
import org.thingsboard.server.queue.settings.TbQueueCoreSettings;
|
||||||
|
import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings;
|
||||||
|
import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings;
|
||||||
|
import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnExpression("'${queue.type:null}'=='pubsub' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')")
|
@ConditionalOnExpression("'${queue.type:null}'=='pubsub' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')")
|
||||||
@ -50,33 +51,42 @@ public class PubSubTransportQueueFactory implements TbTransportQueueFactory {
|
|||||||
private final TbQueueRuleEngineSettings ruleEngineSettings;
|
private final TbQueueRuleEngineSettings ruleEngineSettings;
|
||||||
private final TbQueueTransportApiSettings transportApiSettings;
|
private final TbQueueTransportApiSettings transportApiSettings;
|
||||||
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
private final TbQueueTransportNotificationSettings transportNotificationSettings;
|
||||||
private final TbQueueAdmin admin;
|
|
||||||
|
private final TbQueueAdmin coreAdmin;
|
||||||
|
private final TbQueueAdmin ruleEngineAdmin;
|
||||||
|
private final TbQueueAdmin transportApiAdmin;
|
||||||
|
private final TbQueueAdmin notificationAdmin;
|
||||||
|
|
||||||
public PubSubTransportQueueFactory(TbPubSubSettings pubSubSettings,
|
public PubSubTransportQueueFactory(TbPubSubSettings pubSubSettings,
|
||||||
TbServiceInfoProvider serviceInfoProvider,
|
TbServiceInfoProvider serviceInfoProvider,
|
||||||
TbQueueCoreSettings coreSettings,
|
TbQueueCoreSettings coreSettings,
|
||||||
TbQueueRuleEngineSettings ruleEngineSettings,
|
TbQueueRuleEngineSettings ruleEngineSettings,
|
||||||
TbQueueTransportApiSettings transportApiSettings,
|
TbQueueTransportApiSettings transportApiSettings,
|
||||||
TbQueueTransportNotificationSettings transportNotificationSettings) {
|
TbQueueTransportNotificationSettings transportNotificationSettings,
|
||||||
|
TbPubSubSubscriptionSettings pubSubSubscriptionSettings) {
|
||||||
this.pubSubSettings = pubSubSettings;
|
this.pubSubSettings = pubSubSettings;
|
||||||
this.serviceInfoProvider = serviceInfoProvider;
|
this.serviceInfoProvider = serviceInfoProvider;
|
||||||
this.coreSettings = coreSettings;
|
this.coreSettings = coreSettings;
|
||||||
this.ruleEngineSettings = ruleEngineSettings;
|
this.ruleEngineSettings = ruleEngineSettings;
|
||||||
this.transportApiSettings = transportApiSettings;
|
this.transportApiSettings = transportApiSettings;
|
||||||
this.transportNotificationSettings = transportNotificationSettings;
|
this.transportNotificationSettings = transportNotificationSettings;
|
||||||
this.admin = new TbPubSubAdmin(pubSubSettings);
|
|
||||||
|
this.coreAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getCoreSettings());
|
||||||
|
this.ruleEngineAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getRuleEngineSettings());
|
||||||
|
this.transportApiAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getTransportApiSettings());
|
||||||
|
this.notificationAdmin = new TbPubSubAdmin(pubSubSettings, pubSubSubscriptionSettings.getNotificationsSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiRequestTemplate() {
|
public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiRequestTemplate() {
|
||||||
TbQueueProducer<TbProtoQueueMsg<TransportApiRequestMsg>> producer = new TbPubSubProducerTemplate<>(admin, pubSubSettings, transportApiSettings.getRequestsTopic());
|
TbQueueProducer<TbProtoQueueMsg<TransportApiRequestMsg>> producer = new TbPubSubProducerTemplate<>(transportApiAdmin, pubSubSettings, transportApiSettings.getRequestsTopic());
|
||||||
TbQueueConsumer<TbProtoQueueMsg<TransportApiResponseMsg>> consumer = new TbPubSubConsumerTemplate<>(admin, pubSubSettings,
|
TbQueueConsumer<TbProtoQueueMsg<TransportApiResponseMsg>> consumer = new TbPubSubConsumerTemplate<>(transportApiAdmin, pubSubSettings,
|
||||||
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(producer);
|
templateBuilder.requestTemplate(producer);
|
||||||
templateBuilder.responseTemplate(consumer);
|
templateBuilder.responseTemplate(consumer);
|
||||||
templateBuilder.maxPendingRequests(transportApiSettings.getMaxPendingRequests());
|
templateBuilder.maxPendingRequests(transportApiSettings.getMaxPendingRequests());
|
||||||
@ -87,17 +97,17 @@ public class PubSubTransportQueueFactory implements TbTransportQueueFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(ruleEngineAdmin, pubSubSettings, ruleEngineSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() {
|
||||||
return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic());
|
return new TbPubSubProducerTemplate<>(coreAdmin, pubSubSettings, coreSettings.getTopic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsConsumer() {
|
public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsConsumer() {
|
||||||
return new TbPubSubConsumerTemplate<>(admin, pubSubSettings,
|
return new TbPubSubConsumerTemplate<>(notificationAdmin, pubSubSettings,
|
||||||
transportNotificationSettings.getNotificationsTopic() + "." + serviceInfoProvider.getServiceId(),
|
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()));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,32 +19,37 @@ import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
|
|||||||
import com.google.cloud.pubsub.v1.SubscriptionAdminSettings;
|
import com.google.cloud.pubsub.v1.SubscriptionAdminSettings;
|
||||||
import com.google.cloud.pubsub.v1.TopicAdminClient;
|
import com.google.cloud.pubsub.v1.TopicAdminClient;
|
||||||
import com.google.cloud.pubsub.v1.TopicAdminSettings;
|
import com.google.cloud.pubsub.v1.TopicAdminSettings;
|
||||||
|
import com.google.protobuf.Duration;
|
||||||
import com.google.pubsub.v1.ListSubscriptionsRequest;
|
import com.google.pubsub.v1.ListSubscriptionsRequest;
|
||||||
import com.google.pubsub.v1.ListTopicsRequest;
|
import com.google.pubsub.v1.ListTopicsRequest;
|
||||||
import com.google.pubsub.v1.ProjectName;
|
import com.google.pubsub.v1.ProjectName;
|
||||||
import com.google.pubsub.v1.ProjectSubscriptionName;
|
import com.google.pubsub.v1.ProjectSubscriptionName;
|
||||||
import com.google.pubsub.v1.ProjectTopicName;
|
import com.google.pubsub.v1.ProjectTopicName;
|
||||||
import com.google.pubsub.v1.PushConfig;
|
|
||||||
import com.google.pubsub.v1.Subscription;
|
import com.google.pubsub.v1.Subscription;
|
||||||
import com.google.pubsub.v1.Topic;
|
import com.google.pubsub.v1.Topic;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
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.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TbPubSubAdmin implements TbQueueAdmin {
|
public class TbPubSubAdmin implements TbQueueAdmin {
|
||||||
|
private static final String ACK_DEADLINE = "ackDeadlineInSec";
|
||||||
|
private static final String MESSAGE_RETENTION = "messageRetentionInSec";
|
||||||
|
|
||||||
private final TbPubSubSettings pubSubSettings;
|
private final TbPubSubSettings pubSubSettings;
|
||||||
private final SubscriptionAdminSettings subscriptionAdminSettings;
|
private final SubscriptionAdminSettings subscriptionAdminSettings;
|
||||||
private final TopicAdminSettings topicAdminSettings;
|
private final TopicAdminSettings topicAdminSettings;
|
||||||
private final Set<String> topicSet = ConcurrentHashMap.newKeySet();
|
private final Set<String> topicSet = ConcurrentHashMap.newKeySet();
|
||||||
private final Set<String> subscriptionSet = ConcurrentHashMap.newKeySet();
|
private final Set<String> subscriptionSet = ConcurrentHashMap.newKeySet();
|
||||||
|
private final Map<String, String> subscriptionProperties;
|
||||||
|
|
||||||
public TbPubSubAdmin(TbPubSubSettings pubSubSettings) {
|
public TbPubSubAdmin(TbPubSubSettings pubSubSettings, Map<String, String> subscriptionSettings) {
|
||||||
this.pubSubSettings = pubSubSettings;
|
this.pubSubSettings = pubSubSettings;
|
||||||
|
this.subscriptionProperties = subscriptionSettings;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
topicAdminSettings = TopicAdminSettings.newBuilder().setCredentialsProvider(pubSubSettings.getCredentialsProvider()).build();
|
topicAdminSettings = TopicAdminSettings.newBuilder().setCredentialsProvider(pubSubSettings.getCredentialsProvider()).build();
|
||||||
@ -149,8 +154,15 @@ public class TbPubSubAdmin implements TbQueueAdmin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subscriptionAdminClient.createSubscription(
|
Subscription.Builder subscriptionBuilder = Subscription
|
||||||
subscriptionName, topicName, PushConfig.getDefaultInstance(), pubSubSettings.getAckDeadline()).getName();
|
.newBuilder()
|
||||||
|
.setName(subscriptionName.toString())
|
||||||
|
.setTopic(topicName.toString());
|
||||||
|
|
||||||
|
setAckDeadline(subscriptionBuilder);
|
||||||
|
setMessageRetention(subscriptionBuilder);
|
||||||
|
|
||||||
|
subscriptionAdminClient.createSubscription(subscriptionBuilder.build());
|
||||||
subscriptionSet.add(subscriptionName.toString());
|
subscriptionSet.add(subscriptionName.toString());
|
||||||
log.info("Created new subscription: [{}]", subscriptionName.toString());
|
log.info("Created new subscription: [{}]", subscriptionName.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -159,4 +171,19 @@ public class TbPubSubAdmin implements TbQueueAdmin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setAckDeadline(Subscription.Builder builder) {
|
||||||
|
if (subscriptionProperties.containsKey(ACK_DEADLINE)) {
|
||||||
|
builder.setAckDeadlineSeconds(Integer.parseInt(subscriptionProperties.get(ACK_DEADLINE)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMessageRetention(Subscription.Builder builder) {
|
||||||
|
if (subscriptionProperties.containsKey(MESSAGE_RETENTION)) {
|
||||||
|
Duration duration = Duration
|
||||||
|
.newBuilder()
|
||||||
|
.setSeconds(Long.parseLong(subscriptionProperties.get(MESSAGE_RETENTION)))
|
||||||
|
.build();
|
||||||
|
builder.setMessageRetentionDuration(duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,9 +40,6 @@ public class TbPubSubSettings {
|
|||||||
@Value("${queue.pubsub.service_account}")
|
@Value("${queue.pubsub.service_account}")
|
||||||
private String serviceAccount;
|
private String serviceAccount;
|
||||||
|
|
||||||
@Value("${queue.pubsub.ack_deadline}")
|
|
||||||
private int ackDeadline;
|
|
||||||
|
|
||||||
@Value("${queue.pubsub.max_msg_size}")
|
@Value("${queue.pubsub.max_msg_size}")
|
||||||
private int maxMsgSize;
|
private int maxMsgSize;
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* 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.pubsub;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ConditionalOnExpression("'${queue.type:null}'=='pubsub'")
|
||||||
|
public class TbPubSubSubscriptionSettings {
|
||||||
|
@Value("${queue.pubsub.queue-properties.core}")
|
||||||
|
private String coreProperties;
|
||||||
|
@Value("${queue.pubsub.queue-properties.rule-engine}")
|
||||||
|
private String ruleEngineProperties;
|
||||||
|
@Value("${queue.pubsub.queue-properties.transport-api}")
|
||||||
|
private String transportApiProperties;
|
||||||
|
@Value("${queue.pubsub.queue-properties.notifications}")
|
||||||
|
private String notificationsProperties;
|
||||||
|
@Value("${queue.pubsub.queue-properties.js-executor}")
|
||||||
|
private String jsExecutorProperties;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Map<String, String> coreSettings;
|
||||||
|
@Getter
|
||||||
|
private Map<String, String> ruleEngineSettings;
|
||||||
|
@Getter
|
||||||
|
private Map<String, String> transportApiSettings;
|
||||||
|
@Getter
|
||||||
|
private Map<String, String> notificationsSettings;
|
||||||
|
@Getter
|
||||||
|
private Map<String, String> jsExecutorSettings;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() {
|
||||||
|
coreSettings = getSettings(coreProperties);
|
||||||
|
ruleEngineSettings = getSettings(ruleEngineProperties);
|
||||||
|
transportApiSettings = getSettings(transportApiProperties);
|
||||||
|
notificationsSettings = getSettings(notificationsProperties);
|
||||||
|
jsExecutorSettings = getSettings(jsExecutorProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getSettings(String properties) {
|
||||||
|
Map<String, String> configs = new HashMap<>();
|
||||||
|
for (String property : properties.split(";")) {
|
||||||
|
int delimiterPosition = property.indexOf(":");
|
||||||
|
String key = property.substring(0, delimiterPosition);
|
||||||
|
String value = property.substring(delimiterPosition + 1);
|
||||||
|
configs.put(key, value);
|
||||||
|
}
|
||||||
|
return configs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -72,9 +72,14 @@ queue:
|
|||||||
pubsub:
|
pubsub:
|
||||||
project_id: "${TB_QUEUE_PUBSUB_PROJECT_ID:YOUR_PROJECT_ID}"
|
project_id: "${TB_QUEUE_PUBSUB_PROJECT_ID:YOUR_PROJECT_ID}"
|
||||||
service_account: "${TB_QUEUE_PUBSUB_SERVICE_ACCOUNT:YOUR_SERVICE_ACCOUNT}"
|
service_account: "${TB_QUEUE_PUBSUB_SERVICE_ACCOUNT:YOUR_SERVICE_ACCOUNT}"
|
||||||
ack_deadline: "${TB_QUEUE_PUBSUB_ACK_DEADLINE:30}" #In seconds. If messages wont commit in this time, messages will poll again
|
|
||||||
max_msg_size: "${TB_QUEUE_PUBSUB_MAX_MSG_SIZE:1048576}" #in bytes
|
max_msg_size: "${TB_QUEUE_PUBSUB_MAX_MSG_SIZE:1048576}" #in bytes
|
||||||
max_messages: "${TB_QUEUE_PUBSUB_MAX_MESSAGES:1000}"
|
max_messages: "${TB_QUEUE_PUBSUB_MAX_MESSAGES:1000}"
|
||||||
|
queue-properties:
|
||||||
|
rule-engine: "${TB_QUEUE_PUBSUB_RE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
core: "${TB_QUEUE_PUBSUB_CORE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
transport-api: "${TB_QUEUE_PUBSUB_TA_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
notifications: "${TB_QUEUE_PUBSUB_NOTIFICATIONS_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
js-executor: "${TB_QUEUE_PUBSUB_JE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
service_bus:
|
service_bus:
|
||||||
namespace_name: "${TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME:YOUR_NAMESPACE_NAME}"
|
namespace_name: "${TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME:YOUR_NAMESPACE_NAME}"
|
||||||
sas_key_name: "${TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME:YOUR_SAS_KEY_NAME}"
|
sas_key_name: "${TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME:YOUR_SAS_KEY_NAME}"
|
||||||
|
|||||||
@ -73,9 +73,14 @@ queue:
|
|||||||
pubsub:
|
pubsub:
|
||||||
project_id: "${TB_QUEUE_PUBSUB_PROJECT_ID:YOUR_PROJECT_ID}"
|
project_id: "${TB_QUEUE_PUBSUB_PROJECT_ID:YOUR_PROJECT_ID}"
|
||||||
service_account: "${TB_QUEUE_PUBSUB_SERVICE_ACCOUNT:YOUR_SERVICE_ACCOUNT}"
|
service_account: "${TB_QUEUE_PUBSUB_SERVICE_ACCOUNT:YOUR_SERVICE_ACCOUNT}"
|
||||||
ack_deadline: "${TB_QUEUE_PUBSUB_ACK_DEADLINE:30}" #In seconds. If messages wont commit in this time, messages will poll again
|
|
||||||
max_msg_size: "${TB_QUEUE_PUBSUB_MAX_MSG_SIZE:1048576}" #in bytes
|
max_msg_size: "${TB_QUEUE_PUBSUB_MAX_MSG_SIZE:1048576}" #in bytes
|
||||||
max_messages: "${TB_QUEUE_PUBSUB_MAX_MESSAGES:1000}"
|
max_messages: "${TB_QUEUE_PUBSUB_MAX_MESSAGES:1000}"
|
||||||
|
queue-properties:
|
||||||
|
rule-engine: "${TB_QUEUE_PUBSUB_RE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
core: "${TB_QUEUE_PUBSUB_CORE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
transport-api: "${TB_QUEUE_PUBSUB_TA_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
notifications: "${TB_QUEUE_PUBSUB_NOTIFICATIONS_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
js-executor: "${TB_QUEUE_PUBSUB_JE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
service_bus:
|
service_bus:
|
||||||
namespace_name: "${TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME:YOUR_NAMESPACE_NAME}"
|
namespace_name: "${TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME:YOUR_NAMESPACE_NAME}"
|
||||||
sas_key_name: "${TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME:YOUR_SAS_KEY_NAME}"
|
sas_key_name: "${TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME:YOUR_SAS_KEY_NAME}"
|
||||||
|
|||||||
@ -103,9 +103,14 @@ queue:
|
|||||||
pubsub:
|
pubsub:
|
||||||
project_id: "${TB_QUEUE_PUBSUB_PROJECT_ID:YOUR_PROJECT_ID}"
|
project_id: "${TB_QUEUE_PUBSUB_PROJECT_ID:YOUR_PROJECT_ID}"
|
||||||
service_account: "${TB_QUEUE_PUBSUB_SERVICE_ACCOUNT:YOUR_SERVICE_ACCOUNT}"
|
service_account: "${TB_QUEUE_PUBSUB_SERVICE_ACCOUNT:YOUR_SERVICE_ACCOUNT}"
|
||||||
ack_deadline: "${TB_QUEUE_PUBSUB_ACK_DEADLINE:30}" #In seconds. If messages wont commit in this time, messages will poll again
|
|
||||||
max_msg_size: "${TB_QUEUE_PUBSUB_MAX_MSG_SIZE:1048576}" #in bytes
|
max_msg_size: "${TB_QUEUE_PUBSUB_MAX_MSG_SIZE:1048576}" #in bytes
|
||||||
max_messages: "${TB_QUEUE_PUBSUB_MAX_MESSAGES:1000}"
|
max_messages: "${TB_QUEUE_PUBSUB_MAX_MESSAGES:1000}"
|
||||||
|
queue-properties:
|
||||||
|
rule-engine: "${TB_QUEUE_PUBSUB_RE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
core: "${TB_QUEUE_PUBSUB_CORE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
transport-api: "${TB_QUEUE_PUBSUB_TA_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
notifications: "${TB_QUEUE_PUBSUB_NOTIFICATIONS_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
|
js-executor: "${TB_QUEUE_PUBSUB_JE_QUEUE_PROPERTIES:ackDeadlineInSec:30;messageRetentionInSec:604800}"
|
||||||
service_bus:
|
service_bus:
|
||||||
namespace_name: "${TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME:YOUR_NAMESPACE_NAME}"
|
namespace_name: "${TB_QUEUE_SERVICE_BUS_NAMESPACE_NAME:YOUR_NAMESPACE_NAME}"
|
||||||
sas_key_name: "${TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME:YOUR_SAS_KEY_NAME}"
|
sas_key_name: "${TB_QUEUE_SERVICE_BUS_SAS_KEY_NAME:YOUR_SAS_KEY_NAME}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user