Commit 638ca0e1d104d8ce2ce744e284a777abb0b61bca
1 parent
b39328c9
Refactoring to multiple queues for rule engine
Showing
83 changed files
with
1066 additions
and
665 deletions
@@ -31,7 +31,6 @@ import lombok.Setter; | @@ -31,7 +31,6 @@ import lombok.Setter; | ||
31 | import lombok.extern.slf4j.Slf4j; | 31 | import lombok.extern.slf4j.Slf4j; |
32 | import org.springframework.beans.factory.annotation.Autowired; | 32 | import org.springframework.beans.factory.annotation.Autowired; |
33 | import org.springframework.beans.factory.annotation.Value; | 33 | import org.springframework.beans.factory.annotation.Value; |
34 | -import org.springframework.context.annotation.Lazy; | ||
35 | import org.springframework.data.redis.core.RedisTemplate; | 34 | import org.springframework.data.redis.core.RedisTemplate; |
36 | import org.springframework.scheduling.annotation.Scheduled; | 35 | import org.springframework.scheduling.annotation.Scheduled; |
37 | import org.springframework.stereotype.Component; | 36 | import org.springframework.stereotype.Component; |
@@ -48,7 +47,6 @@ import org.thingsboard.server.common.msg.TbMsg; | @@ -48,7 +47,6 @@ import org.thingsboard.server.common.msg.TbMsg; | ||
48 | import org.thingsboard.server.common.msg.queue.ServiceType; | 47 | import org.thingsboard.server.common.msg.queue.ServiceType; |
49 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 48 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
50 | import org.thingsboard.server.common.msg.tools.TbRateLimits; | 49 | import org.thingsboard.server.common.msg.tools.TbRateLimits; |
51 | -import org.thingsboard.server.common.transport.auth.DeviceAuthService; | ||
52 | import org.thingsboard.server.dao.alarm.AlarmService; | 50 | import org.thingsboard.server.dao.alarm.AlarmService; |
53 | import org.thingsboard.server.dao.asset.AssetService; | 51 | import org.thingsboard.server.dao.asset.AssetService; |
54 | import org.thingsboard.server.dao.attributes.AttributesService; | 52 | import org.thingsboard.server.dao.attributes.AttributesService; |
@@ -413,7 +411,12 @@ public class ActorSystemContext { | @@ -413,7 +411,12 @@ public class ActorSystemContext { | ||
413 | return partitionService.resolve(serviceType, tenantId, entityId); | 411 | return partitionService.resolve(serviceType, tenantId, entityId); |
414 | } | 412 | } |
415 | 413 | ||
416 | - public String getServerAddress() { | 414 | + public TopicPartitionInfo resolve(ServiceType serviceType, String queueName, TenantId tenantId, EntityId entityId) { |
415 | + return partitionService.resolve(serviceType, queueName, tenantId, entityId); | ||
416 | + } | ||
417 | + | ||
418 | + | ||
419 | + public String getServiceId() { | ||
417 | return serviceInfoProvider.getServiceId(); | 420 | return serviceInfoProvider.getServiceId(); |
418 | } | 421 | } |
419 | 422 | ||
@@ -445,7 +448,7 @@ public class ActorSystemContext { | @@ -445,7 +448,7 @@ public class ActorSystemContext { | ||
445 | 448 | ||
446 | ObjectNode node = mapper.createObjectNode() | 449 | ObjectNode node = mapper.createObjectNode() |
447 | .put("type", type) | 450 | .put("type", type) |
448 | - .put("server", getServerAddress()) | 451 | + .put("server", getServiceId()) |
449 | .put("entityId", tbMsg.getOriginator().getId().toString()) | 452 | .put("entityId", tbMsg.getOriginator().getId().toString()) |
450 | .put("entityName", tbMsg.getOriginator().getEntityType().name()) | 453 | .put("entityName", tbMsg.getOriginator().getEntityType().name()) |
451 | .put("msgId", tbMsg.getId().toString()) | 454 | .put("msgId", tbMsg.getId().toString()) |
@@ -505,7 +508,7 @@ public class ActorSystemContext { | @@ -505,7 +508,7 @@ public class ActorSystemContext { | ||
505 | 508 | ||
506 | ObjectNode node = mapper.createObjectNode() | 509 | ObjectNode node = mapper.createObjectNode() |
507 | //todo: what fields are needed here? | 510 | //todo: what fields are needed here? |
508 | - .put("server", getServerAddress()) | 511 | + .put("server", getServiceId()) |
509 | .put("message", "Reached debug mode rate limit!"); | 512 | .put("message", "Reached debug mode rate limit!"); |
510 | 513 | ||
511 | if (error != null) { | 514 | if (error != null) { |
@@ -22,12 +22,11 @@ import com.fasterxml.jackson.core.JsonProcessingException; | @@ -22,12 +22,11 @@ import com.fasterxml.jackson.core.JsonProcessingException; | ||
22 | import com.fasterxml.jackson.databind.ObjectMapper; | 22 | import com.fasterxml.jackson.databind.ObjectMapper; |
23 | import com.fasterxml.jackson.databind.node.ObjectNode; | 23 | import com.fasterxml.jackson.databind.node.ObjectNode; |
24 | import io.netty.channel.EventLoopGroup; | 24 | import io.netty.channel.EventLoopGroup; |
25 | +import lombok.extern.slf4j.Slf4j; | ||
25 | import org.springframework.data.redis.core.RedisTemplate; | 26 | import org.springframework.data.redis.core.RedisTemplate; |
26 | import org.thingsboard.common.util.ListeningExecutor; | 27 | import org.thingsboard.common.util.ListeningExecutor; |
27 | import org.thingsboard.rule.engine.api.MailService; | 28 | import org.thingsboard.rule.engine.api.MailService; |
28 | import org.thingsboard.rule.engine.api.RuleChainTransactionService; | 29 | import org.thingsboard.rule.engine.api.RuleChainTransactionService; |
29 | -import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest; | ||
30 | -import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcResponse; | ||
31 | import org.thingsboard.rule.engine.api.RuleEngineRpcService; | 30 | import org.thingsboard.rule.engine.api.RuleEngineRpcService; |
32 | import org.thingsboard.rule.engine.api.RuleEngineTelemetryService; | 31 | import org.thingsboard.rule.engine.api.RuleEngineTelemetryService; |
33 | import org.thingsboard.rule.engine.api.ScriptEngine; | 32 | import org.thingsboard.rule.engine.api.ScriptEngine; |
@@ -37,18 +36,17 @@ import org.thingsboard.server.actors.ActorSystemContext; | @@ -37,18 +36,17 @@ import org.thingsboard.server.actors.ActorSystemContext; | ||
37 | import org.thingsboard.server.common.data.Customer; | 36 | import org.thingsboard.server.common.data.Customer; |
38 | import org.thingsboard.server.common.data.DataConstants; | 37 | import org.thingsboard.server.common.data.DataConstants; |
39 | import org.thingsboard.server.common.data.Device; | 38 | import org.thingsboard.server.common.data.Device; |
39 | +import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo; | ||
40 | import org.thingsboard.server.common.data.alarm.Alarm; | 40 | import org.thingsboard.server.common.data.alarm.Alarm; |
41 | import org.thingsboard.server.common.data.asset.Asset; | 41 | import org.thingsboard.server.common.data.asset.Asset; |
42 | -import org.thingsboard.server.common.data.id.DeviceId; | ||
43 | import org.thingsboard.server.common.data.id.EntityId; | 42 | import org.thingsboard.server.common.data.id.EntityId; |
44 | import org.thingsboard.server.common.data.id.RuleNodeId; | 43 | import org.thingsboard.server.common.data.id.RuleNodeId; |
45 | import org.thingsboard.server.common.data.id.TenantId; | 44 | import org.thingsboard.server.common.data.id.TenantId; |
46 | -import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | ||
47 | import org.thingsboard.server.common.data.rule.RuleNode; | 45 | import org.thingsboard.server.common.data.rule.RuleNode; |
48 | import org.thingsboard.server.common.msg.TbMsg; | 46 | import org.thingsboard.server.common.msg.TbMsg; |
49 | import org.thingsboard.server.common.msg.TbMsgDataType; | 47 | import org.thingsboard.server.common.msg.TbMsgDataType; |
50 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 48 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
51 | -import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 49 | +import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
52 | import org.thingsboard.server.dao.alarm.AlarmService; | 50 | import org.thingsboard.server.dao.alarm.AlarmService; |
53 | import org.thingsboard.server.dao.asset.AssetService; | 51 | import org.thingsboard.server.dao.asset.AssetService; |
54 | import org.thingsboard.server.dao.attributes.AttributesService; | 52 | import org.thingsboard.server.dao.attributes.AttributesService; |
@@ -63,10 +61,11 @@ import org.thingsboard.server.dao.rule.RuleChainService; | @@ -63,10 +61,11 @@ import org.thingsboard.server.dao.rule.RuleChainService; | ||
63 | import org.thingsboard.server.dao.tenant.TenantService; | 61 | import org.thingsboard.server.dao.tenant.TenantService; |
64 | import org.thingsboard.server.dao.timeseries.TimeseriesService; | 62 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
65 | import org.thingsboard.server.dao.user.UserService; | 63 | import org.thingsboard.server.dao.user.UserService; |
64 | +import org.thingsboard.server.common.msg.queue.ServiceType; | ||
66 | import org.thingsboard.server.gen.transport.TransportProtos; | 65 | import org.thingsboard.server.gen.transport.TransportProtos; |
66 | +import org.thingsboard.server.queue.TbQueueCallback; | ||
67 | +import org.thingsboard.server.queue.TbQueueMsgMetadata; | ||
67 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 68 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
68 | -import org.thingsboard.server.common.msg.queue.ServiceType; | ||
69 | -import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | ||
70 | import org.thingsboard.server.service.script.RuleNodeJsScriptEngine; | 69 | import org.thingsboard.server.service.script.RuleNodeJsScriptEngine; |
71 | import scala.concurrent.duration.Duration; | 70 | import scala.concurrent.duration.Duration; |
72 | 71 | ||
@@ -78,6 +77,7 @@ import java.util.function.Consumer; | @@ -78,6 +77,7 @@ import java.util.function.Consumer; | ||
78 | /** | 77 | /** |
79 | * Created by ashvayka on 19.03.18. | 78 | * Created by ashvayka on 19.03.18. |
80 | */ | 79 | */ |
80 | +@Slf4j | ||
81 | class DefaultTbContext implements TbContext { | 81 | class DefaultTbContext implements TbContext { |
82 | 82 | ||
83 | public final static ObjectMapper mapper = new ObjectMapper(); | 83 | public final static ObjectMapper mapper = new ObjectMapper(); |
@@ -100,11 +100,6 @@ class DefaultTbContext implements TbContext { | @@ -100,11 +100,6 @@ class DefaultTbContext implements TbContext { | ||
100 | tellNext(msg, relationTypes, null); | 100 | tellNext(msg, relationTypes, null); |
101 | } | 101 | } |
102 | 102 | ||
103 | - @Override | ||
104 | - public void tellNext(TbMsg msg, String relationType, Throwable th) { | ||
105 | - tellNext(msg, Collections.singleton(relationType), th); | ||
106 | - } | ||
107 | - | ||
108 | private void tellNext(TbMsg msg, Set<String> relationTypes, Throwable th) { | 103 | private void tellNext(TbMsg msg, Set<String> relationTypes, Throwable th) { |
109 | if (nodeCtx.getSelf().isDebugMode()) { | 104 | if (nodeCtx.getSelf().isDebugMode()) { |
110 | relationTypes.forEach(relationType -> mainCtx.persistDebugOutput(nodeCtx.getTenantId(), nodeCtx.getSelf().getId(), msg, relationType, th)); | 105 | relationTypes.forEach(relationType -> mainCtx.persistDebugOutput(nodeCtx.getTenantId(), nodeCtx.getSelf().getId(), msg, relationType, th)); |
@@ -119,6 +114,77 @@ class DefaultTbContext implements TbContext { | @@ -119,6 +114,77 @@ class DefaultTbContext implements TbContext { | ||
119 | } | 114 | } |
120 | 115 | ||
121 | @Override | 116 | @Override |
117 | + public void enqueue(TbMsg tbMsg, Runnable onSuccess, Consumer<Throwable> onFailure) { | ||
118 | + TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); | ||
119 | + enqueue(tpi, tbMsg, onFailure, onSuccess); | ||
120 | + } | ||
121 | + | ||
122 | + @Override | ||
123 | + public void enqueue(TbMsg tbMsg, String queueName, Runnable onSuccess, Consumer<Throwable> onFailure) { | ||
124 | + TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator()); | ||
125 | + enqueue(tpi, tbMsg, onFailure, onSuccess); | ||
126 | + } | ||
127 | + | ||
128 | + private void enqueue(TopicPartitionInfo tpi, TbMsg tbMsg, Consumer<Throwable> onFailure, Runnable onSuccess) { | ||
129 | + TransportProtos.ToRuleEngineMsg msg = TransportProtos.ToRuleEngineMsg.newBuilder() | ||
130 | + .setTenantIdMSB(getTenantId().getId().getMostSignificantBits()) | ||
131 | + .setTenantIdLSB(getTenantId().getId().getLeastSignificantBits()) | ||
132 | + .setTbMsg(TbMsg.toByteString(tbMsg)).build(); | ||
133 | + mainCtx.getProducerProvider().getRuleEngineMsgProducer().send(tpi, new TbProtoQueueMsg<>(tbMsg.getId(), msg), new SimpleTbQueueCallback(onSuccess, onFailure)); | ||
134 | + } | ||
135 | + | ||
136 | + @Override | ||
137 | + public void enqueueForTellNext(TbMsg tbMsg, String relationType) { | ||
138 | + TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); | ||
139 | + enqueueForTellNext(tpi, tbMsg, Collections.singleton(relationType), null, null); | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public void enqueueForTellNext(TbMsg tbMsg, Set<String> relationTypes) { | ||
144 | + TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); | ||
145 | + enqueueForTellNext(tpi, tbMsg, relationTypes, null, null); | ||
146 | + } | ||
147 | + | ||
148 | + @Override | ||
149 | + public void enqueueForTellNext(TbMsg tbMsg, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure) { | ||
150 | + TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); | ||
151 | + enqueueForTellNext(tpi, tbMsg, Collections.singleton(relationType), onSuccess, onFailure); | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public void enqueueForTellNext(TbMsg tbMsg, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure) { | ||
156 | + TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); | ||
157 | + enqueueForTellNext(tpi, tbMsg, relationTypes, onSuccess, onFailure); | ||
158 | + } | ||
159 | + | ||
160 | + @Override | ||
161 | + public void enqueueForTellNext(TbMsg tbMsg, String queueName, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure) { | ||
162 | + TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); | ||
163 | + enqueueForTellNext(tpi, tbMsg, Collections.singleton(relationType), onSuccess, onFailure); | ||
164 | + } | ||
165 | + | ||
166 | + @Override | ||
167 | + public void enqueueForTellNext(TbMsg tbMsg, String queueName, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure) { | ||
168 | + TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator()); | ||
169 | + enqueueForTellNext(tpi, tbMsg, relationTypes, onSuccess, onFailure); | ||
170 | + } | ||
171 | + | ||
172 | + private void enqueueForTellNext(TopicPartitionInfo tpi, TbMsg tbMsg, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure) { | ||
173 | + TransportProtos.ToRuleEngineMsg msg = TransportProtos.ToRuleEngineMsg.newBuilder() | ||
174 | + .setTenantIdMSB(getTenantId().getId().getMostSignificantBits()) | ||
175 | + .setTenantIdLSB(getTenantId().getId().getLeastSignificantBits()) | ||
176 | + .setTbMsg(TbMsg.toByteString(tbMsg)) | ||
177 | + .addAllRelationTypes(relationTypes) | ||
178 | + .build(); | ||
179 | + mainCtx.getProducerProvider().getRuleEngineMsgProducer().send(tpi, new TbProtoQueueMsg<>(tbMsg.getId(), msg), new SimpleTbQueueCallback(onSuccess, onFailure)); | ||
180 | + } | ||
181 | + | ||
182 | + @Override | ||
183 | + public void ack(TbMsg tbMsg) { | ||
184 | + tbMsg.getCallback().onSuccess(); | ||
185 | + } | ||
186 | + | ||
187 | + @Override | ||
122 | public boolean isLocalEntity(EntityId entityId) { | 188 | public boolean isLocalEntity(EntityId entityId) { |
123 | return mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), entityId).isMyPartition(); | 189 | return mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), entityId).isMyPartition(); |
124 | } | 190 | } |
@@ -135,68 +201,44 @@ class DefaultTbContext implements TbContext { | @@ -135,68 +201,44 @@ class DefaultTbContext implements TbContext { | ||
135 | nodeCtx.getChainActor().tell(new RuleNodeToRuleChainTellNextMsg(nodeCtx.getSelf().getId(), Collections.singleton(TbRelationTypes.FAILURE), msg), nodeCtx.getSelfActor()); | 201 | nodeCtx.getChainActor().tell(new RuleNodeToRuleChainTellNextMsg(nodeCtx.getSelf().getId(), Collections.singleton(TbRelationTypes.FAILURE), msg), nodeCtx.getSelfActor()); |
136 | } | 202 | } |
137 | 203 | ||
138 | - @Override | ||
139 | public void updateSelf(RuleNode self) { | 204 | public void updateSelf(RuleNode self) { |
140 | nodeCtx.setSelf(self); | 205 | nodeCtx.setSelf(self); |
141 | } | 206 | } |
142 | 207 | ||
143 | @Override | 208 | @Override |
144 | public TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data) { | 209 | public TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data) { |
145 | - return new TbMsg(UUIDs.timeBased(), type, originator, metaData.copy(), TbMsgDataType.JSON, data, nodeCtx.getSelf().getRuleChainId(), nodeCtx.getSelf().getId(), null); | 210 | + return TbMsg.newMsg(type, originator, metaData, data, nodeCtx.getSelf().getRuleChainId(), nodeCtx.getSelf().getId()); |
146 | } | 211 | } |
147 | 212 | ||
148 | @Override | 213 | @Override |
149 | public TbMsg transformMsg(TbMsg origMsg, String type, EntityId originator, TbMsgMetaData metaData, String data) { | 214 | public TbMsg transformMsg(TbMsg origMsg, String type, EntityId originator, TbMsgMetaData metaData, String data) { |
150 | - return new TbMsg(origMsg.getId(), type, originator, metaData.copy(), origMsg.getDataType(), | ||
151 | - data, origMsg.getTransactionData(), origMsg.getRuleChainId(), origMsg.getRuleNodeId(), null); | ||
152 | - } | ||
153 | - | ||
154 | - @Override | ||
155 | - public void sendTbMsgToRuleEngine(TbMsg tbMsg) { | ||
156 | - mainCtx.getClusterService().onToRuleEngineMsg(getTenantId(), tbMsg.getOriginator(), tbMsg); | 215 | + return TbMsg.transformMsg(origMsg, type, originator, metaData, data); |
157 | } | 216 | } |
158 | 217 | ||
159 | public TbMsg customerCreatedMsg(Customer customer, RuleNodeId ruleNodeId) { | 218 | public TbMsg customerCreatedMsg(Customer customer, RuleNodeId ruleNodeId) { |
160 | - try { | ||
161 | - ObjectNode entityNode = mapper.valueToTree(customer); | ||
162 | - return new TbMsg(UUIDs.timeBased(), DataConstants.ENTITY_CREATED, customer.getId(), | ||
163 | - getActionMetaData(ruleNodeId), TbMsgDataType.JSON, mapper.writeValueAsString(entityNode), null, null, null); | ||
164 | - } catch (JsonProcessingException | IllegalArgumentException e) { | ||
165 | - throw new RuntimeException("Failed to process customer created msg: " + e); | ||
166 | - } | 219 | + return entityCreatedMsg(customer, customer.getId(), ruleNodeId); |
167 | } | 220 | } |
168 | 221 | ||
169 | public TbMsg deviceCreatedMsg(Device device, RuleNodeId ruleNodeId) { | 222 | public TbMsg deviceCreatedMsg(Device device, RuleNodeId ruleNodeId) { |
170 | - try { | ||
171 | - ObjectNode entityNode = mapper.valueToTree(device); | ||
172 | - return new TbMsg(UUIDs.timeBased(), DataConstants.ENTITY_CREATED, device.getId(), getActionMetaData(ruleNodeId), | ||
173 | - TbMsgDataType.JSON, mapper.writeValueAsString(entityNode), null, null, null); | ||
174 | - } catch (JsonProcessingException | IllegalArgumentException e) { | ||
175 | - throw new RuntimeException("Failed to process device created msg: " + e); | ||
176 | - } | 223 | + return entityCreatedMsg(device, device.getId(), ruleNodeId); |
177 | } | 224 | } |
178 | 225 | ||
179 | public TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId) { | 226 | public TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId) { |
180 | - try { | ||
181 | - ObjectNode entityNode = mapper.valueToTree(asset); | ||
182 | - return new TbMsg(UUIDs.timeBased(), DataConstants.ENTITY_CREATED, asset.getId(), getActionMetaData(ruleNodeId), | ||
183 | - TbMsgDataType.JSON, mapper.writeValueAsString(entityNode), null, null, null); | ||
184 | - } catch (JsonProcessingException | IllegalArgumentException e) { | ||
185 | - throw new RuntimeException("Failed to process asset created msg: " + e); | ||
186 | - } | 227 | + return entityCreatedMsg(asset, asset.getId(), ruleNodeId); |
187 | } | 228 | } |
188 | 229 | ||
189 | public TbMsg alarmCreatedMsg(Alarm alarm, RuleNodeId ruleNodeId) { | 230 | public TbMsg alarmCreatedMsg(Alarm alarm, RuleNodeId ruleNodeId) { |
231 | + return entityCreatedMsg(alarm, alarm.getId(), ruleNodeId); | ||
232 | + } | ||
233 | + | ||
234 | + public <E, I extends EntityId> TbMsg entityCreatedMsg(E entity, I id, RuleNodeId ruleNodeId) { | ||
190 | try { | 235 | try { |
191 | - ObjectNode entityNode = mapper.valueToTree(alarm); | ||
192 | - return new TbMsg(UUIDs.timeBased(), DataConstants.ENTITY_CREATED, alarm.getId(), getActionMetaData(ruleNodeId), | ||
193 | - TbMsgDataType.JSON, mapper.writeValueAsString(entityNode), null, null, null); | 236 | + return TbMsg.newMsg(DataConstants.ENTITY_CREATED, id, getActionMetaData(ruleNodeId), mapper.writeValueAsString(mapper.valueToTree(entity))); |
194 | } catch (JsonProcessingException | IllegalArgumentException e) { | 237 | } catch (JsonProcessingException | IllegalArgumentException e) { |
195 | - throw new RuntimeException("Failed to process alarm created msg: " + e); | 238 | + throw new RuntimeException("Failed to process " + id.getEntityType().name().toLowerCase() + " created msg: " + e); |
196 | } | 239 | } |
197 | } | 240 | } |
198 | 241 | ||
199 | - | ||
200 | @Override | 242 | @Override |
201 | public RuleNodeId getSelfId() { | 243 | public RuleNodeId getSelfId() { |
202 | return nodeCtx.getSelf().getId(); | 244 | return nodeCtx.getSelf().getId(); |
@@ -254,7 +296,7 @@ class DefaultTbContext implements TbContext { | @@ -254,7 +296,7 @@ class DefaultTbContext implements TbContext { | ||
254 | } | 296 | } |
255 | 297 | ||
256 | @Override | 298 | @Override |
257 | - public String getNodeId() { | 299 | + public String getServiceId() { |
258 | return mainCtx.getServiceInfoProvider().getServiceId(); | 300 | return mainCtx.getServiceInfoProvider().getServiceId(); |
259 | } | 301 | } |
260 | 302 | ||
@@ -362,10 +404,6 @@ class DefaultTbContext implements TbContext { | @@ -362,10 +404,6 @@ class DefaultTbContext implements TbContext { | ||
362 | return mainCtx.getRedisTemplate(); | 404 | return mainCtx.getRedisTemplate(); |
363 | } | 405 | } |
364 | 406 | ||
365 | - @Override | ||
366 | - public String getServerAddress() { | ||
367 | - return mainCtx.getServerAddress(); | ||
368 | - } | ||
369 | 407 | ||
370 | private TbMsgMetaData getActionMetaData(RuleNodeId ruleNodeId) { | 408 | private TbMsgMetaData getActionMetaData(RuleNodeId ruleNodeId) { |
371 | TbMsgMetaData metaData = new TbMsgMetaData(); | 409 | TbMsgMetaData metaData = new TbMsgMetaData(); |
@@ -373,4 +411,29 @@ class DefaultTbContext implements TbContext { | @@ -373,4 +411,29 @@ class DefaultTbContext implements TbContext { | ||
373 | return metaData; | 411 | return metaData; |
374 | } | 412 | } |
375 | 413 | ||
414 | + private class SimpleTbQueueCallback implements TbQueueCallback { | ||
415 | + private final Runnable onSuccess; | ||
416 | + private final Consumer<Throwable> onFailure; | ||
417 | + | ||
418 | + public SimpleTbQueueCallback(Runnable onSuccess, Consumer<Throwable> onFailure) { | ||
419 | + this.onSuccess = onSuccess; | ||
420 | + this.onFailure = onFailure; | ||
421 | + } | ||
422 | + | ||
423 | + @Override | ||
424 | + public void onSuccess(TbQueueMsgMetadata metadata) { | ||
425 | + if (onSuccess != null) { | ||
426 | + onSuccess.run(); | ||
427 | + } | ||
428 | + } | ||
429 | + | ||
430 | + @Override | ||
431 | + public void onFailure(Throwable t) { | ||
432 | + if (onFailure != null) { | ||
433 | + onFailure.accept(t); | ||
434 | + } else { | ||
435 | + log.debug("[{}] Failed to put item into queue", nodeCtx.getTenantId(), t); | ||
436 | + } | ||
437 | + } | ||
438 | + } | ||
376 | } | 439 | } |
@@ -39,10 +39,10 @@ import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | @@ -39,10 +39,10 @@ import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | ||
39 | import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg; | 39 | import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg; |
40 | import org.thingsboard.server.dao.rule.RuleChainService; | 40 | import org.thingsboard.server.dao.rule.RuleChainService; |
41 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 41 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
42 | -import org.thingsboard.server.queue.MultipleTbQueueTbMsgCallbackWrapper; | 42 | +import org.thingsboard.server.queue.common.MultipleTbQueueTbMsgCallbackWrapper; |
43 | import org.thingsboard.server.queue.TbQueueCallback; | 43 | import org.thingsboard.server.queue.TbQueueCallback; |
44 | import org.thingsboard.server.queue.TbQueueProducer; | 44 | import org.thingsboard.server.queue.TbQueueProducer; |
45 | -import org.thingsboard.server.queue.TbQueueTbMsgCallbackWrapper; | 45 | +import org.thingsboard.server.queue.common.TbQueueTbMsgCallbackWrapper; |
46 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 46 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
47 | import org.thingsboard.server.common.msg.queue.ServiceType; | 47 | import org.thingsboard.server.common.msg.queue.ServiceType; |
48 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 48 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
application/src/main/java/org/thingsboard/server/actors/ruleChain/RuleNodeActorMessageProcessor.java
@@ -40,7 +40,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod | @@ -40,7 +40,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod | ||
40 | private final RuleChainService service; | 40 | private final RuleChainService service; |
41 | private RuleNode ruleNode; | 41 | private RuleNode ruleNode; |
42 | private TbNode tbNode; | 42 | private TbNode tbNode; |
43 | - private TbContext defaultCtx; | 43 | + private DefaultTbContext defaultCtx; |
44 | 44 | ||
45 | RuleNodeActorMessageProcessor(TenantId tenantId, RuleChainId ruleChainId, RuleNodeId ruleNodeId, ActorSystemContext systemContext | 45 | RuleNodeActorMessageProcessor(TenantId tenantId, RuleChainId ruleChainId, RuleNodeId ruleNodeId, ActorSystemContext systemContext |
46 | , ActorRef parent, ActorRef self) { | 46 | , ActorRef parent, ActorRef self) { |
@@ -26,21 +26,11 @@ import org.springframework.boot.context.event.ApplicationReadyEvent; | @@ -26,21 +26,11 @@ import org.springframework.boot.context.event.ApplicationReadyEvent; | ||
26 | import org.springframework.context.event.EventListener; | 26 | import org.springframework.context.event.EventListener; |
27 | import org.springframework.scheduling.annotation.Scheduled; | 27 | import org.springframework.scheduling.annotation.Scheduled; |
28 | import org.springframework.stereotype.Service; | 28 | import org.springframework.stereotype.Service; |
29 | -import org.thingsboard.rule.engine.api.msg.DeviceCredentialsUpdateNotificationMsg; | ||
30 | -import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg; | ||
31 | import org.thingsboard.server.actors.ActorSystemContext; | 29 | import org.thingsboard.server.actors.ActorSystemContext; |
32 | import org.thingsboard.server.actors.app.AppActor; | 30 | import org.thingsboard.server.actors.app.AppActor; |
33 | import org.thingsboard.server.actors.app.AppInitMsg; | 31 | import org.thingsboard.server.actors.app.AppInitMsg; |
34 | import org.thingsboard.server.actors.stats.StatsActor; | 32 | import org.thingsboard.server.actors.stats.StatsActor; |
35 | -import org.thingsboard.server.common.data.id.DeviceId; | ||
36 | -import org.thingsboard.server.common.data.id.EntityId; | ||
37 | -import org.thingsboard.server.common.data.id.TenantId; | ||
38 | -import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | ||
39 | -import org.thingsboard.server.common.msg.TbActorMsg; | ||
40 | import org.thingsboard.server.common.msg.queue.PartitionChangeMsg; | 33 | import org.thingsboard.server.common.msg.queue.PartitionChangeMsg; |
41 | -import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; | ||
42 | -import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; | ||
43 | -import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | ||
44 | import org.thingsboard.server.queue.discovery.PartitionChangeEvent; | 34 | import org.thingsboard.server.queue.discovery.PartitionChangeEvent; |
45 | import scala.concurrent.Await; | 35 | import scala.concurrent.Await; |
46 | import scala.concurrent.Future; | 36 | import scala.concurrent.Future; |
@@ -93,7 +83,7 @@ public class DefaultActorService implements ActorService { | @@ -93,7 +83,7 @@ public class DefaultActorService implements ActorService { | ||
93 | @EventListener(PartitionChangeEvent.class) | 83 | @EventListener(PartitionChangeEvent.class) |
94 | public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { | 84 | public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { |
95 | log.info("Received partition change event."); | 85 | log.info("Received partition change event."); |
96 | - this.appActor.tell(new PartitionChangeMsg(partitionChangeEvent.getServiceKey(), partitionChangeEvent.getPartitions()), ActorRef.noSender()); | 86 | + this.appActor.tell(new PartitionChangeMsg(partitionChangeEvent.getServiceQueueKey(), partitionChangeEvent.getPartitions()), ActorRef.noSender()); |
97 | } | 87 | } |
98 | 88 | ||
99 | @PreDestroy | 89 | @PreDestroy |
@@ -86,7 +86,7 @@ public class TenantActor extends RuleChainManagerActor { | @@ -86,7 +86,7 @@ public class TenantActor extends RuleChainManagerActor { | ||
86 | switch (msg.getMsgType()) { | 86 | switch (msg.getMsgType()) { |
87 | case PARTITION_CHANGE_MSG: | 87 | case PARTITION_CHANGE_MSG: |
88 | PartitionChangeMsg partitionChangeMsg = (PartitionChangeMsg) msg; | 88 | PartitionChangeMsg partitionChangeMsg = (PartitionChangeMsg) msg; |
89 | - ServiceType serviceType = partitionChangeMsg.getServiceKey().getServiceType(); | 89 | + ServiceType serviceType = partitionChangeMsg.getServiceQueueKey().getServiceType(); |
90 | if (ServiceType.TB_RULE_ENGINE.equals(serviceType)) { | 90 | if (ServiceType.TB_RULE_ENGINE.equals(serviceType)) { |
91 | //To Rule Chain Actors | 91 | //To Rule Chain Actors |
92 | broadcast(msg); | 92 | broadcast(msg); |
@@ -667,9 +667,7 @@ public abstract class BaseController { | @@ -667,9 +667,7 @@ public abstract class BaseController { | ||
667 | } | 667 | } |
668 | } | 668 | } |
669 | } | 669 | } |
670 | - TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), msgType, entityId, metaData, TbMsgDataType.JSON | ||
671 | - , json.writeValueAsString(entityNode) | ||
672 | - , null, null, null); | 670 | + TbMsg tbMsg = TbMsg.newMsg(msgType, entityId, metaData, TbMsgDataType.JSON, json.writeValueAsString(entityNode)); |
673 | tbClusterService.onToRuleEngineMsg(user.getTenantId(), entityId, tbMsg); | 671 | tbClusterService.onToRuleEngineMsg(user.getTenantId(), entityId, tbMsg); |
674 | } catch (Exception e) { | 672 | } catch (Exception e) { |
675 | log.warn("[{}] Failed to push entity action to rule engine: {}", entityId, actionType, e); | 673 | log.warn("[{}] Failed to push entity action to rule engine: {}", entityId, actionType, e); |
@@ -320,7 +320,7 @@ public class RuleChainController extends BaseController { | @@ -320,7 +320,7 @@ public class RuleChainController extends BaseController { | ||
320 | ScriptEngine engine = null; | 320 | ScriptEngine engine = null; |
321 | try { | 321 | try { |
322 | engine = new RuleNodeJsScriptEngine(jsInvokeService, getCurrentUser().getId(), script, argNames); | 322 | engine = new RuleNodeJsScriptEngine(jsInvokeService, getCurrentUser().getId(), script, argNames); |
323 | - TbMsg inMsg = new TbMsg(UUIDs.timeBased(), msgType, null, new TbMsgMetaData(metadata), TbMsgDataType.JSON, data, null, null, null); | 323 | + TbMsg inMsg = TbMsg.newMsg(msgType, null, new TbMsgMetaData(metadata), TbMsgDataType.JSON, data); |
324 | switch (scriptType) { | 324 | switch (scriptType) { |
325 | case "update": | 325 | case "update": |
326 | output = msgToOutput(engine.executeUpdate(inMsg)); | 326 | output = msgToOutput(engine.executeUpdate(inMsg)); |
@@ -36,8 +36,10 @@ import org.thingsboard.server.gen.transport.TransportProtos.TbTimeSeriesUpdatePr | @@ -36,8 +36,10 @@ import org.thingsboard.server.gen.transport.TransportProtos.TbTimeSeriesUpdatePr | ||
36 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 36 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
37 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; | 37 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreNotificationMsg; |
38 | import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg; | 38 | import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg; |
39 | +import org.thingsboard.server.queue.TbQueueConsumer; | ||
39 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 40 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
40 | -import org.thingsboard.server.queue.provider.TbCoreQueueProvider; | 41 | +import org.thingsboard.server.queue.discovery.PartitionChangeEvent; |
42 | +import org.thingsboard.server.queue.provider.TbCoreQueueFactory; | ||
41 | import org.thingsboard.server.queue.util.TbCoreComponent; | 43 | import org.thingsboard.server.queue.util.TbCoreComponent; |
42 | import org.thingsboard.server.service.encoding.DataDecodingEncodingService; | 44 | import org.thingsboard.server.service.encoding.DataDecodingEncodingService; |
43 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; | 45 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; |
@@ -63,27 +65,28 @@ import java.util.stream.Collectors; | @@ -63,27 +65,28 @@ import java.util.stream.Collectors; | ||
63 | @Service | 65 | @Service |
64 | @TbCoreComponent | 66 | @TbCoreComponent |
65 | @Slf4j | 67 | @Slf4j |
66 | -public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCoreMsg, ToCoreNotificationMsg> implements TbCoreConsumerService { | 68 | +public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCoreNotificationMsg> implements TbCoreConsumerService { |
67 | 69 | ||
68 | - @Value("${queue.core.poll_interval}") | 70 | + @Value("${queue.core.poll-interval}") |
69 | private long pollDuration; | 71 | private long pollDuration; |
70 | - @Value("${queue.core.pack_processing_timeout}") | 72 | + @Value("${queue.core.pack-processing-timeout}") |
71 | private long packProcessingTimeout; | 73 | private long packProcessingTimeout; |
72 | @Value("${queue.core.stats.enabled:false}") | 74 | @Value("${queue.core.stats.enabled:false}") |
73 | private boolean statsEnabled; | 75 | private boolean statsEnabled; |
74 | 76 | ||
77 | + private final TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> mainConsumer; | ||
75 | private final DeviceStateService stateService; | 78 | private final DeviceStateService stateService; |
76 | private final TbLocalSubscriptionService localSubscriptionService; | 79 | private final TbLocalSubscriptionService localSubscriptionService; |
77 | private final SubscriptionManagerService subscriptionManagerService; | 80 | private final SubscriptionManagerService subscriptionManagerService; |
78 | private final TbCoreDeviceRpcService tbCoreDeviceRpcService; | 81 | private final TbCoreDeviceRpcService tbCoreDeviceRpcService; |
79 | private final TbCoreConsumerStats stats = new TbCoreConsumerStats(); | 82 | private final TbCoreConsumerStats stats = new TbCoreConsumerStats(); |
80 | 83 | ||
81 | - public DefaultTbCoreConsumerService(TbCoreQueueProvider tbCoreQueueProvider, ActorSystemContext actorContext, | 84 | + public DefaultTbCoreConsumerService(TbCoreQueueFactory tbCoreQueueFactory, ActorSystemContext actorContext, |
82 | DeviceStateService stateService, TbLocalSubscriptionService localSubscriptionService, | 85 | DeviceStateService stateService, TbLocalSubscriptionService localSubscriptionService, |
83 | SubscriptionManagerService subscriptionManagerService, DataDecodingEncodingService encodingService, | 86 | SubscriptionManagerService subscriptionManagerService, DataDecodingEncodingService encodingService, |
84 | TbCoreDeviceRpcService tbCoreDeviceRpcService) { | 87 | TbCoreDeviceRpcService tbCoreDeviceRpcService) { |
85 | - super(actorContext, encodingService, | ||
86 | - tbCoreQueueProvider.getToCoreMsgConsumer(), tbCoreQueueProvider.getToCoreNotificationsMsgConsumer()); | 88 | + super(actorContext, encodingService, tbCoreQueueFactory.createToCoreNotificationsMsgConsumer()); |
89 | + this.mainConsumer = tbCoreQueueFactory.createToCoreMsgConsumer(); | ||
87 | this.stateService = stateService; | 90 | this.stateService = stateService; |
88 | this.localSubscriptionService = localSubscriptionService; | 91 | this.localSubscriptionService = localSubscriptionService; |
89 | this.subscriptionManagerService = subscriptionManagerService; | 92 | this.subscriptionManagerService = subscriptionManagerService; |
@@ -96,8 +99,16 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -96,8 +99,16 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
96 | } | 99 | } |
97 | 100 | ||
98 | @Override | 101 | @Override |
99 | - protected void launchMainConsumer() { | ||
100 | - mainConsumerExecutor.execute(() -> { | 102 | + public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { |
103 | + if (partitionChangeEvent.getServiceType().equals(getServiceType())) { | ||
104 | + log.info("Subscribing to partitions: {}", partitionChangeEvent.getPartitions()); | ||
105 | + this.mainConsumer.subscribe(partitionChangeEvent.getPartitions()); | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + protected void launchMainConsumers() { | ||
111 | + consumersExecutor.submit(() -> { | ||
101 | while (!stopped) { | 112 | while (!stopped) { |
102 | try { | 113 | try { |
103 | List<TbProtoQueueMsg<ToCoreMsg>> msgs = mainConsumer.poll(pollDuration); | 114 | List<TbProtoQueueMsg<ToCoreMsg>> msgs = mainConsumer.poll(pollDuration); |
@@ -171,7 +182,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -171,7 +182,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
171 | } | 182 | } |
172 | 183 | ||
173 | @Override | 184 | @Override |
174 | - protected void handleNotification(UUID id, TbProtoQueueMsg<ToCoreNotificationMsg> msg, TbMsgCallback callback) throws Exception { | 185 | + protected void handleNotification(UUID id, TbProtoQueueMsg<ToCoreNotificationMsg> msg, TbMsgCallback callback) { |
175 | ToCoreNotificationMsg toCoreMsg = msg.getValue(); | 186 | ToCoreNotificationMsg toCoreMsg = msg.getValue(); |
176 | if (toCoreMsg.hasToLocalSubscriptionServiceMsg()) { | 187 | if (toCoreMsg.hasToLocalSubscriptionServiceMsg()) { |
177 | log.trace("[{}] Forwarding message to local subscription service {}", id, toCoreMsg.getToLocalSubscriptionServiceMsg()); | 188 | log.trace("[{}] Forwarding message to local subscription service {}", id, toCoreMsg.getToLocalSubscriptionServiceMsg()); |
@@ -197,7 +208,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -197,7 +208,7 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
197 | callback.onSuccess(); | 208 | callback.onSuccess(); |
198 | } | 209 | } |
199 | 210 | ||
200 | - @Scheduled(fixedDelayString = "${queue.core.stats.print_interval_ms}") | 211 | + @Scheduled(fixedDelayString = "${queue.core.stats.print-interval-ms}") |
201 | public void printStats() { | 212 | public void printStats() { |
202 | if (statsEnabled) { | 213 | if (statsEnabled) { |
203 | stats.printStats(); | 214 | stats.printStats(); |
@@ -255,4 +266,12 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -255,4 +266,12 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
255 | log.warn("Message not handled: {}", msg); | 266 | log.warn("Message not handled: {}", msg); |
256 | callback.onFailure(new RuntimeException("Message not handled!")); | 267 | callback.onFailure(new RuntimeException("Message not handled!")); |
257 | } | 268 | } |
269 | + | ||
270 | + @Override | ||
271 | + protected void stopMainConsumers() { | ||
272 | + if (mainConsumer != null) { | ||
273 | + mainConsumer.unsubscribe(); | ||
274 | + } | ||
275 | + } | ||
276 | + | ||
258 | } | 277 | } |
@@ -17,6 +17,7 @@ package org.thingsboard.server.service.queue; | @@ -17,6 +17,7 @@ package org.thingsboard.server.service.queue; | ||
17 | 17 | ||
18 | import akka.actor.ActorRef; | 18 | import akka.actor.ActorRef; |
19 | import com.google.protobuf.ByteString; | 19 | import com.google.protobuf.ByteString; |
20 | +import com.google.protobuf.ProtocolStringList; | ||
20 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
21 | import org.springframework.beans.factory.annotation.Value; | 22 | import org.springframework.beans.factory.annotation.Value; |
22 | import org.springframework.scheduling.annotation.Scheduled; | 23 | import org.springframework.scheduling.annotation.Scheduled; |
@@ -26,12 +27,17 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -26,12 +27,17 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
26 | import org.thingsboard.server.common.msg.TbActorMsg; | 27 | import org.thingsboard.server.common.msg.TbActorMsg; |
27 | import org.thingsboard.server.common.msg.TbMsg; | 28 | import org.thingsboard.server.common.msg.TbMsg; |
28 | import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg; | 29 | import org.thingsboard.server.common.msg.queue.QueueToRuleEngineMsg; |
30 | +import org.thingsboard.server.common.msg.queue.ServiceQueue; | ||
29 | import org.thingsboard.server.common.msg.queue.ServiceType; | 31 | import org.thingsboard.server.common.msg.queue.ServiceType; |
30 | import org.thingsboard.server.common.msg.queue.TbMsgCallback; | 32 | import org.thingsboard.server.common.msg.queue.TbMsgCallback; |
31 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 33 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
32 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 34 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
35 | +import org.thingsboard.server.queue.TbQueueConsumer; | ||
33 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 36 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
34 | -import org.thingsboard.server.queue.provider.TbRuleEngineQueueProvider; | 37 | +import org.thingsboard.server.queue.discovery.PartitionChangeEvent; |
38 | +import org.thingsboard.server.queue.provider.TbRuleEngineQueueFactory; | ||
39 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; | ||
40 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
35 | import org.thingsboard.server.queue.util.TbRuleEngineComponent; | 41 | import org.thingsboard.server.queue.util.TbRuleEngineComponent; |
36 | import org.thingsboard.server.service.encoding.DataDecodingEncodingService; | 42 | import org.thingsboard.server.service.encoding.DataDecodingEncodingService; |
37 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; | 43 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; |
@@ -41,8 +47,11 @@ import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingStr | @@ -41,8 +47,11 @@ import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingStr | ||
41 | import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingStrategyFactory; | 47 | import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingStrategyFactory; |
42 | 48 | ||
43 | import javax.annotation.PostConstruct; | 49 | import javax.annotation.PostConstruct; |
50 | +import java.util.Collections; | ||
51 | +import java.util.HashSet; | ||
44 | import java.util.List; | 52 | import java.util.List; |
45 | import java.util.Optional; | 53 | import java.util.Optional; |
54 | +import java.util.Set; | ||
46 | import java.util.UUID; | 55 | import java.util.UUID; |
47 | import java.util.concurrent.ConcurrentHashMap; | 56 | import java.util.concurrent.ConcurrentHashMap; |
48 | import java.util.concurrent.ConcurrentMap; | 57 | import java.util.concurrent.ConcurrentMap; |
@@ -54,41 +63,67 @@ import java.util.stream.Collectors; | @@ -54,41 +63,67 @@ import java.util.stream.Collectors; | ||
54 | @Service | 63 | @Service |
55 | @TbRuleEngineComponent | 64 | @TbRuleEngineComponent |
56 | @Slf4j | 65 | @Slf4j |
57 | -public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<ToRuleEngineMsg, ToRuleEngineNotificationMsg> implements TbRuleEngineConsumerService { | 66 | +public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService<ToRuleEngineNotificationMsg> implements TbRuleEngineConsumerService { |
58 | 67 | ||
59 | - @Value("${queue.rule_engine.poll_interval}") | 68 | + @Value("${queue.rule-engine.poll-interval}") |
60 | private long pollDuration; | 69 | private long pollDuration; |
61 | - @Value("${queue.rule_engine.pack_processing_timeout}") | 70 | + @Value("${queue.rule-engine.pack-processing-timeout}") |
62 | private long packProcessingTimeout; | 71 | private long packProcessingTimeout; |
63 | - @Value("${queue.rule_engine.stats.enabled:false}") | 72 | + @Value("${queue.rule-engine.stats.enabled:false}") |
64 | private boolean statsEnabled; | 73 | private boolean statsEnabled; |
65 | 74 | ||
66 | private final TbCoreConsumerStats stats = new TbCoreConsumerStats(); | 75 | private final TbCoreConsumerStats stats = new TbCoreConsumerStats(); |
67 | private final TbRuleEngineProcessingStrategyFactory factory; | 76 | private final TbRuleEngineProcessingStrategyFactory factory; |
77 | + private final TbRuleEngineQueueFactory tbRuleEngineQueueFactory; | ||
78 | + private final TbQueueRuleEngineSettings ruleEngineSettings; | ||
79 | + private final ConcurrentMap<String, TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>>> consumers = new ConcurrentHashMap<>(); | ||
80 | + private final ConcurrentMap<String, TbRuleEngineQueueConfiguration> consumerConfigurations = new ConcurrentHashMap<>(); | ||
68 | 81 | ||
69 | - public DefaultTbRuleEngineConsumerService(TbRuleEngineProcessingStrategyFactory factory, TbRuleEngineQueueProvider tbRuleEngineQueueProvider, | 82 | + public DefaultTbRuleEngineConsumerService(TbRuleEngineProcessingStrategyFactory factory, TbQueueRuleEngineSettings ruleEngineSettings, |
83 | + TbRuleEngineQueueFactory tbRuleEngineQueueFactory, | ||
70 | ActorSystemContext actorContext, DataDecodingEncodingService encodingService) { | 84 | ActorSystemContext actorContext, DataDecodingEncodingService encodingService) { |
71 | - super(actorContext, encodingService, | ||
72 | - tbRuleEngineQueueProvider.getToRuleEngineMsgConsumer(), tbRuleEngineQueueProvider.getToRuleEngineNotificationsMsgConsumer()); | 85 | + super(actorContext, encodingService, tbRuleEngineQueueFactory.createToRuleEngineNotificationsMsgConsumer()); |
86 | + this.ruleEngineSettings = ruleEngineSettings; | ||
87 | + this.tbRuleEngineQueueFactory = tbRuleEngineQueueFactory; | ||
73 | this.factory = factory; | 88 | this.factory = factory; |
74 | } | 89 | } |
75 | 90 | ||
76 | @PostConstruct | 91 | @PostConstruct |
77 | public void init() { | 92 | public void init() { |
78 | super.init("tb-rule-engine-consumer", "tb-rule-engine-notifications-consumer"); | 93 | super.init("tb-rule-engine-consumer", "tb-rule-engine-notifications-consumer"); |
79 | - this.factory.newInstance(); | 94 | + for (TbRuleEngineQueueConfiguration configuration : ruleEngineSettings.getQueues()) { |
95 | + consumers.computeIfAbsent(configuration.getName(), queueName -> tbRuleEngineQueueFactory.createToRuleEngineMsgConsumer(configuration)); | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { | ||
101 | + if (partitionChangeEvent.getServiceType().equals(getServiceType())) { | ||
102 | + ServiceQueue serviceQueue = partitionChangeEvent.getServiceQueueKey().getServiceQueue(); | ||
103 | + log.info("[{}] Subscribing to partitions: {}", serviceQueue.getQueue(), partitionChangeEvent.getPartitions()); | ||
104 | + consumers.get(serviceQueue.getQueue()).subscribe(partitionChangeEvent.getPartitions()); | ||
105 | + } | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + protected void launchMainConsumers() { | ||
110 | + consumers.forEach((queue, consumer) -> launchConsumer(consumer, consumerConfigurations.get(queue))); | ||
80 | } | 111 | } |
81 | 112 | ||
82 | @Override | 113 | @Override |
83 | - protected void launchMainConsumer() { | ||
84 | - mainConsumerExecutor.execute(() -> { | 114 | + protected void stopMainConsumers() { |
115 | + consumers.values().forEach(TbQueueConsumer::unsubscribe); | ||
116 | + } | ||
117 | + | ||
118 | + private void launchConsumer(TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> consumer, TbRuleEngineQueueConfiguration configuration) { | ||
119 | + consumersExecutor.execute(() -> { | ||
85 | while (!stopped) { | 120 | while (!stopped) { |
86 | try { | 121 | try { |
87 | - List<TbProtoQueueMsg<ToRuleEngineMsg>> msgs = mainConsumer.poll(pollDuration); | 122 | + List<TbProtoQueueMsg<ToRuleEngineMsg>> msgs = consumer.poll(pollDuration); |
88 | if (msgs.isEmpty()) { | 123 | if (msgs.isEmpty()) { |
89 | continue; | 124 | continue; |
90 | } | 125 | } |
91 | - TbRuleEngineProcessingStrategy strategy = factory.newInstance(); | 126 | + TbRuleEngineProcessingStrategy strategy = factory.newInstance(configuration.getAckStrategy()); |
92 | TbRuleEngineProcessingDecision decision = null; | 127 | TbRuleEngineProcessingDecision decision = null; |
93 | boolean firstAttempt = true; | 128 | boolean firstAttempt = true; |
94 | while (!stopped && (firstAttempt || !decision.isCommit())) { | 129 | while (!stopped && (firstAttempt || !decision.isCommit())) { |
@@ -111,7 +146,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | @@ -111,7 +146,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | ||
111 | ToRuleEngineMsg toRuleEngineMsg = msg.getValue(); | 146 | ToRuleEngineMsg toRuleEngineMsg = msg.getValue(); |
112 | TenantId tenantId = new TenantId(new UUID(toRuleEngineMsg.getTenantIdMSB(), toRuleEngineMsg.getTenantIdLSB())); | 147 | TenantId tenantId = new TenantId(new UUID(toRuleEngineMsg.getTenantIdMSB(), toRuleEngineMsg.getTenantIdLSB())); |
113 | if (toRuleEngineMsg.getTbMsg() != null && !toRuleEngineMsg.getTbMsg().isEmpty()) { | 148 | if (toRuleEngineMsg.getTbMsg() != null && !toRuleEngineMsg.getTbMsg().isEmpty()) { |
114 | - forwardToRuleEngineActor(tenantId, toRuleEngineMsg.getTbMsg(), callback); | 149 | + forwardToRuleEngineActor(tenantId, toRuleEngineMsg, callback); |
115 | } else { | 150 | } else { |
116 | callback.onSuccess(); | 151 | callback.onSuccess(); |
117 | } | 152 | } |
@@ -126,7 +161,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | @@ -126,7 +161,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | ||
126 | } | 161 | } |
127 | decision = strategy.analyze(new TbRuleEngineProcessingResult(timeout, allMap, successMap, failedMap)); | 162 | decision = strategy.analyze(new TbRuleEngineProcessingResult(timeout, allMap, successMap, failedMap)); |
128 | } | 163 | } |
129 | - mainConsumer.commit(); | 164 | + consumer.commit(); |
130 | } catch (Exception e) { | 165 | } catch (Exception e) { |
131 | if (!stopped) { | 166 | if (!stopped) { |
132 | log.warn("Failed to process messages from queue.", e); | 167 | log.warn("Failed to process messages from queue.", e); |
@@ -172,16 +207,27 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | @@ -172,16 +207,27 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | ||
172 | } | 207 | } |
173 | } | 208 | } |
174 | 209 | ||
175 | - private void forwardToRuleEngineActor(TenantId tenantId, ByteString tbMsgData, TbMsgCallback callback) { | ||
176 | - TbMsg tbMsg = TbMsg.fromBytes(tbMsgData.toByteArray(), callback); | ||
177 | - actorContext.getAppActor().tell(new QueueToRuleEngineMsg(tenantId, tbMsg), ActorRef.noSender()); | 210 | + private void forwardToRuleEngineActor(TenantId tenantId, ToRuleEngineMsg toRuleEngineMsg, TbMsgCallback callback) { |
211 | + TbMsg tbMsg = TbMsg.fromBytes(toRuleEngineMsg.getTbMsg().toByteArray(), callback); | ||
212 | + QueueToRuleEngineMsg msg; | ||
213 | + ProtocolStringList relationTypesList = toRuleEngineMsg.getRelationTypesList(); | ||
214 | + Set<String> relationTypes = null; | ||
215 | + if (relationTypesList != null) { | ||
216 | + if (relationTypesList.size() == 1) { | ||
217 | + relationTypes = Collections.singleton(relationTypesList.get(0)); | ||
218 | + } else { | ||
219 | + relationTypes = new HashSet<>(relationTypesList); | ||
220 | + } | ||
221 | + } | ||
222 | + msg = new QueueToRuleEngineMsg(tenantId, tbMsg, relationTypes); | ||
223 | + actorContext.getAppActor().tell(msg, ActorRef.noSender()); | ||
178 | //TODO: 2.5 before release. | 224 | //TODO: 2.5 before release. |
179 | // if (statsEnabled) { | 225 | // if (statsEnabled) { |
180 | // stats.log(toDeviceActorMsg); | 226 | // stats.log(toDeviceActorMsg); |
181 | // } | 227 | // } |
182 | } | 228 | } |
183 | 229 | ||
184 | - @Scheduled(fixedDelayString = "${queue.rule_engine.stats.print_interval_ms}") | 230 | + @Scheduled(fixedDelayString = "${queue.rule-engine.stats.print-interval-ms}") |
185 | public void printStats() { | 231 | public void printStats() { |
186 | if (statsEnabled) { | 232 | if (statsEnabled) { |
187 | stats.printStats(); | 233 | stats.printStats(); |
@@ -42,55 +42,48 @@ import java.util.function.Function; | @@ -42,55 +42,48 @@ import java.util.function.Function; | ||
42 | import java.util.stream.Collectors; | 42 | import java.util.stream.Collectors; |
43 | 43 | ||
44 | @Slf4j | 44 | @Slf4j |
45 | -public abstract class AbstractConsumerService<T extends com.google.protobuf.GeneratedMessageV3, N extends com.google.protobuf.GeneratedMessageV3> implements ApplicationListener<PartitionChangeEvent> { | 45 | +public abstract class AbstractConsumerService<N extends com.google.protobuf.GeneratedMessageV3> implements ApplicationListener<PartitionChangeEvent> { |
46 | 46 | ||
47 | - protected volatile ExecutorService mainConsumerExecutor; | ||
48 | - private volatile ExecutorService notificationsConsumerExecutor; | 47 | + protected volatile ExecutorService consumersExecutor; |
48 | + protected volatile ExecutorService notificationsConsumerExecutor; | ||
49 | protected volatile boolean stopped = false; | 49 | protected volatile boolean stopped = false; |
50 | 50 | ||
51 | protected final ActorSystemContext actorContext; | 51 | protected final ActorSystemContext actorContext; |
52 | protected final DataDecodingEncodingService encodingService; | 52 | protected final DataDecodingEncodingService encodingService; |
53 | - protected final TbQueueConsumer<TbProtoQueueMsg<T>> mainConsumer; | 53 | + |
54 | protected final TbQueueConsumer<TbProtoQueueMsg<N>> nfConsumer; | 54 | protected final TbQueueConsumer<TbProtoQueueMsg<N>> nfConsumer; |
55 | 55 | ||
56 | - public AbstractConsumerService(ActorSystemContext actorContext, DataDecodingEncodingService encodingService, TbQueueConsumer<TbProtoQueueMsg<T>> mainConsumer, TbQueueConsumer<TbProtoQueueMsg<N>> nfConsumer) { | 56 | + public AbstractConsumerService(ActorSystemContext actorContext, DataDecodingEncodingService encodingService, TbQueueConsumer<TbProtoQueueMsg<N>> nfConsumer) { |
57 | this.actorContext = actorContext; | 57 | this.actorContext = actorContext; |
58 | this.encodingService = encodingService; | 58 | this.encodingService = encodingService; |
59 | - this.mainConsumer = mainConsumer; | ||
60 | this.nfConsumer = nfConsumer; | 59 | this.nfConsumer = nfConsumer; |
61 | } | 60 | } |
62 | 61 | ||
63 | public void init(String mainConsumerThreadName, String nfConsumerThreadName) { | 62 | public void init(String mainConsumerThreadName, String nfConsumerThreadName) { |
64 | - this.mainConsumerExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName(mainConsumerThreadName)); | 63 | + this.consumersExecutor = Executors.newCachedThreadPool(ThingsBoardThreadFactory.forName(mainConsumerThreadName)); |
65 | this.notificationsConsumerExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName(nfConsumerThreadName)); | 64 | this.notificationsConsumerExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName(nfConsumerThreadName)); |
66 | } | 65 | } |
67 | 66 | ||
68 | - @Override | ||
69 | - public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { | ||
70 | - if (partitionChangeEvent.getServiceKey().getServiceType() == getServiceType()) { | ||
71 | - log.info("Subscribing to partitions: {}", partitionChangeEvent.getPartitions()); | ||
72 | - this.mainConsumer.subscribe(partitionChangeEvent.getPartitions()); | ||
73 | - } | ||
74 | - } | ||
75 | - | ||
76 | @EventListener(ApplicationReadyEvent.class) | 67 | @EventListener(ApplicationReadyEvent.class) |
77 | public void onApplicationEvent(ApplicationReadyEvent event) { | 68 | public void onApplicationEvent(ApplicationReadyEvent event) { |
78 | log.info("Subscribing to notifications: {}", nfConsumer.getTopic()); | 69 | log.info("Subscribing to notifications: {}", nfConsumer.getTopic()); |
79 | this.nfConsumer.subscribe(); | 70 | this.nfConsumer.subscribe(); |
80 | launchNotificationsConsumer(); | 71 | launchNotificationsConsumer(); |
81 | - launchMainConsumer(); | 72 | + launchMainConsumers(); |
82 | } | 73 | } |
83 | 74 | ||
84 | protected abstract ServiceType getServiceType(); | 75 | protected abstract ServiceType getServiceType(); |
85 | 76 | ||
86 | - protected abstract void launchMainConsumer(); | 77 | + protected abstract void launchMainConsumers(); |
78 | + | ||
79 | + protected abstract void stopMainConsumers(); | ||
87 | 80 | ||
88 | protected abstract long getNotificationPollDuration(); | 81 | protected abstract long getNotificationPollDuration(); |
89 | 82 | ||
90 | protected abstract long getNotificationPackProcessingTimeout(); | 83 | protected abstract long getNotificationPackProcessingTimeout(); |
91 | 84 | ||
92 | protected void launchNotificationsConsumer() { | 85 | protected void launchNotificationsConsumer() { |
93 | - notificationsConsumerExecutor.execute(() -> { | 86 | + notificationsConsumerExecutor.submit(() -> { |
94 | while (!stopped) { | 87 | while (!stopped) { |
95 | try { | 88 | try { |
96 | List<TbProtoQueueMsg<N>> msgs = nfConsumer.poll(getNotificationPollDuration()); | 89 | List<TbProtoQueueMsg<N>> msgs = nfConsumer.poll(getNotificationPollDuration()); |
@@ -137,16 +130,14 @@ public abstract class AbstractConsumerService<T extends com.google.protobuf.Gene | @@ -137,16 +130,14 @@ public abstract class AbstractConsumerService<T extends com.google.protobuf.Gene | ||
137 | public void destroy() { | 130 | public void destroy() { |
138 | stopped = true; | 131 | stopped = true; |
139 | 132 | ||
140 | - if (mainConsumer != null) { | ||
141 | - mainConsumer.unsubscribe(); | ||
142 | - } | 133 | + stopMainConsumers(); |
143 | 134 | ||
144 | if (nfConsumer != null) { | 135 | if (nfConsumer != null) { |
145 | nfConsumer.unsubscribe(); | 136 | nfConsumer.unsubscribe(); |
146 | } | 137 | } |
147 | 138 | ||
148 | - if (mainConsumerExecutor != null) { | ||
149 | - mainConsumerExecutor.shutdownNow(); | 139 | + if (consumersExecutor != null) { |
140 | + consumersExecutor.shutdownNow(); | ||
150 | } | 141 | } |
151 | if (notificationsConsumerExecutor != null) { | 142 | if (notificationsConsumerExecutor != null) { |
152 | notificationsConsumerExecutor.shutdownNow(); | 143 | notificationsConsumerExecutor.shutdownNow(); |
@@ -20,6 +20,8 @@ import org.springframework.beans.factory.annotation.Value; | @@ -20,6 +20,8 @@ import org.springframework.beans.factory.annotation.Value; | ||
20 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
21 | import org.thingsboard.server.gen.transport.TransportProtos; | 21 | import org.thingsboard.server.gen.transport.TransportProtos; |
22 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 22 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
23 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueAckStrategyConfiguration; | ||
24 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
23 | 25 | ||
24 | import java.util.UUID; | 26 | import java.util.UUID; |
25 | import java.util.concurrent.ConcurrentHashMap; | 27 | import java.util.concurrent.ConcurrentHashMap; |
@@ -30,30 +32,20 @@ import java.util.concurrent.TimeUnit; | @@ -30,30 +32,20 @@ import java.util.concurrent.TimeUnit; | ||
30 | @Slf4j | 32 | @Slf4j |
31 | public class TbRuleEngineProcessingStrategyFactory { | 33 | public class TbRuleEngineProcessingStrategyFactory { |
32 | 34 | ||
33 | - @Value("${queue.rule_engine.strategy.type}") | ||
34 | - private String strategyType; | ||
35 | - @Value("${queue.rule_engine.strategy.retries:3}") | ||
36 | - private int maxRetries; | ||
37 | - @Value("${queue.rule_engine.strategy.failure_percentage:0}") | ||
38 | - private double maxAllowedFailurePercentage; | ||
39 | - @Value("${queue.rule_engine.strategy.pause_between_retries:3}") | ||
40 | - private long pauseBetweenRetries; | ||
41 | - | ||
42 | - | ||
43 | - public TbRuleEngineProcessingStrategy newInstance() { | ||
44 | - switch (strategyType) { | 35 | + public TbRuleEngineProcessingStrategy newInstance(TbRuleEngineQueueAckStrategyConfiguration configuration) { |
36 | + switch (configuration.getType()) { | ||
45 | case "SKIP_ALL": | 37 | case "SKIP_ALL": |
46 | return new SkipStrategy(); | 38 | return new SkipStrategy(); |
47 | case "RETRY_ALL": | 39 | case "RETRY_ALL": |
48 | - return new RetryStrategy(true, true, true, maxRetries, maxAllowedFailurePercentage, pauseBetweenRetries); | 40 | + return new RetryStrategy(true, true, true, configuration); |
49 | case "RETRY_FAILED": | 41 | case "RETRY_FAILED": |
50 | - return new RetryStrategy(false, true, false, maxRetries, maxAllowedFailurePercentage, pauseBetweenRetries); | 42 | + return new RetryStrategy(false, true, false, configuration); |
51 | case "RETRY_TIMED_OUT": | 43 | case "RETRY_TIMED_OUT": |
52 | - return new RetryStrategy(false, false, true, maxRetries, maxAllowedFailurePercentage, pauseBetweenRetries); | 44 | + return new RetryStrategy(false, false, true, configuration); |
53 | case "RETRY_FAILED_AND_TIMED_OUT": | 45 | case "RETRY_FAILED_AND_TIMED_OUT": |
54 | - return new RetryStrategy(false, true, true, maxRetries, maxAllowedFailurePercentage, pauseBetweenRetries); | 46 | + return new RetryStrategy(false, true, true, configuration); |
55 | default: | 47 | default: |
56 | - throw new RuntimeException("TbRuleEngineProcessingStrategy with type " + strategyType + " is not supported!"); | 48 | + throw new RuntimeException("TbRuleEngineProcessingStrategy with type " + configuration.getType() + " is not supported!"); |
57 | } | 49 | } |
58 | } | 50 | } |
59 | 51 | ||
@@ -68,13 +60,13 @@ public class TbRuleEngineProcessingStrategyFactory { | @@ -68,13 +60,13 @@ public class TbRuleEngineProcessingStrategyFactory { | ||
68 | private int initialTotalCount; | 60 | private int initialTotalCount; |
69 | private int retryCount; | 61 | private int retryCount; |
70 | 62 | ||
71 | - public RetryStrategy(boolean retrySuccessful, boolean retryFailed, boolean retryTimeout, int maxRetries, double maxAllowedFailurePercentage, long pauseBetweenRetries) { | 63 | + public RetryStrategy(boolean retrySuccessful, boolean retryFailed, boolean retryTimeout, TbRuleEngineQueueAckStrategyConfiguration configuration) { |
72 | this.retrySuccessful = retrySuccessful; | 64 | this.retrySuccessful = retrySuccessful; |
73 | this.retryFailed = retryFailed; | 65 | this.retryFailed = retryFailed; |
74 | this.retryTimeout = retryTimeout; | 66 | this.retryTimeout = retryTimeout; |
75 | - this.maxRetries = maxRetries; | ||
76 | - this.maxAllowedFailurePercentage = maxAllowedFailurePercentage; | ||
77 | - this.pauseBetweenRetries = pauseBetweenRetries; | 67 | + this.maxRetries = configuration.getRetries(); |
68 | + this.maxAllowedFailurePercentage = configuration.getFailurePercentage(); | ||
69 | + this.pauseBetweenRetries = configuration.getPauseBetweenRetries(); | ||
78 | } | 70 | } |
79 | 71 | ||
80 | @Override | 72 | @Override |
@@ -169,9 +169,7 @@ public class DefaultTbCoreDeviceRpcService implements TbCoreDeviceRpcService { | @@ -169,9 +169,7 @@ public class DefaultTbCoreDeviceRpcService implements TbCoreDeviceRpcService { | ||
169 | entityNode.put("params", msg.getBody().getParams()); | 169 | entityNode.put("params", msg.getBody().getParams()); |
170 | 170 | ||
171 | try { | 171 | try { |
172 | - TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), DataConstants.RPC_CALL_FROM_SERVER_TO_DEVICE, msg.getDeviceId(), metaData, TbMsgDataType.JSON | ||
173 | - , json.writeValueAsString(entityNode) | ||
174 | - , null, null, null); | 172 | + TbMsg tbMsg = TbMsg.newMsg(DataConstants.RPC_CALL_FROM_SERVER_TO_DEVICE, msg.getDeviceId(), metaData, TbMsgDataType.JSON, json.writeValueAsString(entityNode)); |
175 | clusterService.onToRuleEngineMsg(msg.getTenantId(), msg.getDeviceId(), tbMsg); | 173 | clusterService.onToRuleEngineMsg(msg.getTenantId(), msg.getDeviceId(), tbMsg); |
176 | } catch (JsonProcessingException e) { | 174 | } catch (JsonProcessingException e) { |
177 | throw new RuntimeException(e); | 175 | throw new RuntimeException(e); |
@@ -94,7 +94,7 @@ public class RuleNodeJsScriptEngine implements org.thingsboard.rule.engine.api.S | @@ -94,7 +94,7 @@ public class RuleNodeJsScriptEngine implements org.thingsboard.rule.engine.api.S | ||
94 | String newData = data != null ? data : msg.getData(); | 94 | String newData = data != null ? data : msg.getData(); |
95 | TbMsgMetaData newMetadata = metadata != null ? new TbMsgMetaData(metadata) : msg.getMetaData().copy(); | 95 | TbMsgMetaData newMetadata = metadata != null ? new TbMsgMetaData(metadata) : msg.getMetaData().copy(); |
96 | String newMessageType = !StringUtils.isEmpty(messageType) ? messageType : msg.getType(); | 96 | String newMessageType = !StringUtils.isEmpty(messageType) ? messageType : msg.getType(); |
97 | - return new TbMsg(msg.getId(), newMessageType, msg.getOriginator(), newMetadata, msg.getDataType(), newData, msg.getRuleChainId(), msg.getRuleNodeId(), msg.getCallback()); | 97 | + return TbMsg.transformMsg(msg, newMessageType, msg.getOriginator(), newMetadata, newData); |
98 | } catch (Throwable th) { | 98 | } catch (Throwable th) { |
99 | th.printStackTrace(); | 99 | th.printStackTrace(); |
100 | throw new RuntimeException("Failed to unbind message data from javascript result", th); | 100 | throw new RuntimeException("Failed to unbind message data from javascript result", th); |
@@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.state; | 16 | package org.thingsboard.server.service.state; |
17 | 17 | ||
18 | -import com.datastax.driver.core.utils.UUIDs; | ||
19 | import com.fasterxml.jackson.databind.ObjectMapper; | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import com.google.common.base.Function; | 19 | import com.google.common.base.Function; |
21 | import com.google.common.util.concurrent.FutureCallback; | 20 | import com.google.common.util.concurrent.FutureCallback; |
@@ -296,7 +295,7 @@ public class DefaultDeviceStateService implements DeviceStateService { | @@ -296,7 +295,7 @@ public class DefaultDeviceStateService implements DeviceStateService { | ||
296 | 295 | ||
297 | @Override | 296 | @Override |
298 | public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { | 297 | public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { |
299 | - if (ServiceType.TB_CORE.equals(partitionChangeEvent.getServiceKey().getServiceType())) { | 298 | + if (ServiceType.TB_CORE.equals(partitionChangeEvent.getServiceType())) { |
300 | synchronized (this) { | 299 | synchronized (this) { |
301 | if (!clusterUpdatePending) { | 300 | if (!clusterUpdatePending) { |
302 | clusterUpdatePending = true; | 301 | clusterUpdatePending = true; |
@@ -496,9 +495,8 @@ public class DefaultDeviceStateService implements DeviceStateService { | @@ -496,9 +495,8 @@ public class DefaultDeviceStateService implements DeviceStateService { | ||
496 | private void pushRuleEngineMessage(DeviceStateData stateData, String msgType) { | 495 | private void pushRuleEngineMessage(DeviceStateData stateData, String msgType) { |
497 | DeviceState state = stateData.getState(); | 496 | DeviceState state = stateData.getState(); |
498 | try { | 497 | try { |
499 | - TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), msgType, stateData.getDeviceId(), stateData.getMetaData().copy(), TbMsgDataType.JSON | ||
500 | - , json.writeValueAsString(state) | ||
501 | - , null, null, TbMsgCallback.EMPTY); | 498 | + TbMsg tbMsg = TbMsg.newMsg(msgType, stateData.getDeviceId(), stateData.getMetaData().copy(), TbMsgDataType.JSON |
499 | + , json.writeValueAsString(state)); | ||
502 | TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_RULE_ENGINE, stateData.getTenantId(), stateData.getDeviceId()); | 500 | TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_RULE_ENGINE, stateData.getTenantId(), stateData.getDeviceId()); |
503 | TransportProtos.ToRuleEngineMsg msg = TransportProtos.ToRuleEngineMsg.newBuilder() | 501 | TransportProtos.ToRuleEngineMsg msg = TransportProtos.ToRuleEngineMsg.newBuilder() |
504 | .setTenantIdMSB(stateData.getTenantId().getId().getMostSignificantBits()) | 502 | .setTenantIdMSB(stateData.getTenantId().getId().getMostSignificantBits()) |
@@ -95,7 +95,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer | @@ -95,7 +95,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer | ||
95 | @Override | 95 | @Override |
96 | @EventListener(PartitionChangeEvent.class) | 96 | @EventListener(PartitionChangeEvent.class) |
97 | public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { | 97 | public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { |
98 | - if (ServiceType.TB_CORE.equals(partitionChangeEvent.getServiceKey().getServiceType())) { | 98 | + if (ServiceType.TB_CORE.equals(partitionChangeEvent.getServiceType())) { |
99 | currentPartitions.clear(); | 99 | currentPartitions.clear(); |
100 | currentPartitions.addAll(partitionChangeEvent.getPartitions()); | 100 | currentPartitions.addAll(partitionChangeEvent.getPartitions()); |
101 | } | 101 | } |
@@ -104,7 +104,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer | @@ -104,7 +104,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer | ||
104 | @Override | 104 | @Override |
105 | @EventListener(ClusterTopologyChangeEvent.class) | 105 | @EventListener(ClusterTopologyChangeEvent.class) |
106 | public void onApplicationEvent(ClusterTopologyChangeEvent event) { | 106 | public void onApplicationEvent(ClusterTopologyChangeEvent event) { |
107 | - if (event.getServiceKeys().stream().anyMatch(key -> ServiceType.TB_CORE.equals(key.getServiceType()))) { | 107 | + if (event.getServiceQueueKeys().stream().anyMatch(key -> ServiceType.TB_CORE.equals(key.getServiceType()))) { |
108 | /* | 108 | /* |
109 | * If the cluster topology has changed, we need to push all current subscriptions to SubscriptionManagerService again. | 109 | * If the cluster topology has changed, we need to push all current subscriptions to SubscriptionManagerService again. |
110 | * Otherwise, the SubscriptionManagerService may "forget" those subscriptions in case of restart. | 110 | * Otherwise, the SubscriptionManagerService may "forget" those subscriptions in case of restart. |
@@ -113,7 +113,7 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio | @@ -113,7 +113,7 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio | ||
113 | @Override | 113 | @Override |
114 | @EventListener(PartitionChangeEvent.class) | 114 | @EventListener(PartitionChangeEvent.class) |
115 | public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { | 115 | public void onApplicationEvent(PartitionChangeEvent partitionChangeEvent) { |
116 | - if (ServiceType.TB_CORE.equals(partitionChangeEvent.getServiceKey().getServiceType())) { | 116 | + if (ServiceType.TB_CORE.equals(partitionChangeEvent.getServiceType())) { |
117 | currentPartitions.clear(); | 117 | currentPartitions.clear(); |
118 | currentPartitions.addAll(partitionChangeEvent.getPartitions()); | 118 | currentPartitions.addAll(partitionChangeEvent.getPartitions()); |
119 | } | 119 | } |
@@ -27,7 +27,7 @@ import org.thingsboard.server.queue.common.DefaultTbQueueResponseTemplate; | @@ -27,7 +27,7 @@ import org.thingsboard.server.queue.common.DefaultTbQueueResponseTemplate; | ||
27 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 27 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
28 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; | 28 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; |
29 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 29 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
30 | -import org.thingsboard.server.queue.provider.TbCoreQueueProvider; | 30 | +import org.thingsboard.server.queue.provider.TbCoreQueueFactory; |
31 | import org.thingsboard.server.queue.util.TbCoreComponent; | 31 | import org.thingsboard.server.queue.util.TbCoreComponent; |
32 | 32 | ||
33 | import javax.annotation.PostConstruct; | 33 | import javax.annotation.PostConstruct; |
@@ -42,7 +42,7 @@ import java.util.concurrent.*; | @@ -42,7 +42,7 @@ import java.util.concurrent.*; | ||
42 | @TbCoreComponent | 42 | @TbCoreComponent |
43 | public class TbCoreTransportApiService { | 43 | public class TbCoreTransportApiService { |
44 | 44 | ||
45 | - private final TbCoreQueueProvider tbCoreQueueProvider; | 45 | + private final TbCoreQueueFactory tbCoreQueueFactory; |
46 | private final TransportApiService transportApiService; | 46 | private final TransportApiService transportApiService; |
47 | 47 | ||
48 | @Value("${queue.transport_api.max_pending_requests:10000}") | 48 | @Value("${queue.transport_api.max_pending_requests:10000}") |
@@ -58,16 +58,16 @@ public class TbCoreTransportApiService { | @@ -58,16 +58,16 @@ public class TbCoreTransportApiService { | ||
58 | private TbQueueResponseTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, | 58 | private TbQueueResponseTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, |
59 | TbProtoQueueMsg<TransportApiResponseMsg>> transportApiTemplate; | 59 | TbProtoQueueMsg<TransportApiResponseMsg>> transportApiTemplate; |
60 | 60 | ||
61 | - public TbCoreTransportApiService(TbCoreQueueProvider tbCoreQueueProvider, TransportApiService transportApiService) { | ||
62 | - this.tbCoreQueueProvider = tbCoreQueueProvider; | 61 | + public TbCoreTransportApiService(TbCoreQueueFactory tbCoreQueueFactory, TransportApiService transportApiService) { |
62 | + this.tbCoreQueueFactory = tbCoreQueueFactory; | ||
63 | this.transportApiService = transportApiService; | 63 | this.transportApiService = transportApiService; |
64 | } | 64 | } |
65 | 65 | ||
66 | @PostConstruct | 66 | @PostConstruct |
67 | public void init() { | 67 | public void init() { |
68 | this.transportCallbackExecutor = Executors.newWorkStealingPool(maxCallbackThreads); | 68 | this.transportCallbackExecutor = Executors.newWorkStealingPool(maxCallbackThreads); |
69 | - TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> producer = tbCoreQueueProvider.getTransportApiResponseProducer(); | ||
70 | - TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> consumer = tbCoreQueueProvider.getTransportApiRequestConsumer(); | 69 | + TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> producer = tbCoreQueueFactory.createTransportApiResponseProducer(); |
70 | + TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> consumer = tbCoreQueueFactory.createTransportApiRequestConsumer(); | ||
71 | 71 | ||
72 | DefaultTbQueueResponseTemplate.DefaultTbQueueResponseTemplateBuilder | 72 | DefaultTbQueueResponseTemplate.DefaultTbQueueResponseTemplateBuilder |
73 | <TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> builder = DefaultTbQueueResponseTemplate.builder(); | 73 | <TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> builder = DefaultTbQueueResponseTemplate.builder(); |
@@ -25,7 +25,6 @@ | @@ -25,7 +25,6 @@ | ||
25 | </encoder> | 25 | </encoder> |
26 | </appender> | 26 | </appender> |
27 | 27 | ||
28 | - <logger name="org.springframework.boot.autoconfigure.logging" level="DEBUG" /> | ||
29 | <logger name="org.thingsboard.server" level="INFO" /> | 28 | <logger name="org.thingsboard.server" level="INFO" /> |
30 | <logger name="akka" level="INFO" /> | 29 | <logger name="akka" level="INFO" /> |
31 | <logger name="org.thingsboard.server.service.queue" level="TRACE" /> | 30 | <logger name="org.thingsboard.server.service.queue" level="TRACE" /> |
@@ -550,26 +550,44 @@ queue: | @@ -550,26 +550,44 @@ queue: | ||
550 | response_poll_interval: "${TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS:25}" | 550 | response_poll_interval: "${TB_QUEUE_TRANSPORT_RESPONSE_POLL_INTERVAL_MS:25}" |
551 | core: | 551 | core: |
552 | topic: "${TB_QUEUE_CORE_TOPIC:tb.core}" | 552 | topic: "${TB_QUEUE_CORE_TOPIC:tb.core}" |
553 | - poll_interval: "${TB_QUEUE_CORE_POLL_INTERVAL_MS:25}" | 553 | + poll-interval: "${TB_QUEUE_CORE_POLL_INTERVAL_MS:25}" |
554 | partitions: "${TB_QUEUE_CORE_PARTITIONS:10}" | 554 | partitions: "${TB_QUEUE_CORE_PARTITIONS:10}" |
555 | - pack_processing_timeout: "${TB_QUEUE_CORE_PACK_PROCESSING_TIMEOUT_MS:60000}" | 555 | + pack-processing-timeout: "${TB_QUEUE_CORE_PACK_PROCESSING_TIMEOUT_MS:60000}" |
556 | stats: | 556 | stats: |
557 | enabled: "${TB_QUEUE_CORE_STATS_ENABLED:false}" | 557 | enabled: "${TB_QUEUE_CORE_STATS_ENABLED:false}" |
558 | - print_interval_ms: "${TB_QUEUE_CORE_STATS_PRINT_INTERVAL_MS:10000}" | ||
559 | - rule_engine: | 558 | + print-interval-ms: "${TB_QUEUE_CORE_STATS_PRINT_INTERVAL_MS:10000}" |
559 | + rule-engine: | ||
560 | topic: "${TB_QUEUE_RULE_ENGINE_TOPIC:tb.rule-engine}" | 560 | topic: "${TB_QUEUE_RULE_ENGINE_TOPIC:tb.rule-engine}" |
561 | - poll_interval: "${TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS:25}" | ||
562 | - partitions: "${TB_QUEUE_RULE_ENGINE_PARTITIONS:10}" | ||
563 | - pack_processing_timeout: "${TB_QUEUE_RULE_ENGINE_PACK_PROCESSING_TIMEOUT_MS:60000}" | ||
564 | - strategy: | ||
565 | - type: "${TB_QUEUE_RULE_ENGINE_STRATEGY_TYPE:RETRY_FAILED_AND_TIMED_OUT}" # SKIP_ALL_FAILURES, RETRY_ALL, RETRY_FAILED, RETRY_TIMED_OUT, RETRY_FAILED_AND_TIMED_OUT | ||
566 | - # For RETRY_ALL, RETRY_FAILED, RETRY_TIMED_OUT, RETRY_FAILED_AND_TIMED_OUT | ||
567 | - retries: "${TB_QUEUE_RULE_ENGINE_STRATEGY_RETRIES:3}" # Number of retries, 0 is unlimited | ||
568 | - failure_percentage: "${TB_QUEUE_RULE_ENGINE_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages; | ||
569 | - pause_between_retries: "${TB_QUEUE_RULE_ENGINE_STRATEGY_RETRY_PAUSE:3}"# Time in seconds to wait in consumer thread before retries; | 561 | + poll-interval: "${TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS:25}" |
562 | + pack-processing-timeout: "${TB_QUEUE_RULE_ENGINE_PACK_PROCESSING_TIMEOUT_MS:60000}" | ||
570 | stats: | 563 | stats: |
571 | enabled: "${TB_QUEUE_RULE_ENGINE_STATS_ENABLED:false}" | 564 | enabled: "${TB_QUEUE_RULE_ENGINE_STATS_ENABLED:false}" |
572 | - print_interval_ms: "${TB_QUEUE_RULE_ENGINE_STATS_PRINT_INTERVAL_MS:10000}" | 565 | + print-interval-ms: "${TB_QUEUE_RULE_ENGINE_STATS_PRINT_INTERVAL_MS:10000}" |
566 | + queues: # TODO 2.5: specify correct ENV variable names. | ||
567 | + - | ||
568 | + name: "Main" | ||
569 | + topic: "${TB_QUEUE_RULE_ENGINE_TOPIC:tb.rule-engine.main}" | ||
570 | + poll-interval: "${TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS:25}" | ||
571 | + partitions: "${TB_QUEUE_RULE_ENGINE_PARTITIONS:10}" | ||
572 | + pack-processing-timeout: "${TB_QUEUE_RULE_ENGINE_PACK_PROCESSING_TIMEOUT_MS:60000}" | ||
573 | + ack-strategy: | ||
574 | + type: "${TB_QUEUE_RULE_ENGINE_STRATEGY_TYPE:RETRY_FAILED_AND_TIMED_OUT}" # SKIP_ALL_FAILURES, RETRY_ALL, RETRY_FAILED, RETRY_TIMED_OUT, RETRY_FAILED_AND_TIMED_OUT | ||
575 | + # For RETRY_ALL, RETRY_FAILED, RETRY_TIMED_OUT, RETRY_FAILED_AND_TIMED_OUT | ||
576 | + retries: "${TB_QUEUE_RULE_ENGINE_STRATEGY_RETRIES:3}" # Number of retries, 0 is unlimited | ||
577 | + failure-percentage: "${TB_QUEUE_RULE_ENGINE_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages; | ||
578 | + pause-between-retries: "${TB_QUEUE_RULE_ENGINE_STRATEGY_RETRY_PAUSE:3}"# Time in seconds to wait in consumer thread before retries; | ||
579 | + - | ||
580 | + name: "HighPriority" | ||
581 | + topic: "${TB_QUEUE_RULE_ENGINE_TOPIC:tb.rule-engine.hp}" | ||
582 | + poll-interval: "${TB_QUEUE_RULE_ENGINE_POLL_INTERVAL_MS:25}" | ||
583 | + partitions: "${TB_QUEUE_RULE_ENGINE_PARTITIONS:3}" | ||
584 | + pack-processing-timeout: "${TB_QUEUE_RULE_ENGINE_PACK_PROCESSING_TIMEOUT_MS:60000}" | ||
585 | + ack-strategy: | ||
586 | + type: "${TB_QUEUE_RULE_ENGINE_STRATEGY_TYPE:RETRY_FAILED_AND_TIMED_OUT}" # SKIP_ALL_FAILURES, RETRY_ALL, RETRY_FAILED, RETRY_TIMED_OUT, RETRY_FAILED_AND_TIMED_OUT | ||
587 | + # For RETRY_ALL, RETRY_FAILED, RETRY_TIMED_OUT, RETRY_FAILED_AND_TIMED_OUT | ||
588 | + retries: "${TB_QUEUE_RULE_ENGINE_STRATEGY_RETRIES:0}" # Number of retries, 0 is unlimited | ||
589 | + failure-percentage: "${TB_QUEUE_RULE_ENGINE_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages; | ||
590 | + pause-between-retries: "${TB_QUEUE_RULE_ENGINE_STRATEGY_RETRY_PAUSE:1}"# Time in seconds to wait in consumer thread before retries; | ||
573 | transport: | 591 | transport: |
574 | # For high priority notifications that require minimum latency and processing time | 592 | # For high priority notifications that require minimum latency and processing time |
575 | notifications_topic: "${TB_QUEUE_TRANSPORT_NOTIFICATIONS_TOPIC:tb.transport.notifications}" | 593 | notifications_topic: "${TB_QUEUE_TRANSPORT_NOTIFICATIONS_TOPIC:tb.transport.notifications}" |
@@ -145,11 +145,10 @@ public abstract class AbstractRuleEngineFlowIntegrationTest extends AbstractRule | @@ -145,11 +145,10 @@ public abstract class AbstractRuleEngineFlowIntegrationTest extends AbstractRule | ||
145 | Thread.sleep(1000); | 145 | Thread.sleep(1000); |
146 | 146 | ||
147 | // Pushing Message to the system | 147 | // Pushing Message to the system |
148 | - TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), | 148 | + TbMsg tbMsg = TbMsg.newMsg( |
149 | "CUSTOM", | 149 | "CUSTOM", |
150 | device.getId(), | 150 | device.getId(), |
151 | - new TbMsgMetaData(), TbMsgDataType.JSON, | ||
152 | - "{}", null, null, null); | 151 | + new TbMsgMetaData(), TbMsgDataType.JSON, "{}"); |
153 | //TODO 2.5 | 152 | //TODO 2.5 |
154 | // actorService.onMsg(new SendToClusterMsg(device.getId(), new QueueToRuleEngineMsg(savedTenant.getId(), tbMsg))); | 153 | // actorService.onMsg(new SendToClusterMsg(device.getId(), new QueueToRuleEngineMsg(savedTenant.getId(), tbMsg))); |
155 | 154 | ||
@@ -261,12 +260,12 @@ public abstract class AbstractRuleEngineFlowIntegrationTest extends AbstractRule | @@ -261,12 +260,12 @@ public abstract class AbstractRuleEngineFlowIntegrationTest extends AbstractRule | ||
261 | Thread.sleep(1000); | 260 | Thread.sleep(1000); |
262 | 261 | ||
263 | // Pushing Message to the system | 262 | // Pushing Message to the system |
264 | - TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), | 263 | + TbMsg tbMsg = TbMsg.newMsg( |
265 | "CUSTOM", | 264 | "CUSTOM", |
266 | device.getId(), | 265 | device.getId(), |
267 | new TbMsgMetaData(), | 266 | new TbMsgMetaData(), |
268 | TbMsgDataType.JSON, | 267 | TbMsgDataType.JSON, |
269 | - "{}", null, null, null); | 268 | + "{}"); |
270 | //TODO 2.5 | 269 | //TODO 2.5 |
271 | // actorService.onMsg(new SendToClusterMsg(device.getId(), new QueueToRuleEngineMsg(savedTenant.getId(), tbMsg))); | 270 | // actorService.onMsg(new SendToClusterMsg(device.getId(), new QueueToRuleEngineMsg(savedTenant.getId(), tbMsg))); |
272 | 271 |
@@ -136,13 +136,12 @@ public abstract class AbstractRuleEngineLifecycleIntegrationTest extends Abstrac | @@ -136,13 +136,12 @@ public abstract class AbstractRuleEngineLifecycleIntegrationTest extends Abstrac | ||
136 | Thread.sleep(1000); | 136 | Thread.sleep(1000); |
137 | 137 | ||
138 | // Pushing Message to the system | 138 | // Pushing Message to the system |
139 | - TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), | 139 | + TbMsg tbMsg = TbMsg.newMsg( |
140 | "CUSTOM", | 140 | "CUSTOM", |
141 | device.getId(), | 141 | device.getId(), |
142 | new TbMsgMetaData(), | 142 | new TbMsgMetaData(), |
143 | TbMsgDataType.JSON, | 143 | TbMsgDataType.JSON, |
144 | - "{}", | ||
145 | - null, null, null); | 144 | + "{}"); |
146 | //TODO 2.5 | 145 | //TODO 2.5 |
147 | // actorService.onMsg(new SendToClusterMsg(device.getId(), new QueueToRuleEngineMsg(savedTenant.getId(), tbMsg))); | 146 | // actorService.onMsg(new SendToClusterMsg(device.getId(), new QueueToRuleEngineMsg(savedTenant.getId(), tbMsg))); |
148 | 147 |
@@ -63,7 +63,7 @@ public class RuleNodeJsScriptEngineTest { | @@ -63,7 +63,7 @@ public class RuleNodeJsScriptEngineTest { | ||
63 | metaData.putValue("humidity", "99"); | 63 | metaData.putValue("humidity", "99"); |
64 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; | 64 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; |
65 | 65 | ||
66 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, rawJson, null, null, null); | 66 | + TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, rawJson); |
67 | 67 | ||
68 | TbMsg actual = scriptEngine.executeUpdate(msg); | 68 | TbMsg actual = scriptEngine.executeUpdate(msg); |
69 | assertEquals("70", actual.getMetaData().getValue("temp")); | 69 | assertEquals("70", actual.getMetaData().getValue("temp")); |
@@ -79,7 +79,7 @@ public class RuleNodeJsScriptEngineTest { | @@ -79,7 +79,7 @@ public class RuleNodeJsScriptEngineTest { | ||
79 | metaData.putValue("humidity", "99"); | 79 | metaData.putValue("humidity", "99"); |
80 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; | 80 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; |
81 | 81 | ||
82 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, rawJson, null, null, null); | 82 | + TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, rawJson); |
83 | 83 | ||
84 | TbMsg actual = scriptEngine.executeUpdate(msg); | 84 | TbMsg actual = scriptEngine.executeUpdate(msg); |
85 | assertEquals("94", actual.getMetaData().getValue("newAttr")); | 85 | assertEquals("94", actual.getMetaData().getValue("newAttr")); |
@@ -95,7 +95,7 @@ public class RuleNodeJsScriptEngineTest { | @@ -95,7 +95,7 @@ public class RuleNodeJsScriptEngineTest { | ||
95 | metaData.putValue("humidity", "99"); | 95 | metaData.putValue("humidity", "99"); |
96 | String rawJson = "{\"name\":\"Vit\",\"passed\": 5,\"bigObj\":{\"prop\":42}}"; | 96 | String rawJson = "{\"name\":\"Vit\",\"passed\": 5,\"bigObj\":{\"prop\":42}}"; |
97 | 97 | ||
98 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, rawJson, null, null, null); | 98 | + TbMsg msg =TbMsg.newMsg("USER", null, metaData, TbMsgDataType.JSON, rawJson); |
99 | 99 | ||
100 | TbMsg actual = scriptEngine.executeUpdate(msg); | 100 | TbMsg actual = scriptEngine.executeUpdate(msg); |
101 | 101 | ||
@@ -113,7 +113,7 @@ public class RuleNodeJsScriptEngineTest { | @@ -113,7 +113,7 @@ public class RuleNodeJsScriptEngineTest { | ||
113 | metaData.putValue("humidity", "99"); | 113 | metaData.putValue("humidity", "99"); |
114 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; | 114 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; |
115 | 115 | ||
116 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, rawJson, null, null, null); | 116 | + TbMsg msg = TbMsg.newMsg("USER", null, metaData, TbMsgDataType.JSON, rawJson); |
117 | assertFalse(scriptEngine.executeFilter(msg)); | 117 | assertFalse(scriptEngine.executeFilter(msg)); |
118 | scriptEngine.destroy(); | 118 | scriptEngine.destroy(); |
119 | } | 119 | } |
@@ -127,7 +127,7 @@ public class RuleNodeJsScriptEngineTest { | @@ -127,7 +127,7 @@ public class RuleNodeJsScriptEngineTest { | ||
127 | metaData.putValue("humidity", "99"); | 127 | metaData.putValue("humidity", "99"); |
128 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; | 128 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; |
129 | 129 | ||
130 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData,TbMsgDataType.JSON, rawJson, null, null, null); | 130 | + TbMsg msg = TbMsg.newMsg( "USER", null, metaData,TbMsgDataType.JSON, rawJson); |
131 | assertTrue(scriptEngine.executeFilter(msg)); | 131 | assertTrue(scriptEngine.executeFilter(msg)); |
132 | scriptEngine.destroy(); | 132 | scriptEngine.destroy(); |
133 | } | 133 | } |
@@ -148,7 +148,7 @@ public class RuleNodeJsScriptEngineTest { | @@ -148,7 +148,7 @@ public class RuleNodeJsScriptEngineTest { | ||
148 | metaData.putValue("humidity", "99"); | 148 | metaData.putValue("humidity", "99"); |
149 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; | 149 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; |
150 | 150 | ||
151 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, rawJson, null, null, null); | 151 | + TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, rawJson); |
152 | Set<String> actual = scriptEngine.executeSwitch(msg); | 152 | Set<String> actual = scriptEngine.executeSwitch(msg); |
153 | assertEquals(Sets.newHashSet("one"), actual); | 153 | assertEquals(Sets.newHashSet("one"), actual); |
154 | scriptEngine.destroy(); | 154 | scriptEngine.destroy(); |
@@ -170,7 +170,7 @@ public class RuleNodeJsScriptEngineTest { | @@ -170,7 +170,7 @@ public class RuleNodeJsScriptEngineTest { | ||
170 | metaData.putValue("humidity", "99"); | 170 | metaData.putValue("humidity", "99"); |
171 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; | 171 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5, \"bigObj\": {\"prop\":42}}"; |
172 | 172 | ||
173 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, rawJson, null, null, null); | 173 | + TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, rawJson); |
174 | Set<String> actual = scriptEngine.executeSwitch(msg); | 174 | Set<String> actual = scriptEngine.executeSwitch(msg); |
175 | assertEquals(Sets.newHashSet("one", "three"), actual); | 175 | assertEquals(Sets.newHashSet("one", "three"), actual); |
176 | scriptEngine.destroy(); | 176 | scriptEngine.destroy(); |
@@ -52,13 +52,34 @@ public final class TbMsg implements Serializable { | @@ -52,13 +52,34 @@ public final class TbMsg implements Serializable { | ||
52 | //This field is not serialized because we use queues and there is no need to do it | 52 | //This field is not serialized because we use queues and there is no need to do it |
53 | private final TbMsgCallback callback; | 53 | private final TbMsgCallback callback; |
54 | 54 | ||
55 | - public TbMsg(UUID id, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, | ||
56 | - RuleChainId ruleChainId, RuleNodeId ruleNodeId, TbMsgCallback callback) { | 55 | + public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data) { |
56 | + return new TbMsg(UUID.randomUUID(), type, originator, metaData.copy(), TbMsgDataType.JSON, data, null, null, TbMsgCallback.EMPTY); | ||
57 | + } | ||
58 | + | ||
59 | + public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data, RuleChainId ruleChainId, RuleNodeId ruleNodeId) { | ||
60 | + return new TbMsg(UUID.randomUUID(), type, originator, metaData.copy(), TbMsgDataType.JSON, data, ruleChainId, ruleNodeId, TbMsgCallback.EMPTY); | ||
61 | + } | ||
62 | + | ||
63 | + public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data) { | ||
64 | + return new TbMsg(UUID.randomUUID(), type, originator, metaData.copy(), dataType, data, null, null, TbMsgCallback.EMPTY); | ||
65 | + } | ||
66 | + | ||
67 | + public static TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, RuleChainId ruleChainId, RuleNodeId ruleNodeId) { | ||
68 | + return new TbMsg(UUID.randomUUID(), type, originator, metaData.copy(), dataType, data, ruleChainId, ruleNodeId, TbMsgCallback.EMPTY); | ||
69 | + } | ||
70 | + | ||
71 | + public static TbMsg transformMsg(TbMsg origMsg, String type, EntityId originator, TbMsgMetaData metaData, String data) { | ||
72 | + return new TbMsg(origMsg.getId(), type, originator, metaData.copy(), origMsg.getDataType(), | ||
73 | + data, origMsg.getTransactionData(), origMsg.getRuleChainId(), origMsg.getRuleNodeId(), origMsg.getCallback()); | ||
74 | + } | ||
75 | + | ||
76 | + private TbMsg(UUID id, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, | ||
77 | + RuleChainId ruleChainId, RuleNodeId ruleNodeId, TbMsgCallback callback) { | ||
57 | this(id, type, originator, metaData, dataType, data, new TbMsgTransactionData(id, originator), ruleChainId, ruleNodeId, callback); | 78 | this(id, type, originator, metaData, dataType, data, new TbMsgTransactionData(id, originator), ruleChainId, ruleNodeId, callback); |
58 | } | 79 | } |
59 | 80 | ||
60 | - public TbMsg(UUID id, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, | ||
61 | - TbMsgTransactionData transactionData, RuleChainId ruleChainId, RuleNodeId ruleNodeId, TbMsgCallback callback) { | 81 | + private TbMsg(UUID id, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, |
82 | + TbMsgTransactionData transactionData, RuleChainId ruleChainId, RuleNodeId ruleNodeId, TbMsgCallback callback) { | ||
62 | this.id = id; | 83 | this.id = id; |
63 | this.type = type; | 84 | this.type = type; |
64 | this.originator = originator; | 85 | this.originator = originator; |
@@ -115,7 +136,6 @@ public final class TbMsg implements Serializable { | @@ -115,7 +136,6 @@ public final class TbMsg implements Serializable { | ||
115 | builder.setDataType(msg.getDataType().ordinal()); | 136 | builder.setDataType(msg.getDataType().ordinal()); |
116 | builder.setData(msg.getData()); | 137 | builder.setData(msg.getData()); |
117 | return builder.build().toByteArray(); | 138 | return builder.build().toByteArray(); |
118 | - | ||
119 | } | 139 | } |
120 | 140 | ||
121 | public static TbMsg fromBytes(byte[] data, TbMsgCallback callback) { | 141 | public static TbMsg fromBytes(byte[] data, TbMsgCallback callback) { |
@@ -29,7 +29,7 @@ import java.util.Set; | @@ -29,7 +29,7 @@ import java.util.Set; | ||
29 | public final class PartitionChangeMsg implements TbActorMsg { | 29 | public final class PartitionChangeMsg implements TbActorMsg { |
30 | 30 | ||
31 | @Getter | 31 | @Getter |
32 | - private final ServiceKey serviceKey; | 32 | + private final ServiceQueueKey serviceQueueKey; |
33 | @Getter | 33 | @Getter |
34 | private final Set<TopicPartitionInfo> partitions; | 34 | private final Set<TopicPartitionInfo> partitions; |
35 | 35 |
@@ -22,6 +22,7 @@ import org.thingsboard.server.common.msg.TbActorMsg; | @@ -22,6 +22,7 @@ import org.thingsboard.server.common.msg.TbActorMsg; | ||
22 | import org.thingsboard.server.common.msg.TbMsg; | 22 | import org.thingsboard.server.common.msg.TbMsg; |
23 | 23 | ||
24 | import java.io.Serializable; | 24 | import java.io.Serializable; |
25 | +import java.util.Set; | ||
25 | 26 | ||
26 | /** | 27 | /** |
27 | * Created by ashvayka on 15.03.18. | 28 | * Created by ashvayka on 15.03.18. |
@@ -31,9 +32,14 @@ public final class QueueToRuleEngineMsg implements TbActorMsg { | @@ -31,9 +32,14 @@ public final class QueueToRuleEngineMsg implements TbActorMsg { | ||
31 | 32 | ||
32 | private final TenantId tenantId; | 33 | private final TenantId tenantId; |
33 | private final TbMsg tbMsg; | 34 | private final TbMsg tbMsg; |
35 | + private final Set<String> relationTypes; | ||
34 | 36 | ||
35 | @Override | 37 | @Override |
36 | public MsgType getMsgType() { | 38 | public MsgType getMsgType() { |
37 | return MsgType.QUEUE_TO_RULE_ENGINE_MSG; | 39 | return MsgType.QUEUE_TO_RULE_ENGINE_MSG; |
38 | } | 40 | } |
41 | + | ||
42 | + public boolean isTellNext() { | ||
43 | + return relationTypes != null && !relationTypes.isEmpty(); | ||
44 | + } | ||
39 | } | 45 | } |
1 | +/** | ||
2 | + * Copyright © 2016-2020 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.common.msg.queue; | ||
17 | + | ||
18 | +import lombok.ToString; | ||
19 | + | ||
20 | +import java.util.Objects; | ||
21 | + | ||
22 | +@ToString | ||
23 | +public class ServiceQueue { | ||
24 | + | ||
25 | + public static final String MAIN = "Main"; | ||
26 | + | ||
27 | + private final ServiceType type; | ||
28 | + private final String queue; | ||
29 | + | ||
30 | + public ServiceQueue(ServiceType type) { | ||
31 | + this.type = type; | ||
32 | + this.queue = MAIN; | ||
33 | + } | ||
34 | + | ||
35 | + public ServiceQueue(ServiceType type, String queue) { | ||
36 | + this.type = type; | ||
37 | + this.queue = queue; | ||
38 | + } | ||
39 | + | ||
40 | + public ServiceType getType() { | ||
41 | + return type; | ||
42 | + } | ||
43 | + | ||
44 | + public String getQueue() { | ||
45 | + return queue; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public boolean equals(Object o) { | ||
50 | + if (this == o) return true; | ||
51 | + if (o == null || getClass() != o.getClass()) return false; | ||
52 | + ServiceQueue that = (ServiceQueue) o; | ||
53 | + return type == that.type && | ||
54 | + queue.equals(that.queue); | ||
55 | + } | ||
56 | + | ||
57 | + @Override | ||
58 | + public int hashCode() { | ||
59 | + return Objects.hash(type, queue); | ||
60 | + } | ||
61 | + | ||
62 | +} |
common/message/src/main/java/org/thingsboard/server/common/msg/queue/ServiceQueueKey.java
renamed from
common/message/src/main/java/org/thingsboard/server/common/msg/queue/ServiceKey.java
@@ -22,14 +22,15 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -22,14 +22,15 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
22 | import java.util.Objects; | 22 | import java.util.Objects; |
23 | 23 | ||
24 | @ToString | 24 | @ToString |
25 | -public class ServiceKey { | 25 | +public class ServiceQueueKey { |
26 | @Getter | 26 | @Getter |
27 | - private final ServiceType serviceType; | 27 | + private final ServiceQueue serviceQueue; |
28 | + | ||
28 | @Getter | 29 | @Getter |
29 | private final TenantId tenantId; | 30 | private final TenantId tenantId; |
30 | 31 | ||
31 | - public ServiceKey(ServiceType serviceType, TenantId tenantId) { | ||
32 | - this.serviceType = serviceType; | 32 | + public ServiceQueueKey(ServiceQueue serviceQueue, TenantId tenantId) { |
33 | + this.serviceQueue = serviceQueue; | ||
33 | this.tenantId = tenantId; | 34 | this.tenantId = tenantId; |
34 | } | 35 | } |
35 | 36 | ||
@@ -37,13 +38,17 @@ public class ServiceKey { | @@ -37,13 +38,17 @@ public class ServiceKey { | ||
37 | public boolean equals(Object o) { | 38 | public boolean equals(Object o) { |
38 | if (this == o) return true; | 39 | if (this == o) return true; |
39 | if (o == null || getClass() != o.getClass()) return false; | 40 | if (o == null || getClass() != o.getClass()) return false; |
40 | - ServiceKey that = (ServiceKey) o; | ||
41 | - return serviceType == that.serviceType && | 41 | + ServiceQueueKey that = (ServiceQueueKey) o; |
42 | + return serviceQueue.equals(that.serviceQueue) && | ||
42 | Objects.equals(tenantId, that.tenantId); | 43 | Objects.equals(tenantId, that.tenantId); |
43 | } | 44 | } |
44 | 45 | ||
45 | @Override | 46 | @Override |
46 | public int hashCode() { | 47 | public int hashCode() { |
47 | - return Objects.hash(serviceType, tenantId); | 48 | + return Objects.hash(serviceQueue, tenantId); |
49 | + } | ||
50 | + | ||
51 | + public ServiceType getServiceType() { | ||
52 | + return serviceQueue.getType(); | ||
48 | } | 53 | } |
49 | } | 54 | } |
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | package org.thingsboard.server.common.msg.queue; | 16 | package org.thingsboard.server.common.msg.queue; |
17 | 17 | ||
18 | public enum ServiceType { | 18 | public enum ServiceType { |
19 | + | ||
19 | TB_CORE, TB_RULE_ENGINE, TB_TRANSPORT, JS_EXECUTOR; | 20 | TB_CORE, TB_RULE_ENGINE, TB_TRANSPORT, JS_EXECUTOR; |
20 | 21 | ||
21 | public static ServiceType of(String serviceType) { | 22 | public static ServiceType of(String serviceType) { |
common/queue/src/main/java/org/thingsboard/server/queue/common/MultipleTbQueueTbMsgCallbackWrapper.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/MultipleTbQueueTbMsgCallbackWrapper.java
@@ -13,9 +13,11 @@ | @@ -13,9 +13,11 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.queue; | 16 | +package org.thingsboard.server.queue.common; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.queue.TbMsgCallback; | 18 | import org.thingsboard.server.common.msg.queue.TbMsgCallback; |
19 | +import org.thingsboard.server.queue.TbQueueCallback; | ||
20 | +import org.thingsboard.server.queue.TbQueueMsgMetadata; | ||
19 | 21 | ||
20 | import java.util.concurrent.atomic.AtomicInteger; | 22 | import java.util.concurrent.atomic.AtomicInteger; |
21 | 23 |
common/queue/src/main/java/org/thingsboard/server/queue/common/TbQueueTbMsgCallbackWrapper.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueTbMsgCallbackWrapper.java
@@ -13,9 +13,11 @@ | @@ -13,9 +13,11 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.queue; | 16 | +package org.thingsboard.server.queue.common; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.queue.TbMsgCallback; | 18 | import org.thingsboard.server.common.msg.queue.TbMsgCallback; |
19 | +import org.thingsboard.server.queue.TbQueueCallback; | ||
20 | +import org.thingsboard.server.queue.TbQueueMsgMetadata; | ||
19 | 21 | ||
20 | import java.util.concurrent.atomic.AtomicInteger; | 22 | import java.util.concurrent.atomic.AtomicInteger; |
21 | 23 |
@@ -17,7 +17,7 @@ package org.thingsboard.server.queue.discovery; | @@ -17,7 +17,7 @@ package org.thingsboard.server.queue.discovery; | ||
17 | 17 | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | import org.springframework.context.ApplicationEvent; | 19 | import org.springframework.context.ApplicationEvent; |
20 | -import org.thingsboard.server.common.msg.queue.ServiceKey; | 20 | +import org.thingsboard.server.common.msg.queue.ServiceQueueKey; |
21 | 21 | ||
22 | import java.util.Set; | 22 | import java.util.Set; |
23 | 23 | ||
@@ -25,10 +25,10 @@ import java.util.Set; | @@ -25,10 +25,10 @@ import java.util.Set; | ||
25 | public class ClusterTopologyChangeEvent extends ApplicationEvent { | 25 | public class ClusterTopologyChangeEvent extends ApplicationEvent { |
26 | 26 | ||
27 | @Getter | 27 | @Getter |
28 | - private final Set<ServiceKey> serviceKeys; | 28 | + private final Set<ServiceQueueKey> serviceQueueKeys; |
29 | 29 | ||
30 | - public ClusterTopologyChangeEvent(Object source, Set<ServiceKey> serviceKeys) { | 30 | + public ClusterTopologyChangeEvent(Object source, Set<ServiceQueueKey> serviceQueueKeys) { |
31 | super(source); | 31 | super(source); |
32 | - this.serviceKeys = serviceKeys; | 32 | + this.serviceQueueKeys = serviceQueueKeys; |
33 | } | 33 | } |
34 | } | 34 | } |
@@ -24,7 +24,8 @@ import org.springframework.context.ApplicationEventPublisher; | @@ -24,7 +24,8 @@ import org.springframework.context.ApplicationEventPublisher; | ||
24 | import org.springframework.stereotype.Service; | 24 | import org.springframework.stereotype.Service; |
25 | import org.thingsboard.server.common.data.id.EntityId; | 25 | import org.thingsboard.server.common.data.id.EntityId; |
26 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
27 | -import org.thingsboard.server.common.msg.queue.ServiceKey; | 27 | +import org.thingsboard.server.common.msg.queue.ServiceQueueKey; |
28 | +import org.thingsboard.server.common.msg.queue.ServiceQueue; | ||
28 | import org.thingsboard.server.common.msg.queue.ServiceType; | 29 | import org.thingsboard.server.common.msg.queue.ServiceType; |
29 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 30 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
30 | import org.thingsboard.server.gen.transport.TransportProtos; | 31 | import org.thingsboard.server.gen.transport.TransportProtos; |
@@ -53,10 +54,6 @@ public class ConsistentHashPartitionService implements PartitionService { | @@ -53,10 +54,6 @@ public class ConsistentHashPartitionService implements PartitionService { | ||
53 | private String coreTopic; | 54 | private String coreTopic; |
54 | @Value("${queue.core.partitions:100}") | 55 | @Value("${queue.core.partitions:100}") |
55 | private Integer corePartitions; | 56 | private Integer corePartitions; |
56 | - @Value("${queue.rule_engine.topic}") | ||
57 | - private String ruleEngineTopic; | ||
58 | - @Value("${queue.rule_engine.partitions:100}") | ||
59 | - private Integer ruleEnginePartitions; | ||
60 | @Value("${queue.partitions.hash_function_name:murmur3_128}") | 57 | @Value("${queue.partitions.hash_function_name:murmur3_128}") |
61 | private String hashFunctionName; | 58 | private String hashFunctionName; |
62 | @Value("${queue.partitions.virtual_nodes_size:16}") | 59 | @Value("${queue.partitions.virtual_nodes_size:16}") |
@@ -64,9 +61,9 @@ public class ConsistentHashPartitionService implements PartitionService { | @@ -64,9 +61,9 @@ public class ConsistentHashPartitionService implements PartitionService { | ||
64 | 61 | ||
65 | private final ApplicationEventPublisher applicationEventPublisher; | 62 | private final ApplicationEventPublisher applicationEventPublisher; |
66 | private final TbServiceInfoProvider serviceInfoProvider; | 63 | private final TbServiceInfoProvider serviceInfoProvider; |
67 | - private final ConcurrentMap<ServiceType, String> partitionTopics = new ConcurrentHashMap<>(); | ||
68 | - private final ConcurrentMap<ServiceType, Integer> partitionSizes = new ConcurrentHashMap<>(); | ||
69 | - private ConcurrentMap<ServiceKey, List<Integer>> myPartitions = new ConcurrentHashMap<>(); | 64 | + private final ConcurrentMap<ServiceQueue, String> partitionTopics = new ConcurrentHashMap<>(); |
65 | + private final ConcurrentMap<ServiceQueue, Integer> partitionSizes = new ConcurrentHashMap<>(); | ||
66 | + private ConcurrentMap<ServiceQueueKey, List<Integer>> myPartitions = new ConcurrentHashMap<>(); | ||
70 | //TODO: Fetch this from the database, together with size of partitions for each service for each tenant. | 67 | //TODO: Fetch this from the database, together with size of partitions for each service for each tenant. |
71 | private ConcurrentMap<TenantId, Set<ServiceType>> isolatedTenants = new ConcurrentHashMap<>(); | 68 | private ConcurrentMap<TenantId, Set<ServiceType>> isolatedTenants = new ConcurrentHashMap<>(); |
72 | private ConcurrentMap<TopicPartitionInfoKey, TopicPartitionInfo> tpiCache = new ConcurrentHashMap<>(); | 69 | private ConcurrentMap<TopicPartitionInfoKey, TopicPartitionInfo> tpiCache = new ConcurrentHashMap<>(); |
@@ -85,49 +82,53 @@ public class ConsistentHashPartitionService implements PartitionService { | @@ -85,49 +82,53 @@ public class ConsistentHashPartitionService implements PartitionService { | ||
85 | @PostConstruct | 82 | @PostConstruct |
86 | public void init() { | 83 | public void init() { |
87 | this.hashFunction = forName(hashFunctionName); | 84 | this.hashFunction = forName(hashFunctionName); |
88 | - partitionSizes.put(ServiceType.TB_CORE, corePartitions); | ||
89 | - partitionSizes.put(ServiceType.TB_RULE_ENGINE, ruleEnginePartitions); | ||
90 | - partitionTopics.put(ServiceType.TB_CORE, coreTopic); | ||
91 | - partitionTopics.put(ServiceType.TB_RULE_ENGINE, ruleEngineTopic); | 85 | + partitionSizes.put(new ServiceQueue(ServiceType.TB_CORE), corePartitions); |
86 | + partitionTopics.put(new ServiceQueue(ServiceType.TB_CORE), coreTopic); | ||
92 | } | 87 | } |
93 | 88 | ||
89 | +// public Set<TopicPartitionInfo> getCurrentPartitions(ServiceType serviceType) { | ||
90 | +// ServiceInfo currentService = serviceInfoProvider.getServiceInfo(); | ||
91 | +// TenantId tenantId = getSystemOrIsolatedTenantId(currentService); | ||
92 | +// ServiceQueueKey serviceQueueKey = new ServiceQueueKey(serviceType, tenantId); | ||
93 | +// List<Integer> partitions = myPartitions.get(serviceQueueKey); | ||
94 | +// Set<TopicPartitionInfo> topicPartitions = new LinkedHashSet<>(); | ||
95 | +// for (Integer partition : partitions) { | ||
96 | +// TopicPartitionInfo.TopicPartitionInfoBuilder tpi = TopicPartitionInfo.builder(); | ||
97 | +// tpi.topic(partitionTopics.get(serviceType)); | ||
98 | +// tpi.partition(partition); | ||
99 | +// if (!tenantId.isNullUid()) { | ||
100 | +// tpi.tenantId(tenantId); | ||
101 | +// } | ||
102 | +// topicPartitions.add(tpi.build()); | ||
103 | +// } | ||
104 | +// return topicPartitions; | ||
105 | +// } | ||
106 | + | ||
94 | @Override | 107 | @Override |
95 | - public Set<TopicPartitionInfo> getCurrentPartitions(ServiceType serviceType) { | ||
96 | - ServiceInfo currentService = serviceInfoProvider.getServiceInfo(); | ||
97 | - TenantId tenantId = getSystemOrIsolatedTenantId(currentService); | ||
98 | - ServiceKey serviceKey = new ServiceKey(serviceType, tenantId); | ||
99 | - List<Integer> partitions = myPartitions.get(serviceKey); | ||
100 | - Set<TopicPartitionInfo> topicPartitions = new LinkedHashSet<>(); | ||
101 | - for (Integer partition : partitions) { | ||
102 | - TopicPartitionInfo.TopicPartitionInfoBuilder tpi = TopicPartitionInfo.builder(); | ||
103 | - tpi.topic(partitionTopics.get(serviceType)); | ||
104 | - tpi.partition(partition); | ||
105 | - if (!tenantId.isNullUid()) { | ||
106 | - tpi.tenantId(tenantId); | ||
107 | - } | ||
108 | - topicPartitions.add(tpi.build()); | ||
109 | - } | ||
110 | - return topicPartitions; | 108 | + public TopicPartitionInfo resolve(ServiceType serviceType, TenantId tenantId, EntityId entityId) { |
109 | + return resolve(new ServiceQueue(serviceType), tenantId, entityId); | ||
111 | } | 110 | } |
112 | 111 | ||
113 | - //TODO 2.5 This should return cached TopicPartitionInfo objects instead of creating new one every time. | ||
114 | @Override | 112 | @Override |
115 | - public TopicPartitionInfo resolve(ServiceType serviceType, TenantId tenantId, EntityId entityId) { | 113 | + public TopicPartitionInfo resolve(ServiceType serviceType, String queueName, TenantId tenantId, EntityId entityId) { |
114 | + return resolve(new ServiceQueue(serviceType, queueName), tenantId, entityId); | ||
115 | + } | ||
116 | + | ||
117 | + private TopicPartitionInfo resolve(ServiceQueue serviceQueue, TenantId tenantId, EntityId entityId) { | ||
116 | int hash = hashFunction.newHasher() | 118 | int hash = hashFunction.newHasher() |
117 | .putLong(entityId.getId().getMostSignificantBits()) | 119 | .putLong(entityId.getId().getMostSignificantBits()) |
118 | .putLong(entityId.getId().getLeastSignificantBits()).hash().asInt(); | 120 | .putLong(entityId.getId().getLeastSignificantBits()).hash().asInt(); |
119 | - int partition = Math.abs(hash % partitionSizes.get(serviceType)); | ||
120 | - boolean isolatedTenant = isIsolated(serviceType, tenantId); | ||
121 | - TopicPartitionInfoKey cacheKey = new TopicPartitionInfoKey(serviceType, isolatedTenant ? tenantId : null, partition); | ||
122 | - return tpiCache.computeIfAbsent(cacheKey, key -> buildTopicPartitionInfo(serviceType, tenantId, partition)); | 121 | + int partition = Math.abs(hash % partitionSizes.get(serviceQueue)); |
122 | + boolean isolatedTenant = isIsolated(serviceQueue, tenantId); | ||
123 | + TopicPartitionInfoKey cacheKey = new TopicPartitionInfoKey(serviceQueue, isolatedTenant ? tenantId : null, partition); | ||
124 | + return tpiCache.computeIfAbsent(cacheKey, key -> buildTopicPartitionInfo(serviceQueue, tenantId, partition)); | ||
123 | } | 125 | } |
124 | 126 | ||
125 | @Override | 127 | @Override |
126 | public void recalculatePartitions(ServiceInfo currentService, List<ServiceInfo> otherServices) { | 128 | public void recalculatePartitions(ServiceInfo currentService, List<ServiceInfo> otherServices) { |
127 | logServiceInfo(currentService); | 129 | logServiceInfo(currentService); |
128 | otherServices.forEach(this::logServiceInfo); | 130 | otherServices.forEach(this::logServiceInfo); |
129 | - | ||
130 | - Map<ServiceKey, ConsistentHashCircle<ServiceInfo>> circles = new HashMap<>(); | 131 | + Map<ServiceQueueKey, ConsistentHashCircle<ServiceInfo>> circles = new HashMap<>(); |
131 | addNode(circles, currentService); | 132 | addNode(circles, currentService); |
132 | for (ServiceInfo other : otherServices) { | 133 | for (ServiceInfo other : otherServices) { |
133 | TenantId tenantId = getSystemOrIsolatedTenantId(other); | 134 | TenantId tenantId = getSystemOrIsolatedTenantId(other); |
@@ -140,26 +141,26 @@ public class ConsistentHashPartitionService implements PartitionService { | @@ -140,26 +141,26 @@ public class ConsistentHashPartitionService implements PartitionService { | ||
140 | 141 | ||
141 | } | 142 | } |
142 | } | 143 | } |
143 | - ConcurrentMap<ServiceKey, List<Integer>> oldPartitions = myPartitions; | 144 | + ConcurrentMap<ServiceQueueKey, List<Integer>> oldPartitions = myPartitions; |
144 | TenantId myTenantId = getSystemOrIsolatedTenantId(currentService); | 145 | TenantId myTenantId = getSystemOrIsolatedTenantId(currentService); |
145 | myPartitions = new ConcurrentHashMap<>(); | 146 | myPartitions = new ConcurrentHashMap<>(); |
146 | partitionSizes.forEach((type, size) -> { | 147 | partitionSizes.forEach((type, size) -> { |
147 | - ServiceKey myServiceKey = new ServiceKey(type, myTenantId); | 148 | + ServiceQueueKey myServiceQueueKey = new ServiceQueueKey(type, myTenantId); |
148 | for (int i = 0; i < size; i++) { | 149 | for (int i = 0; i < size; i++) { |
149 | - ServiceInfo serviceInfo = resolveByPartitionIdx(circles.get(myServiceKey), i); | 150 | + ServiceInfo serviceInfo = resolveByPartitionIdx(circles.get(myServiceQueueKey), i); |
150 | if (currentService.equals(serviceInfo)) { | 151 | if (currentService.equals(serviceInfo)) { |
151 | - ServiceKey serviceKey = new ServiceKey(type, getSystemOrIsolatedTenantId(serviceInfo)); | ||
152 | - myPartitions.computeIfAbsent(serviceKey, key -> new ArrayList<>()).add(i); | 152 | + ServiceQueueKey serviceQueueKey = new ServiceQueueKey(type, getSystemOrIsolatedTenantId(serviceInfo)); |
153 | + myPartitions.computeIfAbsent(serviceQueueKey, key -> new ArrayList<>()).add(i); | ||
153 | } | 154 | } |
154 | } | 155 | } |
155 | }); | 156 | }); |
156 | - myPartitions.forEach((serviceKey, partitions) -> { | ||
157 | - if (!partitions.equals(oldPartitions.get(serviceKey))) { | ||
158 | - log.info("[{}] NEW PARTITIONS: {}", serviceKey, partitions); | 157 | + myPartitions.forEach((serviceQueueKey, partitions) -> { |
158 | + if (!partitions.equals(oldPartitions.get(serviceQueueKey))) { | ||
159 | + log.info("[{}] NEW PARTITIONS: {}", serviceQueueKey, partitions); | ||
159 | Set<TopicPartitionInfo> tpiList = partitions.stream() | 160 | Set<TopicPartitionInfo> tpiList = partitions.stream() |
160 | - .map(partition -> buildTopicPartitionInfo(serviceKey, partition)) | 161 | + .map(partition -> buildTopicPartitionInfo(serviceQueueKey, partition)) |
161 | .collect(Collectors.toSet()); | 162 | .collect(Collectors.toSet()); |
162 | - applicationEventPublisher.publishEvent(new PartitionChangeEvent(this, serviceKey, tpiList)); | 163 | + applicationEventPublisher.publishEvent(new PartitionChangeEvent(this, serviceQueueKey, tpiList)); |
163 | } | 164 | } |
164 | }); | 165 | }); |
165 | tpiCache.clear(); | 166 | tpiCache.clear(); |
@@ -167,14 +168,13 @@ public class ConsistentHashPartitionService implements PartitionService { | @@ -167,14 +168,13 @@ public class ConsistentHashPartitionService implements PartitionService { | ||
167 | if (currentOtherServices == null) { | 168 | if (currentOtherServices == null) { |
168 | currentOtherServices = new ArrayList<>(otherServices); | 169 | currentOtherServices = new ArrayList<>(otherServices); |
169 | } else { | 170 | } else { |
170 | - Set<ServiceKey> changes = new HashSet<>(); | ||
171 | - Map<ServiceKey, List<ServiceInfo>> currentMap = getServiceKeyListMap(currentOtherServices); | ||
172 | - Map<ServiceKey, List<ServiceInfo>> newMap = getServiceKeyListMap(otherServices); | 171 | + Set<ServiceQueueKey> changes = new HashSet<>(); |
172 | + Map<ServiceQueueKey, List<ServiceInfo>> currentMap = getServiceKeyListMap(currentOtherServices); | ||
173 | + Map<ServiceQueueKey, List<ServiceInfo>> newMap = getServiceKeyListMap(otherServices); | ||
173 | currentOtherServices = otherServices; | 174 | currentOtherServices = otherServices; |
174 | currentMap.forEach((key, list) -> { | 175 | currentMap.forEach((key, list) -> { |
175 | if (!list.equals(newMap.get(key))) { | 176 | if (!list.equals(newMap.get(key))) { |
176 | changes.add(key); | 177 | changes.add(key); |
177 | - | ||
178 | } | 178 | } |
179 | }); | 179 | }); |
180 | currentMap.keySet().forEach(newMap::remove); | 180 | currentMap.keySet().forEach(newMap::remove); |
@@ -214,13 +214,20 @@ public class ConsistentHashPartitionService implements PartitionService { | @@ -214,13 +214,20 @@ public class ConsistentHashPartitionService implements PartitionService { | ||
214 | } | 214 | } |
215 | } | 215 | } |
216 | 216 | ||
217 | - private Map<ServiceKey, List<ServiceInfo>> getServiceKeyListMap(List<ServiceInfo> services) { | ||
218 | - final Map<ServiceKey, List<ServiceInfo>> currentMap = new HashMap<>(); | 217 | + private Map<ServiceQueueKey, List<ServiceInfo>> getServiceKeyListMap(List<ServiceInfo> services) { |
218 | + final Map<ServiceQueueKey, List<ServiceInfo>> currentMap = new HashMap<>(); | ||
219 | services.forEach(serviceInfo -> { | 219 | services.forEach(serviceInfo -> { |
220 | for (String serviceTypeStr : serviceInfo.getServiceTypesList()) { | 220 | for (String serviceTypeStr : serviceInfo.getServiceTypesList()) { |
221 | ServiceType serviceType = ServiceType.valueOf(serviceTypeStr.toUpperCase()); | 221 | ServiceType serviceType = ServiceType.valueOf(serviceTypeStr.toUpperCase()); |
222 | - ServiceKey serviceKey = new ServiceKey(serviceType, getSystemOrIsolatedTenantId(serviceInfo)); | ||
223 | - currentMap.computeIfAbsent(serviceKey, key -> new ArrayList<>()).add(serviceInfo); | 222 | + if (ServiceType.TB_RULE_ENGINE.equals(serviceType)) { |
223 | + for (TransportProtos.QueueInfo queue : serviceInfo.getRuleEngineQueuesList()) { | ||
224 | + ServiceQueueKey serviceQueueKey = new ServiceQueueKey(new ServiceQueue(serviceType, queue.getName()), getSystemOrIsolatedTenantId(serviceInfo)); | ||
225 | + currentMap.computeIfAbsent(serviceQueueKey, key -> new ArrayList<>()).add(serviceInfo); | ||
226 | + } | ||
227 | + } else { | ||
228 | + ServiceQueueKey serviceQueueKey = new ServiceQueueKey(new ServiceQueue(serviceType), getSystemOrIsolatedTenantId(serviceInfo)); | ||
229 | + currentMap.computeIfAbsent(serviceQueueKey, key -> new ArrayList<>()).add(serviceInfo); | ||
230 | + } | ||
224 | } | 231 | } |
225 | }); | 232 | }); |
226 | return currentMap; | 233 | return currentMap; |
@@ -230,20 +237,20 @@ public class ConsistentHashPartitionService implements PartitionService { | @@ -230,20 +237,20 @@ public class ConsistentHashPartitionService implements PartitionService { | ||
230 | return new TopicPartitionInfo(serviceType.name().toLowerCase() + ".notifications." + serviceId, null, null, false); | 237 | return new TopicPartitionInfo(serviceType.name().toLowerCase() + ".notifications." + serviceId, null, null, false); |
231 | } | 238 | } |
232 | 239 | ||
233 | - private TopicPartitionInfo buildTopicPartitionInfo(ServiceKey serviceKey, int partition) { | ||
234 | - return buildTopicPartitionInfo(serviceKey.getServiceType(), serviceKey.getTenantId(), partition); | 240 | + private TopicPartitionInfo buildTopicPartitionInfo(ServiceQueueKey serviceQueueKey, int partition) { |
241 | + return buildTopicPartitionInfo(serviceQueueKey.getServiceQueue(), serviceQueueKey.getTenantId(), partition); | ||
235 | } | 242 | } |
236 | 243 | ||
237 | - private TopicPartitionInfo buildTopicPartitionInfo(ServiceType serviceType, TenantId tenantId, int partition) { | 244 | + private TopicPartitionInfo buildTopicPartitionInfo(ServiceQueue serviceQueue, TenantId tenantId, int partition) { |
238 | TopicPartitionInfo.TopicPartitionInfoBuilder tpi = TopicPartitionInfo.builder(); | 245 | TopicPartitionInfo.TopicPartitionInfoBuilder tpi = TopicPartitionInfo.builder(); |
239 | - tpi.topic(partitionTopics.get(serviceType)); | 246 | + tpi.topic(partitionTopics.get(serviceQueue)); |
240 | tpi.partition(partition); | 247 | tpi.partition(partition); |
241 | - ServiceKey myPartitionsSearchKey; | ||
242 | - if (isIsolated(serviceType, tenantId)) { | 248 | + ServiceQueueKey myPartitionsSearchKey; |
249 | + if (isIsolated(serviceQueue, tenantId)) { | ||
243 | tpi.tenantId(tenantId); | 250 | tpi.tenantId(tenantId); |
244 | - myPartitionsSearchKey = new ServiceKey(serviceType, tenantId); | 251 | + myPartitionsSearchKey = new ServiceQueueKey(serviceQueue, tenantId); |
245 | } else { | 252 | } else { |
246 | - myPartitionsSearchKey = new ServiceKey(serviceType, new TenantId(TenantId.NULL_UUID)); | 253 | + myPartitionsSearchKey = new ServiceQueueKey(serviceQueue, new TenantId(TenantId.NULL_UUID)); |
247 | } | 254 | } |
248 | List<Integer> partitions = myPartitions.get(myPartitionsSearchKey); | 255 | List<Integer> partitions = myPartitions.get(myPartitionsSearchKey); |
249 | if (partitions != null) { | 256 | if (partitions != null) { |
@@ -254,8 +261,8 @@ public class ConsistentHashPartitionService implements PartitionService { | @@ -254,8 +261,8 @@ public class ConsistentHashPartitionService implements PartitionService { | ||
254 | return tpi.build(); | 261 | return tpi.build(); |
255 | } | 262 | } |
256 | 263 | ||
257 | - private boolean isIsolated(ServiceType serviceType, TenantId tenantId) { | ||
258 | - return isolatedTenants.get(tenantId) != null && isolatedTenants.get(tenantId).contains(serviceType); | 264 | + private boolean isIsolated(ServiceQueue serviceQueue, TenantId tenantId) { |
265 | + return isolatedTenants.get(tenantId) != null && isolatedTenants.get(tenantId).contains(serviceQueue.getType()); | ||
259 | } | 266 | } |
260 | 267 | ||
261 | private void logServiceInfo(TransportProtos.ServiceInfo server) { | 268 | private void logServiceInfo(TransportProtos.ServiceInfo server) { |
@@ -271,13 +278,24 @@ public class ConsistentHashPartitionService implements PartitionService { | @@ -271,13 +278,24 @@ public class ConsistentHashPartitionService implements PartitionService { | ||
271 | return new TenantId(new UUID(serviceInfo.getTenantIdMSB(), serviceInfo.getTenantIdLSB())); | 278 | return new TenantId(new UUID(serviceInfo.getTenantIdMSB(), serviceInfo.getTenantIdLSB())); |
272 | } | 279 | } |
273 | 280 | ||
274 | - private void addNode(Map<ServiceKey, ConsistentHashCircle<ServiceInfo>> circles, ServiceInfo instance) { | 281 | + private void addNode(Map<ServiceQueueKey, ConsistentHashCircle<ServiceInfo>> circles, ServiceInfo instance) { |
275 | TenantId tenantId = getSystemOrIsolatedTenantId(instance); | 282 | TenantId tenantId = getSystemOrIsolatedTenantId(instance); |
276 | for (String serviceTypeStr : instance.getServiceTypesList()) { | 283 | for (String serviceTypeStr : instance.getServiceTypesList()) { |
277 | ServiceType serviceType = ServiceType.valueOf(serviceTypeStr.toUpperCase()); | 284 | ServiceType serviceType = ServiceType.valueOf(serviceTypeStr.toUpperCase()); |
278 | - ServiceKey serviceKey = new ServiceKey(serviceType, tenantId); | ||
279 | - for (int i = 0; i < virtualNodesSize; i++) { | ||
280 | - circles.computeIfAbsent(serviceKey, key -> new ConsistentHashCircle<>()).put(hash(instance, i).asLong(), instance); | 285 | + if (ServiceType.TB_RULE_ENGINE.equals(serviceType)) { |
286 | + for (TransportProtos.QueueInfo queue : instance.getRuleEngineQueuesList()) { | ||
287 | + ServiceQueueKey serviceQueueKey = new ServiceQueueKey(new ServiceQueue(serviceType, queue.getName()), tenantId); | ||
288 | + partitionSizes.put(new ServiceQueue(ServiceType.TB_RULE_ENGINE, queue.getName()), queue.getPartitions()); | ||
289 | + partitionTopics.put(new ServiceQueue(ServiceType.TB_RULE_ENGINE, queue.getName()), queue.getTopic()); | ||
290 | + for (int i = 0; i < virtualNodesSize; i++) { | ||
291 | + circles.computeIfAbsent(serviceQueueKey, key -> new ConsistentHashCircle<>()).put(hash(instance, i).asLong(), instance); | ||
292 | + } | ||
293 | + } | ||
294 | + } else { | ||
295 | + ServiceQueueKey serviceQueueKey = new ServiceQueueKey(new ServiceQueue(serviceType), tenantId); | ||
296 | + for (int i = 0; i < virtualNodesSize; i++) { | ||
297 | + circles.computeIfAbsent(serviceQueueKey, key -> new ConsistentHashCircle<>()).put(hash(instance, i).asLong(), instance); | ||
298 | + } | ||
281 | } | 299 | } |
282 | } | 300 | } |
283 | } | 301 | } |
@@ -17,12 +17,16 @@ package org.thingsboard.server.queue.discovery; | @@ -17,12 +17,16 @@ package org.thingsboard.server.queue.discovery; | ||
17 | 17 | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | +import org.springframework.beans.factory.annotation.Autowired; | ||
20 | import org.springframework.beans.factory.annotation.Value; | 21 | import org.springframework.beans.factory.annotation.Value; |
21 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
22 | import org.springframework.util.StringUtils; | 23 | import org.springframework.util.StringUtils; |
23 | import org.thingsboard.server.common.data.id.TenantId; | 24 | import org.thingsboard.server.common.data.id.TenantId; |
24 | import org.thingsboard.server.common.msg.queue.ServiceType; | 25 | import org.thingsboard.server.common.msg.queue.ServiceType; |
26 | +import org.thingsboard.server.gen.transport.TransportProtos; | ||
25 | import org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo; |
28 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; | ||
29 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
26 | 30 | ||
27 | import javax.annotation.PostConstruct; | 31 | import javax.annotation.PostConstruct; |
28 | import java.net.InetAddress; | 32 | import java.net.InetAddress; |
@@ -49,6 +53,9 @@ public class DefaultTbServiceInfoProvider implements TbServiceInfoProvider { | @@ -49,6 +53,9 @@ public class DefaultTbServiceInfoProvider implements TbServiceInfoProvider { | ||
49 | @Value("${service.tenant_id:}") | 53 | @Value("${service.tenant_id:}") |
50 | private String tenantIdStr; | 54 | private String tenantIdStr; |
51 | 55 | ||
56 | + @Autowired(required = false) | ||
57 | + private TbQueueRuleEngineSettings ruleEngineSettings; | ||
58 | + | ||
52 | private List<ServiceType> serviceTypes; | 59 | private List<ServiceType> serviceTypes; |
53 | private ServiceInfo serviceInfo; | 60 | private ServiceInfo serviceInfo; |
54 | 61 | ||
@@ -78,13 +85,18 @@ public class DefaultTbServiceInfoProvider implements TbServiceInfoProvider { | @@ -78,13 +85,18 @@ public class DefaultTbServiceInfoProvider implements TbServiceInfoProvider { | ||
78 | } | 85 | } |
79 | builder.setTenantIdMSB(tenantId.getMostSignificantBits()); | 86 | builder.setTenantIdMSB(tenantId.getMostSignificantBits()); |
80 | builder.setTenantIdLSB(tenantId.getLeastSignificantBits()); | 87 | builder.setTenantIdLSB(tenantId.getLeastSignificantBits()); |
81 | - serviceInfo = builder.build(); | ||
82 | - } | ||
83 | 88 | ||
89 | + if (serviceTypes.contains(ServiceType.TB_RULE_ENGINE) && ruleEngineSettings != null) { | ||
90 | + for (TbRuleEngineQueueConfiguration queue : ruleEngineSettings.getQueues()) { | ||
91 | + TransportProtos.QueueInfo queueInfo = TransportProtos.QueueInfo.newBuilder() | ||
92 | + .setName(queue.getName()) | ||
93 | + .setTopic(queue.getTopic()) | ||
94 | + .setPartitions(queue.getPartitions()).build(); | ||
95 | + builder.addRuleEngineQueues(queueInfo); | ||
96 | + } | ||
97 | + } | ||
84 | 98 | ||
85 | - @Override | ||
86 | - public List<ServiceType> getSupportedServiceTypes() { | ||
87 | - return serviceTypes; | 99 | + serviceInfo = builder.build(); |
88 | } | 100 | } |
89 | 101 | ||
90 | @Override | 102 | @Override |
@@ -17,7 +17,8 @@ package org.thingsboard.server.queue.discovery; | @@ -17,7 +17,8 @@ package org.thingsboard.server.queue.discovery; | ||
17 | 17 | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | import org.springframework.context.ApplicationEvent; | 19 | import org.springframework.context.ApplicationEvent; |
20 | -import org.thingsboard.server.common.msg.queue.ServiceKey; | 20 | +import org.thingsboard.server.common.msg.queue.ServiceQueueKey; |
21 | +import org.thingsboard.server.common.msg.queue.ServiceType; | ||
21 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 22 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
22 | 23 | ||
23 | import java.util.Set; | 24 | import java.util.Set; |
@@ -26,13 +27,17 @@ import java.util.Set; | @@ -26,13 +27,17 @@ import java.util.Set; | ||
26 | public class PartitionChangeEvent extends ApplicationEvent { | 27 | public class PartitionChangeEvent extends ApplicationEvent { |
27 | 28 | ||
28 | @Getter | 29 | @Getter |
29 | - private final ServiceKey serviceKey; | 30 | + private final ServiceQueueKey serviceQueueKey; |
30 | @Getter | 31 | @Getter |
31 | private final Set<TopicPartitionInfo> partitions; | 32 | private final Set<TopicPartitionInfo> partitions; |
32 | 33 | ||
33 | - public PartitionChangeEvent(Object source, ServiceKey serviceKey, Set<TopicPartitionInfo> partitions) { | 34 | + public PartitionChangeEvent(Object source, ServiceQueueKey serviceQueueKey, Set<TopicPartitionInfo> partitions) { |
34 | super(source); | 35 | super(source); |
35 | - this.serviceKey = serviceKey; | 36 | + this.serviceQueueKey = serviceQueueKey; |
36 | this.partitions = partitions; | 37 | this.partitions = partitions; |
37 | } | 38 | } |
39 | + | ||
40 | + public ServiceType getServiceType() { | ||
41 | + return serviceQueueKey.getServiceQueue().getType(); | ||
42 | + } | ||
38 | } | 43 | } |
@@ -29,10 +29,10 @@ import java.util.Set; | @@ -29,10 +29,10 @@ import java.util.Set; | ||
29 | */ | 29 | */ |
30 | public interface PartitionService { | 30 | public interface PartitionService { |
31 | 31 | ||
32 | - Set<TopicPartitionInfo> getCurrentPartitions(ServiceType serviceType); | ||
33 | - | ||
34 | TopicPartitionInfo resolve(ServiceType serviceType, TenantId tenantId, EntityId entityId); | 32 | TopicPartitionInfo resolve(ServiceType serviceType, TenantId tenantId, EntityId entityId); |
35 | 33 | ||
34 | + TopicPartitionInfo resolve(ServiceType serviceType, String queueName, TenantId tenantId, EntityId entityId); | ||
35 | + | ||
36 | /** | 36 | /** |
37 | * Received from the Discovery service when network topology is changed. | 37 | * Received from the Discovery service when network topology is changed. |
38 | * @param currentService - current service information {@link org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo} | 38 | * @param currentService - current service information {@link org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo} |
@@ -15,15 +15,10 @@ | @@ -15,15 +15,10 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.queue.discovery; | 16 | package org.thingsboard.server.queue.discovery; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.queue.ServiceType; | ||
19 | import org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo; | 18 | import org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo; |
20 | 19 | ||
21 | -import java.util.List; | ||
22 | - | ||
23 | public interface TbServiceInfoProvider { | 20 | public interface TbServiceInfoProvider { |
24 | 21 | ||
25 | - List<ServiceType> getSupportedServiceTypes(); | ||
26 | - | ||
27 | String getServiceId(); | 22 | String getServiceId(); |
28 | 23 | ||
29 | ServiceInfo getServiceInfo(); | 24 | ServiceInfo getServiceInfo(); |
@@ -17,13 +17,13 @@ package org.thingsboard.server.queue.discovery; | @@ -17,13 +17,13 @@ package org.thingsboard.server.queue.discovery; | ||
17 | 17 | ||
18 | import lombok.AllArgsConstructor; | 18 | import lombok.AllArgsConstructor; |
19 | import org.thingsboard.server.common.data.id.TenantId; | 19 | import org.thingsboard.server.common.data.id.TenantId; |
20 | -import org.thingsboard.server.common.msg.queue.ServiceType; | 20 | +import org.thingsboard.server.common.msg.queue.ServiceQueue; |
21 | 21 | ||
22 | import java.util.Objects; | 22 | import java.util.Objects; |
23 | 23 | ||
24 | @AllArgsConstructor | 24 | @AllArgsConstructor |
25 | public class TopicPartitionInfoKey { | 25 | public class TopicPartitionInfoKey { |
26 | - private ServiceType serviceType; | 26 | + private ServiceQueue serviceQueue; |
27 | private TenantId isolatedTenantId; | 27 | private TenantId isolatedTenantId; |
28 | private int partition; | 28 | private int partition; |
29 | 29 | ||
@@ -33,12 +33,12 @@ public class TopicPartitionInfoKey { | @@ -33,12 +33,12 @@ public class TopicPartitionInfoKey { | ||
33 | if (o == null || getClass() != o.getClass()) return false; | 33 | if (o == null || getClass() != o.getClass()) return false; |
34 | TopicPartitionInfoKey that = (TopicPartitionInfoKey) o; | 34 | TopicPartitionInfoKey that = (TopicPartitionInfoKey) o; |
35 | return partition == that.partition && | 35 | return partition == that.partition && |
36 | - serviceType == that.serviceType && | 36 | + serviceQueue.equals(that.serviceQueue) && |
37 | Objects.equals(isolatedTenantId, that.isolatedTenantId); | 37 | Objects.equals(isolatedTenantId, that.isolatedTenantId); |
38 | } | 38 | } |
39 | 39 | ||
40 | @Override | 40 | @Override |
41 | public int hashCode() { | 41 | public int hashCode() { |
42 | - return Objects.hash(serviceType, isolatedTenantId, partition); | 42 | + return Objects.hash(serviceQueue, isolatedTenantId, partition); |
43 | } | 43 | } |
44 | } | 44 | } |
common/queue/src/main/java/org/thingsboard/server/queue/provider/AwsSqsMonolithQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/AwsSqsMonolithQueueProvider.java
@@ -21,14 +21,15 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | @@ -21,14 +21,15 @@ import org.thingsboard.server.common.msg.queue.ServiceType; | ||
21 | import org.thingsboard.server.gen.transport.TransportProtos; | 21 | import org.thingsboard.server.gen.transport.TransportProtos; |
22 | import org.thingsboard.server.queue.TbQueueAdmin; | 22 | import org.thingsboard.server.queue.TbQueueAdmin; |
23 | import org.thingsboard.server.queue.TbQueueConsumer; | 23 | import org.thingsboard.server.queue.TbQueueConsumer; |
24 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 24 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
25 | import org.thingsboard.server.queue.TbQueueProducer; | 25 | import org.thingsboard.server.queue.TbQueueProducer; |
26 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | ||
27 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | ||
28 | -import org.thingsboard.server.queue.TbQueueTransportNotificationSettings; | 26 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
27 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; | ||
28 | +import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings; | ||
29 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 29 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
30 | import org.thingsboard.server.queue.discovery.PartitionService; | 30 | import org.thingsboard.server.queue.discovery.PartitionService; |
31 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 31 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
32 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
32 | import org.thingsboard.server.queue.sqs.TbAwsSqsAdmin; | 33 | import org.thingsboard.server.queue.sqs.TbAwsSqsAdmin; |
33 | import org.thingsboard.server.queue.sqs.TbAwsSqsConsumerTemplate; | 34 | import org.thingsboard.server.queue.sqs.TbAwsSqsConsumerTemplate; |
34 | import org.thingsboard.server.queue.sqs.TbAwsSqsProducerTemplate; | 35 | import org.thingsboard.server.queue.sqs.TbAwsSqsProducerTemplate; |
@@ -36,7 +37,7 @@ import org.thingsboard.server.queue.sqs.TbAwsSqsSettings; | @@ -36,7 +37,7 @@ import org.thingsboard.server.queue.sqs.TbAwsSqsSettings; | ||
36 | 37 | ||
37 | @Component | 38 | @Component |
38 | @ConditionalOnExpression("'${queue.type:null}'=='aws-sqs' && '${service.type:null}'=='monolith'") | 39 | @ConditionalOnExpression("'${queue.type:null}'=='aws-sqs' && '${service.type:null}'=='monolith'") |
39 | -public class AwsSqsMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEngineQueueProvider { | 40 | +public class AwsSqsMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEngineQueueFactory { |
40 | 41 | ||
41 | private final PartitionService partitionService; | 42 | private final PartitionService partitionService; |
42 | private final TbQueueCoreSettings coreSettings; | 43 | private final TbQueueCoreSettings coreSettings; |
@@ -47,12 +48,12 @@ public class AwsSqsMonolithQueueProvider implements TbCoreQueueProvider, TbRuleE | @@ -47,12 +48,12 @@ public class AwsSqsMonolithQueueProvider implements TbCoreQueueProvider, TbRuleE | ||
47 | private final TbAwsSqsSettings sqsSettings; | 48 | private final TbAwsSqsSettings sqsSettings; |
48 | private final TbQueueAdmin admin; | 49 | private final TbQueueAdmin admin; |
49 | 50 | ||
50 | - public AwsSqsMonolithQueueProvider(PartitionService partitionService, TbQueueCoreSettings coreSettings, | ||
51 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
52 | - TbServiceInfoProvider serviceInfoProvider, | ||
53 | - TbQueueTransportApiSettings transportApiSettings, | ||
54 | - TbQueueTransportNotificationSettings transportNotificationSettings, | ||
55 | - TbAwsSqsSettings sqsSettings) { | 51 | + public AwsSqsMonolithQueueFactory(PartitionService partitionService, TbQueueCoreSettings coreSettings, |
52 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
53 | + TbServiceInfoProvider serviceInfoProvider, | ||
54 | + TbQueueTransportApiSettings transportApiSettings, | ||
55 | + TbQueueTransportNotificationSettings transportNotificationSettings, | ||
56 | + TbAwsSqsSettings sqsSettings) { | ||
56 | this.partitionService = partitionService; | 57 | this.partitionService = partitionService; |
57 | this.coreSettings = coreSettings; | 58 | this.coreSettings = coreSettings; |
58 | this.serviceInfoProvider = serviceInfoProvider; | 59 | this.serviceInfoProvider = serviceInfoProvider; |
@@ -64,64 +65,64 @@ public class AwsSqsMonolithQueueProvider implements TbCoreQueueProvider, TbRuleE | @@ -64,64 +65,64 @@ public class AwsSqsMonolithQueueProvider implements TbCoreQueueProvider, TbRuleE | ||
64 | } | 65 | } |
65 | 66 | ||
66 | @Override | 67 | @Override |
67 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> getTransportNotificationsMsgProducer() { | 68 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> createTransportNotificationsMsgProducer() { |
68 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportNotificationSettings.getNotificationsTopic()); | 69 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportNotificationSettings.getNotificationsTopic()); |
69 | } | 70 | } |
70 | 71 | ||
71 | @Override | 72 | @Override |
72 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 73 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
73 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic()); | 74 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic()); |
74 | } | 75 | } |
75 | 76 | ||
76 | @Override | 77 | @Override |
77 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 78 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
78 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic()); | 79 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic()); |
79 | } | 80 | } |
80 | 81 | ||
81 | @Override | 82 | @Override |
82 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> getTbCoreMsgProducer() { | 83 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> createTbCoreMsgProducer() { |
83 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 84 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
84 | } | 85 | } |
85 | 86 | ||
86 | @Override | 87 | @Override |
87 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 88 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
88 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 89 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
89 | } | 90 | } |
90 | 91 | ||
91 | @Override | 92 | @Override |
92 | - public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> getToRuleEngineMsgConsumer() { | 93 | + public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) { |
93 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic(), | 94 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic(), |
94 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); | 95 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); |
95 | } | 96 | } |
96 | 97 | ||
97 | @Override | 98 | @Override |
98 | - public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> getToRuleEngineNotificationsMsgConsumer() { | 99 | + public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() { |
99 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, | 100 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, |
100 | partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(), | 101 | partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(), |
101 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); | 102 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); |
102 | } | 103 | } |
103 | 104 | ||
104 | @Override | 105 | @Override |
105 | - public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> getToCoreMsgConsumer() { | 106 | + public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> createToCoreMsgConsumer() { |
106 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, coreSettings.getTopic(), | 107 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, coreSettings.getTopic(), |
107 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders())); | 108 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders())); |
108 | } | 109 | } |
109 | 110 | ||
110 | @Override | 111 | @Override |
111 | - public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> getToCoreNotificationsMsgConsumer() { | 112 | + public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() { |
112 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, | 113 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, |
113 | partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(), | 114 | partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(), |
114 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); | 115 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); |
115 | } | 116 | } |
116 | 117 | ||
117 | @Override | 118 | @Override |
118 | - public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg>> getTransportApiRequestConsumer() { | 119 | + public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg>> createTransportApiRequestConsumer() { |
119 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic(), | 120 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic(), |
120 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders())); | 121 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders())); |
121 | } | 122 | } |
122 | 123 | ||
123 | @Override | 124 | @Override |
124 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.TransportApiResponseMsg>> getTransportApiResponseProducer() { | 125 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.TransportApiResponseMsg>> createTransportApiResponseProducer() { |
125 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportApiSettings.getResponsesTopic()); | 126 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportApiSettings.getResponsesTopic()); |
126 | } | 127 | } |
127 | } | 128 | } |
common/queue/src/main/java/org/thingsboard/server/queue/provider/AwsSqsTbCoreQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/AwsSqsTbCoreQueueProvider.java
@@ -26,10 +26,10 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | @@ -26,10 +26,10 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | ||
26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
27 | import org.thingsboard.server.queue.TbQueueAdmin; | 27 | import org.thingsboard.server.queue.TbQueueAdmin; |
28 | import org.thingsboard.server.queue.TbQueueConsumer; | 28 | import org.thingsboard.server.queue.TbQueueConsumer; |
29 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 29 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
30 | import org.thingsboard.server.queue.TbQueueProducer; | 30 | import org.thingsboard.server.queue.TbQueueProducer; |
31 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | ||
32 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | 31 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
32 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; | ||
33 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 33 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
34 | import org.thingsboard.server.queue.discovery.PartitionService; | 34 | import org.thingsboard.server.queue.discovery.PartitionService; |
35 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 35 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
@@ -40,7 +40,7 @@ import org.thingsboard.server.queue.sqs.TbAwsSqsSettings; | @@ -40,7 +40,7 @@ import org.thingsboard.server.queue.sqs.TbAwsSqsSettings; | ||
40 | 40 | ||
41 | @Component | 41 | @Component |
42 | @ConditionalOnExpression("'${queue.type:null}'=='aws-sqs' && '${service.type:null}'=='tb-core'") | 42 | @ConditionalOnExpression("'${queue.type:null}'=='aws-sqs' && '${service.type:null}'=='tb-core'") |
43 | -public class AwsSqsTbCoreQueueProvider implements TbCoreQueueProvider { | 43 | +public class AwsSqsTbCoreQueueFactory implements TbCoreQueueFactory { |
44 | 44 | ||
45 | private final TbAwsSqsSettings sqsSettings; | 45 | private final TbAwsSqsSettings sqsSettings; |
46 | private final TbQueueRuleEngineSettings ruleEngineSettings; | 46 | private final TbQueueRuleEngineSettings ruleEngineSettings; |
@@ -52,12 +52,12 @@ public class AwsSqsTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -52,12 +52,12 @@ public class AwsSqsTbCoreQueueProvider implements TbCoreQueueProvider { | ||
52 | 52 | ||
53 | private final TbQueueAdmin admin; | 53 | private final TbQueueAdmin admin; |
54 | 54 | ||
55 | - public AwsSqsTbCoreQueueProvider(TbAwsSqsSettings sqsSettings, | ||
56 | - TbQueueCoreSettings coreSettings, | ||
57 | - TbQueueTransportApiSettings transportApiSettings, | ||
58 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
59 | - PartitionService partitionService, | ||
60 | - TbServiceInfoProvider serviceInfoProvider) { | 55 | + public AwsSqsTbCoreQueueFactory(TbAwsSqsSettings sqsSettings, |
56 | + TbQueueCoreSettings coreSettings, | ||
57 | + TbQueueTransportApiSettings transportApiSettings, | ||
58 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
59 | + PartitionService partitionService, | ||
60 | + TbServiceInfoProvider serviceInfoProvider) { | ||
61 | this.sqsSettings = sqsSettings; | 61 | this.sqsSettings = sqsSettings; |
62 | this.coreSettings = coreSettings; | 62 | this.coreSettings = coreSettings; |
63 | this.transportApiSettings = transportApiSettings; | 63 | this.transportApiSettings = transportApiSettings; |
@@ -68,50 +68,50 @@ public class AwsSqsTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -68,50 +68,50 @@ public class AwsSqsTbCoreQueueProvider implements TbCoreQueueProvider { | ||
68 | } | 68 | } |
69 | 69 | ||
70 | @Override | 70 | @Override |
71 | - public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer() { | 71 | + public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() { |
72 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 72 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
73 | } | 73 | } |
74 | 74 | ||
75 | @Override | 75 | @Override |
76 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 76 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
77 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 77 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
78 | } | 78 | } |
79 | 79 | ||
80 | @Override | 80 | @Override |
81 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 81 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
82 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic()); | 82 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic()); |
83 | } | 83 | } |
84 | 84 | ||
85 | @Override | 85 | @Override |
86 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 86 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
87 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 87 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
88 | } | 88 | } |
89 | 89 | ||
90 | @Override | 90 | @Override |
91 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 91 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
92 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 92 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
93 | } | 93 | } |
94 | 94 | ||
95 | @Override | 95 | @Override |
96 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> getToCoreMsgConsumer() { | 96 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() { |
97 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, coreSettings.getTopic(), | 97 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, coreSettings.getTopic(), |
98 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders())); | 98 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders())); |
99 | } | 99 | } |
100 | 100 | ||
101 | @Override | 101 | @Override |
102 | - public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> getToCoreNotificationsMsgConsumer() { | 102 | + public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() { |
103 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, | 103 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, |
104 | partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(), | 104 | partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(), |
105 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); | 105 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); |
106 | } | 106 | } |
107 | 107 | ||
108 | @Override | 108 | @Override |
109 | - public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> getTransportApiRequestConsumer() { | 109 | + public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> createTransportApiRequestConsumer() { |
110 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic(), msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders())); | 110 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic(), msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders())); |
111 | } | 111 | } |
112 | 112 | ||
113 | @Override | 113 | @Override |
114 | - public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiResponseProducer() { | 114 | + public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiResponseProducer() { |
115 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 115 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
116 | } | 116 | } |
117 | } | 117 | } |
common/queue/src/main/java/org/thingsboard/server/queue/provider/AwsSqsTbRuleEngineQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/AwsSqsTbRuleEngineQueueProvider.java
@@ -24,12 +24,13 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | @@ -24,12 +24,13 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | ||
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
25 | import org.thingsboard.server.queue.TbQueueAdmin; | 25 | import org.thingsboard.server.queue.TbQueueAdmin; |
26 | import org.thingsboard.server.queue.TbQueueConsumer; | 26 | import org.thingsboard.server.queue.TbQueueConsumer; |
27 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 27 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
28 | import org.thingsboard.server.queue.TbQueueProducer; | 28 | import org.thingsboard.server.queue.TbQueueProducer; |
29 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | 29 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
30 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 30 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
31 | import org.thingsboard.server.queue.discovery.PartitionService; | 31 | import org.thingsboard.server.queue.discovery.PartitionService; |
32 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 32 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
33 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
33 | import org.thingsboard.server.queue.sqs.TbAwsSqsAdmin; | 34 | import org.thingsboard.server.queue.sqs.TbAwsSqsAdmin; |
34 | import org.thingsboard.server.queue.sqs.TbAwsSqsConsumerTemplate; | 35 | import org.thingsboard.server.queue.sqs.TbAwsSqsConsumerTemplate; |
35 | import org.thingsboard.server.queue.sqs.TbAwsSqsProducerTemplate; | 36 | import org.thingsboard.server.queue.sqs.TbAwsSqsProducerTemplate; |
@@ -37,7 +38,7 @@ import org.thingsboard.server.queue.sqs.TbAwsSqsSettings; | @@ -37,7 +38,7 @@ import org.thingsboard.server.queue.sqs.TbAwsSqsSettings; | ||
37 | 38 | ||
38 | @Component | 39 | @Component |
39 | @ConditionalOnExpression("'${queue.type:null}'=='aws-sqs' && '${service.type:null}'=='tb-rule-engine'") | 40 | @ConditionalOnExpression("'${queue.type:null}'=='aws-sqs' && '${service.type:null}'=='tb-rule-engine'") |
40 | -public class AwsSqsTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider { | 41 | +public class AwsSqsTbRuleEngineQueueFactory implements TbRuleEngineQueueFactory { |
41 | 42 | ||
42 | private final PartitionService partitionService; | 43 | private final PartitionService partitionService; |
43 | private final TbQueueCoreSettings coreSettings; | 44 | private final TbQueueCoreSettings coreSettings; |
@@ -46,10 +47,10 @@ public class AwsSqsTbRuleEngineQueueProvider implements TbRuleEngineQueueProvide | @@ -46,10 +47,10 @@ public class AwsSqsTbRuleEngineQueueProvider implements TbRuleEngineQueueProvide | ||
46 | private final TbAwsSqsSettings sqsSettings; | 47 | private final TbAwsSqsSettings sqsSettings; |
47 | private final TbQueueAdmin admin; | 48 | private final TbQueueAdmin admin; |
48 | 49 | ||
49 | - public AwsSqsTbRuleEngineQueueProvider(PartitionService partitionService, TbQueueCoreSettings coreSettings, | ||
50 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
51 | - TbServiceInfoProvider serviceInfoProvider, | ||
52 | - TbAwsSqsSettings sqsSettings) { | 50 | + public AwsSqsTbRuleEngineQueueFactory(PartitionService partitionService, TbQueueCoreSettings coreSettings, |
51 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
52 | + TbServiceInfoProvider serviceInfoProvider, | ||
53 | + TbAwsSqsSettings sqsSettings) { | ||
53 | this.partitionService = partitionService; | 54 | this.partitionService = partitionService; |
54 | this.coreSettings = coreSettings; | 55 | this.coreSettings = coreSettings; |
55 | this.serviceInfoProvider = serviceInfoProvider; | 56 | this.serviceInfoProvider = serviceInfoProvider; |
@@ -59,37 +60,37 @@ public class AwsSqsTbRuleEngineQueueProvider implements TbRuleEngineQueueProvide | @@ -59,37 +60,37 @@ public class AwsSqsTbRuleEngineQueueProvider implements TbRuleEngineQueueProvide | ||
59 | } | 60 | } |
60 | 61 | ||
61 | @Override | 62 | @Override |
62 | - public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer() { | 63 | + public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() { |
63 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 64 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
64 | } | 65 | } |
65 | 66 | ||
66 | @Override | 67 | @Override |
67 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 68 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
68 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 69 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
69 | } | 70 | } |
70 | 71 | ||
71 | @Override | 72 | @Override |
72 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 73 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
73 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic()); | 74 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic()); |
74 | } | 75 | } |
75 | 76 | ||
76 | @Override | 77 | @Override |
77 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 78 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
78 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 79 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
79 | } | 80 | } |
80 | 81 | ||
81 | @Override | 82 | @Override |
82 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 83 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
83 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); | 84 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, coreSettings.getTopic()); |
84 | } | 85 | } |
85 | 86 | ||
86 | @Override | 87 | @Override |
87 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> getToRuleEngineMsgConsumer() { | 88 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) { |
88 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic(), msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); | 89 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, ruleEngineSettings.getTopic(), msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); |
89 | } | 90 | } |
90 | 91 | ||
91 | @Override | 92 | @Override |
92 | - public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> getToRuleEngineNotificationsMsgConsumer() { | 93 | + public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() { |
93 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, | 94 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, |
94 | partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(), | 95 | partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(), |
95 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); | 96 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); |
common/queue/src/main/java/org/thingsboard/server/queue/provider/AwsSqsTransportQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/AwsSqsTransportQueueProvider.java
@@ -23,8 +23,8 @@ import org.thingsboard.server.queue.TbQueueAdmin; | @@ -23,8 +23,8 @@ import org.thingsboard.server.queue.TbQueueAdmin; | ||
23 | import org.thingsboard.server.queue.TbQueueConsumer; | 23 | import org.thingsboard.server.queue.TbQueueConsumer; |
24 | import org.thingsboard.server.queue.TbQueueProducer; | 24 | import org.thingsboard.server.queue.TbQueueProducer; |
25 | import org.thingsboard.server.queue.TbQueueRequestTemplate; | 25 | import org.thingsboard.server.queue.TbQueueRequestTemplate; |
26 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | ||
27 | -import org.thingsboard.server.queue.TbQueueTransportNotificationSettings; | 26 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; |
27 | +import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings; | ||
28 | import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate; | 28 | import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate; |
29 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 29 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
30 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 30 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
@@ -36,17 +36,17 @@ import org.thingsboard.server.queue.sqs.TbAwsSqsSettings; | @@ -36,17 +36,17 @@ import org.thingsboard.server.queue.sqs.TbAwsSqsSettings; | ||
36 | @Component | 36 | @Component |
37 | @ConditionalOnExpression("'${queue.type:null}'=='aws-sqs' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')") | 37 | @ConditionalOnExpression("'${queue.type:null}'=='aws-sqs' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')") |
38 | @Slf4j | 38 | @Slf4j |
39 | -public class AwsSqsTransportQueueProvider implements TbTransportQueueProvider { | 39 | +public class AwsSqsTransportQueueFactory implements TbTransportQueueFactory { |
40 | private final TbQueueTransportApiSettings transportApiSettings; | 40 | private final TbQueueTransportApiSettings transportApiSettings; |
41 | private final TbQueueTransportNotificationSettings transportNotificationSettings; | 41 | private final TbQueueTransportNotificationSettings transportNotificationSettings; |
42 | private final TbAwsSqsSettings sqsSettings; | 42 | private final TbAwsSqsSettings sqsSettings; |
43 | private final TbQueueAdmin admin; | 43 | private final TbQueueAdmin admin; |
44 | private final TbServiceInfoProvider serviceInfoProvider; | 44 | private final TbServiceInfoProvider serviceInfoProvider; |
45 | 45 | ||
46 | - public AwsSqsTransportQueueProvider(TbQueueTransportApiSettings transportApiSettings, | ||
47 | - TbQueueTransportNotificationSettings transportNotificationSettings, | ||
48 | - TbAwsSqsSettings sqsSettings, | ||
49 | - TbServiceInfoProvider serviceInfoProvider) { | 46 | + public AwsSqsTransportQueueFactory(TbQueueTransportApiSettings transportApiSettings, |
47 | + TbQueueTransportNotificationSettings transportNotificationSettings, | ||
48 | + TbAwsSqsSettings sqsSettings, | ||
49 | + TbServiceInfoProvider serviceInfoProvider) { | ||
50 | this.transportApiSettings = transportApiSettings; | 50 | this.transportApiSettings = transportApiSettings; |
51 | this.transportNotificationSettings = transportNotificationSettings; | 51 | this.transportNotificationSettings = transportNotificationSettings; |
52 | this.sqsSettings = sqsSettings; | 52 | this.sqsSettings = sqsSettings; |
@@ -55,7 +55,7 @@ public class AwsSqsTransportQueueProvider implements TbTransportQueueProvider { | @@ -55,7 +55,7 @@ public class AwsSqsTransportQueueProvider implements TbTransportQueueProvider { | ||
55 | } | 55 | } |
56 | 56 | ||
57 | @Override | 57 | @Override |
58 | - public TbQueueRequestTemplate<TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg>, TbProtoQueueMsg<TransportProtos.TransportApiResponseMsg>> getTransportApiRequestTemplate() { | 58 | + public TbQueueRequestTemplate<TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg>, TbProtoQueueMsg<TransportProtos.TransportApiResponseMsg>> createTransportApiRequestTemplate() { |
59 | TbAwsSqsProducerTemplate<TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg>> producerTemplate = | 59 | TbAwsSqsProducerTemplate<TbProtoQueueMsg<TransportProtos.TransportApiRequestMsg>> producerTemplate = |
60 | new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic()); | 60 | new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic()); |
61 | 61 | ||
@@ -76,17 +76,17 @@ public class AwsSqsTransportQueueProvider implements TbTransportQueueProvider { | @@ -76,17 +76,17 @@ public class AwsSqsTransportQueueProvider implements TbTransportQueueProvider { | ||
76 | } | 76 | } |
77 | 77 | ||
78 | @Override | 78 | @Override |
79 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 79 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
80 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic()); | 80 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic()); |
81 | } | 81 | } |
82 | 82 | ||
83 | @Override | 83 | @Override |
84 | - public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> getTbCoreMsgProducer() { | 84 | + public TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> createTbCoreMsgProducer() { |
85 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic()); | 85 | return new TbAwsSqsProducerTemplate<>(admin, sqsSettings, transportApiSettings.getRequestsTopic()); |
86 | } | 86 | } |
87 | 87 | ||
88 | @Override | 88 | @Override |
89 | - public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> getTransportNotificationsConsumer() { | 89 | + public TbQueueConsumer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> createTransportNotificationsConsumer() { |
90 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, transportNotificationSettings.getNotificationsTopic() + "_" + serviceInfoProvider.getServiceId(), | 90 | return new TbAwsSqsConsumerTemplate<>(admin, sqsSettings, transportNotificationSettings.getNotificationsTopic() + "_" + serviceInfoProvider.getServiceId(), |
91 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToTransportMsg.parseFrom(msg.getData()), msg.getHeaders())); | 91 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportProtos.ToTransportMsg.parseFrom(msg.getData()), msg.getHeaders())); |
92 | } | 92 | } |
common/queue/src/main/java/org/thingsboard/server/queue/provider/InMemoryMonolithQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/InMemoryMonolithQueueProvider.java
@@ -26,29 +26,30 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | @@ -26,29 +26,30 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | ||
26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; | 26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; |
27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
28 | import org.thingsboard.server.queue.TbQueueConsumer; | 28 | import org.thingsboard.server.queue.TbQueueConsumer; |
29 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 29 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
30 | import org.thingsboard.server.queue.TbQueueProducer; | 30 | import org.thingsboard.server.queue.TbQueueProducer; |
31 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | ||
32 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | ||
33 | -import org.thingsboard.server.queue.TbQueueTransportNotificationSettings; | 31 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
32 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; | ||
33 | +import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings; | ||
34 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 34 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
35 | import org.thingsboard.server.queue.memory.InMemoryTbQueueConsumer; | 35 | import org.thingsboard.server.queue.memory.InMemoryTbQueueConsumer; |
36 | import org.thingsboard.server.queue.memory.InMemoryTbQueueProducer; | 36 | import org.thingsboard.server.queue.memory.InMemoryTbQueueProducer; |
37 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
37 | 38 | ||
38 | @Slf4j | 39 | @Slf4j |
39 | @Component | 40 | @Component |
40 | @ConditionalOnExpression("'${queue.type:null}'=='in-memory' && '${service.type:null}'=='monolith'") | 41 | @ConditionalOnExpression("'${queue.type:null}'=='in-memory' && '${service.type:null}'=='monolith'") |
41 | -public class InMemoryMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEngineQueueProvider { | 42 | +public class InMemoryMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEngineQueueFactory { |
42 | 43 | ||
43 | private final TbQueueCoreSettings coreSettings; | 44 | private final TbQueueCoreSettings coreSettings; |
44 | private final TbQueueRuleEngineSettings ruleEngineSettings; | 45 | private final TbQueueRuleEngineSettings ruleEngineSettings; |
45 | private final TbQueueTransportApiSettings transportApiSettings; | 46 | private final TbQueueTransportApiSettings transportApiSettings; |
46 | private final TbQueueTransportNotificationSettings notificationSettings; | 47 | private final TbQueueTransportNotificationSettings notificationSettings; |
47 | 48 | ||
48 | - public InMemoryMonolithQueueProvider(TbQueueCoreSettings coreSettings, | ||
49 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
50 | - TbQueueTransportApiSettings transportApiSettings, | ||
51 | - TbQueueTransportNotificationSettings notificationSettings) { | 49 | + public InMemoryMonolithQueueFactory(TbQueueCoreSettings coreSettings, |
50 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
51 | + TbQueueTransportApiSettings transportApiSettings, | ||
52 | + TbQueueTransportNotificationSettings notificationSettings) { | ||
52 | this.coreSettings = coreSettings; | 53 | this.coreSettings = coreSettings; |
53 | this.ruleEngineSettings = ruleEngineSettings; | 54 | this.ruleEngineSettings = ruleEngineSettings; |
54 | this.transportApiSettings = transportApiSettings; | 55 | this.transportApiSettings = transportApiSettings; |
@@ -56,57 +57,57 @@ public class InMemoryMonolithQueueProvider implements TbCoreQueueProvider, TbRul | @@ -56,57 +57,57 @@ public class InMemoryMonolithQueueProvider implements TbCoreQueueProvider, TbRul | ||
56 | } | 57 | } |
57 | 58 | ||
58 | @Override | 59 | @Override |
59 | - public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer() { | 60 | + public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() { |
60 | return new InMemoryTbQueueProducer<>(notificationSettings.getNotificationsTopic()); | 61 | return new InMemoryTbQueueProducer<>(notificationSettings.getNotificationsTopic()); |
61 | } | 62 | } |
62 | 63 | ||
63 | @Override | 64 | @Override |
64 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 65 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
65 | return new InMemoryTbQueueProducer<>(ruleEngineSettings.getTopic()); | 66 | return new InMemoryTbQueueProducer<>(ruleEngineSettings.getTopic()); |
66 | } | 67 | } |
67 | 68 | ||
68 | @Override | 69 | @Override |
69 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 70 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
70 | return new InMemoryTbQueueProducer<>(coreSettings.getTopic()); | 71 | return new InMemoryTbQueueProducer<>(coreSettings.getTopic()); |
71 | } | 72 | } |
72 | 73 | ||
73 | @Override | 74 | @Override |
74 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> getToRuleEngineMsgConsumer() { | 75 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) { |
75 | return new InMemoryTbQueueConsumer<>(ruleEngineSettings.getTopic()); | 76 | return new InMemoryTbQueueConsumer<>(ruleEngineSettings.getTopic()); |
76 | } | 77 | } |
77 | 78 | ||
78 | @Override | 79 | @Override |
79 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> getToCoreMsgConsumer() { | 80 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() { |
80 | return new InMemoryTbQueueConsumer<>(coreSettings.getTopic()); | 81 | return new InMemoryTbQueueConsumer<>(coreSettings.getTopic()); |
81 | } | 82 | } |
82 | 83 | ||
83 | @Override | 84 | @Override |
84 | - public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> getTransportApiRequestConsumer() { | 85 | + public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> createTransportApiRequestConsumer() { |
85 | return new InMemoryTbQueueConsumer<>(transportApiSettings.getRequestsTopic()); | 86 | return new InMemoryTbQueueConsumer<>(transportApiSettings.getRequestsTopic()); |
86 | } | 87 | } |
87 | 88 | ||
88 | @Override | 89 | @Override |
89 | - public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiResponseProducer() { | 90 | + public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiResponseProducer() { |
90 | return new InMemoryTbQueueProducer<>(transportApiSettings.getResponsesTopic()); | 91 | return new InMemoryTbQueueProducer<>(transportApiSettings.getResponsesTopic()); |
91 | } | 92 | } |
92 | 93 | ||
93 | @Override | 94 | @Override |
94 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 95 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
95 | return new InMemoryTbQueueProducer<>(ruleEngineSettings.getTopic() + ".notifications"); | 96 | return new InMemoryTbQueueProducer<>(ruleEngineSettings.getTopic() + ".notifications"); |
96 | } | 97 | } |
97 | 98 | ||
98 | @Override | 99 | @Override |
99 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 100 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
100 | return new InMemoryTbQueueProducer<>(coreSettings.getTopic() + ".notifications"); | 101 | return new InMemoryTbQueueProducer<>(coreSettings.getTopic() + ".notifications"); |
101 | } | 102 | } |
102 | 103 | ||
103 | @Override | 104 | @Override |
104 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> getToCoreNotificationsMsgConsumer() { | 105 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() { |
105 | return new InMemoryTbQueueConsumer<>(coreSettings.getTopic() + ".notifications"); | 106 | return new InMemoryTbQueueConsumer<>(coreSettings.getTopic() + ".notifications"); |
106 | } | 107 | } |
107 | 108 | ||
108 | @Override | 109 | @Override |
109 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getToRuleEngineNotificationsMsgConsumer() { | 110 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() { |
110 | return new InMemoryTbQueueConsumer<>(ruleEngineSettings.getTopic() + ".notifications"); | 111 | return new InMemoryTbQueueConsumer<>(ruleEngineSettings.getTopic() + ".notifications"); |
111 | } | 112 | } |
112 | } | 113 | } |
common/queue/src/main/java/org/thingsboard/server/queue/provider/InMemoryTbTransportQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/InMemoryTbTransportQueueProvider.java
@@ -20,12 +20,12 @@ import lombok.extern.slf4j.Slf4j; | @@ -20,12 +20,12 @@ import lombok.extern.slf4j.Slf4j; | ||
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | 20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
21 | import org.springframework.stereotype.Component; | 21 | import org.springframework.stereotype.Component; |
22 | import org.thingsboard.server.queue.TbQueueConsumer; | 22 | import org.thingsboard.server.queue.TbQueueConsumer; |
23 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 23 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
24 | import org.thingsboard.server.queue.TbQueueProducer; | 24 | import org.thingsboard.server.queue.TbQueueProducer; |
25 | import org.thingsboard.server.queue.TbQueueRequestTemplate; | 25 | import org.thingsboard.server.queue.TbQueueRequestTemplate; |
26 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | ||
27 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | ||
28 | -import org.thingsboard.server.queue.TbQueueTransportNotificationSettings; | 26 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
27 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; | ||
28 | +import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings; | ||
29 | import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate; | 29 | import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate; |
30 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 30 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
31 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 31 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
@@ -39,17 +39,17 @@ import org.thingsboard.server.queue.memory.InMemoryTbQueueProducer; | @@ -39,17 +39,17 @@ import org.thingsboard.server.queue.memory.InMemoryTbQueueProducer; | ||
39 | @Component | 39 | @Component |
40 | @ConditionalOnExpression("'${queue.type:null}'=='in-memory' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')") | 40 | @ConditionalOnExpression("'${queue.type:null}'=='in-memory' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')") |
41 | @Slf4j | 41 | @Slf4j |
42 | -public class InMemoryTbTransportQueueProvider implements TbTransportQueueProvider { | 42 | +public class InMemoryTbTransportQueueFactory implements TbTransportQueueFactory { |
43 | 43 | ||
44 | private final TbQueueCoreSettings coreSettings; | 44 | private final TbQueueCoreSettings coreSettings; |
45 | private final TbQueueRuleEngineSettings ruleEngineSettings; | 45 | private final TbQueueRuleEngineSettings ruleEngineSettings; |
46 | private final TbQueueTransportApiSettings transportApiSettings; | 46 | private final TbQueueTransportApiSettings transportApiSettings; |
47 | private final TbQueueTransportNotificationSettings notificationSettings; | 47 | private final TbQueueTransportNotificationSettings notificationSettings; |
48 | 48 | ||
49 | - public InMemoryTbTransportQueueProvider(TbQueueCoreSettings coreSettings, | ||
50 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
51 | - TbQueueTransportApiSettings transportApiSettings, | ||
52 | - TbQueueTransportNotificationSettings notificationSettings) { | 49 | + public InMemoryTbTransportQueueFactory(TbQueueCoreSettings coreSettings, |
50 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
51 | + TbQueueTransportApiSettings transportApiSettings, | ||
52 | + TbQueueTransportNotificationSettings notificationSettings) { | ||
53 | this.coreSettings = coreSettings; | 53 | this.coreSettings = coreSettings; |
54 | this.ruleEngineSettings = ruleEngineSettings; | 54 | this.ruleEngineSettings = ruleEngineSettings; |
55 | this.transportApiSettings = transportApiSettings; | 55 | this.transportApiSettings = transportApiSettings; |
@@ -57,7 +57,7 @@ public class InMemoryTbTransportQueueProvider implements TbTransportQueueProvide | @@ -57,7 +57,7 @@ public class InMemoryTbTransportQueueProvider implements TbTransportQueueProvide | ||
57 | } | 57 | } |
58 | 58 | ||
59 | @Override | 59 | @Override |
60 | - public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiRequestTemplate() { | 60 | + public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiRequestTemplate() { |
61 | InMemoryTbQueueProducer<TbProtoQueueMsg<TransportApiRequestMsg>> producer = new InMemoryTbQueueProducer<>(transportApiSettings.getRequestsTopic()); | 61 | InMemoryTbQueueProducer<TbProtoQueueMsg<TransportApiRequestMsg>> producer = new InMemoryTbQueueProducer<>(transportApiSettings.getRequestsTopic()); |
62 | InMemoryTbQueueConsumer<TbProtoQueueMsg<TransportApiResponseMsg>> consumer = new InMemoryTbQueueConsumer<>(transportApiSettings.getResponsesTopic()); | 62 | InMemoryTbQueueConsumer<TbProtoQueueMsg<TransportApiResponseMsg>> consumer = new InMemoryTbQueueConsumer<>(transportApiSettings.getResponsesTopic()); |
63 | 63 | ||
@@ -73,17 +73,17 @@ public class InMemoryTbTransportQueueProvider implements TbTransportQueueProvide | @@ -73,17 +73,17 @@ public class InMemoryTbTransportQueueProvider implements TbTransportQueueProvide | ||
73 | } | 73 | } |
74 | 74 | ||
75 | @Override | 75 | @Override |
76 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 76 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
77 | return new InMemoryTbQueueProducer<>(ruleEngineSettings.getTopic()); | 77 | return new InMemoryTbQueueProducer<>(ruleEngineSettings.getTopic()); |
78 | } | 78 | } |
79 | 79 | ||
80 | @Override | 80 | @Override |
81 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 81 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
82 | return new InMemoryTbQueueProducer<>(coreSettings.getTopic()); | 82 | return new InMemoryTbQueueProducer<>(coreSettings.getTopic()); |
83 | } | 83 | } |
84 | 84 | ||
85 | @Override | 85 | @Override |
86 | - public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsConsumer() { | 86 | + public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsConsumer() { |
87 | return new InMemoryTbQueueConsumer<>(notificationSettings.getNotificationsTopic()); | 87 | return new InMemoryTbQueueConsumer<>(notificationSettings.getNotificationsTopic()); |
88 | } | 88 | } |
89 | } | 89 | } |
common/queue/src/main/java/org/thingsboard/server/queue/provider/KafkaMonolithQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/KafkaMonolithQueueProvider.java
@@ -26,21 +26,22 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | @@ -26,21 +26,22 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | ||
26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; | 26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; |
27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
28 | import org.thingsboard.server.queue.TbQueueConsumer; | 28 | import org.thingsboard.server.queue.TbQueueConsumer; |
29 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 29 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
30 | import org.thingsboard.server.queue.TbQueueProducer; | 30 | import org.thingsboard.server.queue.TbQueueProducer; |
31 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | ||
32 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | ||
33 | -import org.thingsboard.server.queue.TbQueueTransportNotificationSettings; | 31 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
32 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; | ||
33 | +import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings; | ||
34 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 34 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
35 | import org.thingsboard.server.queue.discovery.PartitionService; | 35 | import org.thingsboard.server.queue.discovery.PartitionService; |
36 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 36 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
37 | import org.thingsboard.server.queue.kafka.TBKafkaConsumerTemplate; | 37 | import org.thingsboard.server.queue.kafka.TBKafkaConsumerTemplate; |
38 | import org.thingsboard.server.queue.kafka.TBKafkaProducerTemplate; | 38 | import org.thingsboard.server.queue.kafka.TBKafkaProducerTemplate; |
39 | import org.thingsboard.server.queue.kafka.TbKafkaSettings; | 39 | import org.thingsboard.server.queue.kafka.TbKafkaSettings; |
40 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
40 | 41 | ||
41 | @Component | 42 | @Component |
42 | @ConditionalOnExpression("'${queue.type:null}'=='kafka' && '${service.type:null}'=='monolith'") | 43 | @ConditionalOnExpression("'${queue.type:null}'=='kafka' && '${service.type:null}'=='monolith'") |
43 | -public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEngineQueueProvider { | 44 | +public class KafkaMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEngineQueueFactory { |
44 | 45 | ||
45 | private final PartitionService partitionService; | 46 | private final PartitionService partitionService; |
46 | private final TbKafkaSettings kafkaSettings; | 47 | private final TbKafkaSettings kafkaSettings; |
@@ -50,12 +51,12 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -50,12 +51,12 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
50 | private final TbQueueTransportApiSettings transportApiSettings; | 51 | private final TbQueueTransportApiSettings transportApiSettings; |
51 | private final TbQueueTransportNotificationSettings transportNotificationSettings; | 52 | private final TbQueueTransportNotificationSettings transportNotificationSettings; |
52 | 53 | ||
53 | - public KafkaMonolithQueueProvider(PartitionService partitionService, TbKafkaSettings kafkaSettings, | ||
54 | - TbServiceInfoProvider serviceInfoProvider, | ||
55 | - TbQueueCoreSettings coreSettings, | ||
56 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
57 | - TbQueueTransportApiSettings transportApiSettings, | ||
58 | - TbQueueTransportNotificationSettings transportNotificationSettings) { | 54 | + public KafkaMonolithQueueFactory(PartitionService partitionService, TbKafkaSettings kafkaSettings, |
55 | + TbServiceInfoProvider serviceInfoProvider, | ||
56 | + TbQueueCoreSettings coreSettings, | ||
57 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
58 | + TbQueueTransportApiSettings transportApiSettings, | ||
59 | + TbQueueTransportNotificationSettings transportNotificationSettings) { | ||
59 | this.partitionService = partitionService; | 60 | this.partitionService = partitionService; |
60 | this.kafkaSettings = kafkaSettings; | 61 | this.kafkaSettings = kafkaSettings; |
61 | this.serviceInfoProvider = serviceInfoProvider; | 62 | this.serviceInfoProvider = serviceInfoProvider; |
@@ -66,7 +67,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -66,7 +67,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
66 | } | 67 | } |
67 | 68 | ||
68 | @Override | 69 | @Override |
69 | - public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer() { | 70 | + public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() { |
70 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToTransportMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 71 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToTransportMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
71 | requestBuilder.settings(kafkaSettings); | 72 | requestBuilder.settings(kafkaSettings); |
72 | requestBuilder.clientId("monolith-transport-notifications-" + serviceInfoProvider.getServiceId()); | 73 | requestBuilder.clientId("monolith-transport-notifications-" + serviceInfoProvider.getServiceId()); |
@@ -75,7 +76,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -75,7 +76,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
75 | } | 76 | } |
76 | 77 | ||
77 | @Override | 78 | @Override |
78 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 79 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
79 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 80 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
80 | requestBuilder.settings(kafkaSettings); | 81 | requestBuilder.settings(kafkaSettings); |
81 | requestBuilder.clientId("monolith-rule-engine-" + serviceInfoProvider.getServiceId()); | 82 | requestBuilder.clientId("monolith-rule-engine-" + serviceInfoProvider.getServiceId()); |
@@ -84,7 +85,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -84,7 +85,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
84 | } | 85 | } |
85 | 86 | ||
86 | @Override | 87 | @Override |
87 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 88 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
88 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 89 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
89 | requestBuilder.settings(kafkaSettings); | 90 | requestBuilder.settings(kafkaSettings); |
90 | requestBuilder.clientId("monolith-rule-engine-notifications-" + serviceInfoProvider.getServiceId()); | 91 | requestBuilder.clientId("monolith-rule-engine-notifications-" + serviceInfoProvider.getServiceId()); |
@@ -93,7 +94,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -93,7 +94,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
93 | } | 94 | } |
94 | 95 | ||
95 | @Override | 96 | @Override |
96 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 97 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
97 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 98 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
98 | requestBuilder.settings(kafkaSettings); | 99 | requestBuilder.settings(kafkaSettings); |
99 | requestBuilder.clientId("monolith-core-" + serviceInfoProvider.getServiceId()); | 100 | requestBuilder.clientId("monolith-core-" + serviceInfoProvider.getServiceId()); |
@@ -102,7 +103,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -102,7 +103,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
102 | } | 103 | } |
103 | 104 | ||
104 | @Override | 105 | @Override |
105 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 106 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
106 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 107 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
107 | requestBuilder.settings(kafkaSettings); | 108 | requestBuilder.settings(kafkaSettings); |
108 | requestBuilder.clientId("monolith-core-notifications-" + serviceInfoProvider.getServiceId()); | 109 | requestBuilder.clientId("monolith-core-notifications-" + serviceInfoProvider.getServiceId()); |
@@ -111,18 +112,19 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -111,18 +112,19 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
111 | } | 112 | } |
112 | 113 | ||
113 | @Override | 114 | @Override |
114 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> getToRuleEngineMsgConsumer() { | 115 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) { |
116 | + String queueName = configuration.getName(); | ||
115 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 117 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
116 | consumerBuilder.settings(kafkaSettings); | 118 | consumerBuilder.settings(kafkaSettings); |
117 | consumerBuilder.topic(ruleEngineSettings.getTopic()); | 119 | consumerBuilder.topic(ruleEngineSettings.getTopic()); |
118 | - consumerBuilder.clientId("monolith-rule-engine-consumer-" + serviceInfoProvider.getServiceId()); | ||
119 | - consumerBuilder.groupId("monolith-rule-engine-consumer-" + serviceInfoProvider.getServiceId()); | 120 | + consumerBuilder.clientId("re-" + queueName + "-consumer-" + serviceInfoProvider.getServiceId()); |
121 | + consumerBuilder.groupId("re-" + queueName + "-consumer-" + serviceInfoProvider.getServiceId()); | ||
120 | consumerBuilder.decoder(msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); | 122 | consumerBuilder.decoder(msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); |
121 | return consumerBuilder.build(); | 123 | return consumerBuilder.build(); |
122 | } | 124 | } |
123 | 125 | ||
124 | @Override | 126 | @Override |
125 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getToRuleEngineNotificationsMsgConsumer() { | 127 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() { |
126 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 128 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
127 | consumerBuilder.settings(kafkaSettings); | 129 | consumerBuilder.settings(kafkaSettings); |
128 | consumerBuilder.topic(partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName()); | 130 | consumerBuilder.topic(partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName()); |
@@ -133,7 +135,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -133,7 +135,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
133 | } | 135 | } |
134 | 136 | ||
135 | @Override | 137 | @Override |
136 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> getToCoreMsgConsumer() { | 138 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() { |
137 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 139 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
138 | consumerBuilder.settings(kafkaSettings); | 140 | consumerBuilder.settings(kafkaSettings); |
139 | consumerBuilder.topic(coreSettings.getTopic()); | 141 | consumerBuilder.topic(coreSettings.getTopic()); |
@@ -144,7 +146,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -144,7 +146,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
144 | } | 146 | } |
145 | 147 | ||
146 | @Override | 148 | @Override |
147 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> getToCoreNotificationsMsgConsumer() { | 149 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() { |
148 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 150 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
149 | consumerBuilder.settings(kafkaSettings); | 151 | consumerBuilder.settings(kafkaSettings); |
150 | consumerBuilder.topic(partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName()); | 152 | consumerBuilder.topic(partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName()); |
@@ -155,7 +157,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -155,7 +157,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
155 | } | 157 | } |
156 | 158 | ||
157 | @Override | 159 | @Override |
158 | - public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> getTransportApiRequestConsumer() { | 160 | + public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> createTransportApiRequestConsumer() { |
159 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<TransportApiRequestMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 161 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<TransportApiRequestMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
160 | consumerBuilder.settings(kafkaSettings); | 162 | consumerBuilder.settings(kafkaSettings); |
161 | consumerBuilder.topic(transportApiSettings.getRequestsTopic()); | 163 | consumerBuilder.topic(transportApiSettings.getRequestsTopic()); |
@@ -166,7 +168,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | @@ -166,7 +168,7 @@ public class KafkaMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEn | ||
166 | } | 168 | } |
167 | 169 | ||
168 | @Override | 170 | @Override |
169 | - public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiResponseProducer() { | 171 | + public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiResponseProducer() { |
170 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<TransportApiResponseMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 172 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<TransportApiResponseMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
171 | requestBuilder.settings(kafkaSettings); | 173 | requestBuilder.settings(kafkaSettings); |
172 | requestBuilder.clientId("monolith-transport-api-producer-" + serviceInfoProvider.getServiceId()); | 174 | requestBuilder.clientId("monolith-transport-api-producer-" + serviceInfoProvider.getServiceId()); |
common/queue/src/main/java/org/thingsboard/server/queue/provider/KafkaTbCoreQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/KafkaTbCoreQueueProvider.java
@@ -26,10 +26,10 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | @@ -26,10 +26,10 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | ||
26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; | 26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; |
27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
28 | import org.thingsboard.server.queue.TbQueueConsumer; | 28 | import org.thingsboard.server.queue.TbQueueConsumer; |
29 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 29 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
30 | import org.thingsboard.server.queue.TbQueueProducer; | 30 | import org.thingsboard.server.queue.TbQueueProducer; |
31 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | ||
32 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | 31 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
32 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; | ||
33 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 33 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
34 | import org.thingsboard.server.queue.discovery.PartitionService; | 34 | import org.thingsboard.server.queue.discovery.PartitionService; |
35 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 35 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
@@ -39,7 +39,7 @@ import org.thingsboard.server.queue.kafka.TbKafkaSettings; | @@ -39,7 +39,7 @@ import org.thingsboard.server.queue.kafka.TbKafkaSettings; | ||
39 | 39 | ||
40 | @Component | 40 | @Component |
41 | @ConditionalOnExpression("'${queue.type:null}'=='kafka' && '${service.type:null}'=='tb-core'") | 41 | @ConditionalOnExpression("'${queue.type:null}'=='kafka' && '${service.type:null}'=='tb-core'") |
42 | -public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | 42 | +public class KafkaTbCoreQueueFactory implements TbCoreQueueFactory { |
43 | 43 | ||
44 | private final PartitionService partitionService; | 44 | private final PartitionService partitionService; |
45 | private final TbKafkaSettings kafkaSettings; | 45 | private final TbKafkaSettings kafkaSettings; |
@@ -48,11 +48,11 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -48,11 +48,11 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
48 | private final TbQueueRuleEngineSettings ruleEngineSettings; | 48 | private final TbQueueRuleEngineSettings ruleEngineSettings; |
49 | private final TbQueueTransportApiSettings transportApiSettings; | 49 | private final TbQueueTransportApiSettings transportApiSettings; |
50 | 50 | ||
51 | - public KafkaTbCoreQueueProvider(PartitionService partitionService, TbKafkaSettings kafkaSettings, | ||
52 | - TbServiceInfoProvider serviceInfoProvider, | ||
53 | - TbQueueCoreSettings coreSettings, | ||
54 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
55 | - TbQueueTransportApiSettings transportApiSettings) { | 51 | + public KafkaTbCoreQueueFactory(PartitionService partitionService, TbKafkaSettings kafkaSettings, |
52 | + TbServiceInfoProvider serviceInfoProvider, | ||
53 | + TbQueueCoreSettings coreSettings, | ||
54 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
55 | + TbQueueTransportApiSettings transportApiSettings) { | ||
56 | this.partitionService = partitionService; | 56 | this.partitionService = partitionService; |
57 | this.kafkaSettings = kafkaSettings; | 57 | this.kafkaSettings = kafkaSettings; |
58 | this.serviceInfoProvider = serviceInfoProvider; | 58 | this.serviceInfoProvider = serviceInfoProvider; |
@@ -62,7 +62,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -62,7 +62,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
62 | } | 62 | } |
63 | 63 | ||
64 | @Override | 64 | @Override |
65 | - public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer() { | 65 | + public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() { |
66 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToTransportMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 66 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToTransportMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
67 | requestBuilder.settings(kafkaSettings); | 67 | requestBuilder.settings(kafkaSettings); |
68 | requestBuilder.clientId("tb-core-transport-notifications-" + serviceInfoProvider.getServiceId()); | 68 | requestBuilder.clientId("tb-core-transport-notifications-" + serviceInfoProvider.getServiceId()); |
@@ -71,7 +71,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -71,7 +71,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
71 | } | 71 | } |
72 | 72 | ||
73 | @Override | 73 | @Override |
74 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 74 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
75 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 75 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
76 | requestBuilder.settings(kafkaSettings); | 76 | requestBuilder.settings(kafkaSettings); |
77 | requestBuilder.clientId("tb-core-rule-engine-" + serviceInfoProvider.getServiceId()); | 77 | requestBuilder.clientId("tb-core-rule-engine-" + serviceInfoProvider.getServiceId()); |
@@ -80,7 +80,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -80,7 +80,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
80 | } | 80 | } |
81 | 81 | ||
82 | @Override | 82 | @Override |
83 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 83 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
84 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 84 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
85 | requestBuilder.settings(kafkaSettings); | 85 | requestBuilder.settings(kafkaSettings); |
86 | requestBuilder.clientId("tb-core-rule-engine-notifications-" + serviceInfoProvider.getServiceId()); | 86 | requestBuilder.clientId("tb-core-rule-engine-notifications-" + serviceInfoProvider.getServiceId()); |
@@ -89,7 +89,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -89,7 +89,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
89 | } | 89 | } |
90 | 90 | ||
91 | @Override | 91 | @Override |
92 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 92 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
93 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 93 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
94 | requestBuilder.settings(kafkaSettings); | 94 | requestBuilder.settings(kafkaSettings); |
95 | requestBuilder.clientId("tb-core-to-core-" + serviceInfoProvider.getServiceId()); | 95 | requestBuilder.clientId("tb-core-to-core-" + serviceInfoProvider.getServiceId()); |
@@ -98,7 +98,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -98,7 +98,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
98 | } | 98 | } |
99 | 99 | ||
100 | @Override | 100 | @Override |
101 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 101 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
102 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 102 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
103 | requestBuilder.settings(kafkaSettings); | 103 | requestBuilder.settings(kafkaSettings); |
104 | requestBuilder.clientId("tb-core-to-core-notifications-" + serviceInfoProvider.getServiceId()); | 104 | requestBuilder.clientId("tb-core-to-core-notifications-" + serviceInfoProvider.getServiceId()); |
@@ -107,7 +107,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -107,7 +107,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
107 | } | 107 | } |
108 | 108 | ||
109 | @Override | 109 | @Override |
110 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> getToCoreMsgConsumer() { | 110 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() { |
111 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 111 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
112 | consumerBuilder.settings(kafkaSettings); | 112 | consumerBuilder.settings(kafkaSettings); |
113 | consumerBuilder.topic(coreSettings.getTopic()); | 113 | consumerBuilder.topic(coreSettings.getTopic()); |
@@ -118,7 +118,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -118,7 +118,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
118 | } | 118 | } |
119 | 119 | ||
120 | @Override | 120 | @Override |
121 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> getToCoreNotificationsMsgConsumer() { | 121 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() { |
122 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 122 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
123 | consumerBuilder.settings(kafkaSettings); | 123 | consumerBuilder.settings(kafkaSettings); |
124 | consumerBuilder.topic(partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName()); | 124 | consumerBuilder.topic(partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName()); |
@@ -129,7 +129,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -129,7 +129,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
129 | } | 129 | } |
130 | 130 | ||
131 | @Override | 131 | @Override |
132 | - public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> getTransportApiRequestConsumer() { | 132 | + public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> createTransportApiRequestConsumer() { |
133 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<TransportApiRequestMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 133 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<TransportApiRequestMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
134 | consumerBuilder.settings(kafkaSettings); | 134 | consumerBuilder.settings(kafkaSettings); |
135 | consumerBuilder.topic(transportApiSettings.getRequestsTopic()); | 135 | consumerBuilder.topic(transportApiSettings.getRequestsTopic()); |
@@ -140,7 +140,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -140,7 +140,7 @@ public class KafkaTbCoreQueueProvider implements TbCoreQueueProvider { | ||
140 | } | 140 | } |
141 | 141 | ||
142 | @Override | 142 | @Override |
143 | - public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiResponseProducer() { | 143 | + public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiResponseProducer() { |
144 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<TransportApiResponseMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 144 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<TransportApiResponseMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
145 | requestBuilder.settings(kafkaSettings); | 145 | requestBuilder.settings(kafkaSettings); |
146 | requestBuilder.clientId("tb-core-transport-api-producer-" + serviceInfoProvider.getServiceId()); | 146 | requestBuilder.clientId("tb-core-transport-api-producer-" + serviceInfoProvider.getServiceId()); |
common/queue/src/main/java/org/thingsboard/server/queue/provider/KafkaTbRuleEngineQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/KafkaTbRuleEngineQueueProvider.java
@@ -24,19 +24,20 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | @@ -24,19 +24,20 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | ||
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
26 | import org.thingsboard.server.queue.TbQueueConsumer; | 26 | import org.thingsboard.server.queue.TbQueueConsumer; |
27 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 27 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
28 | import org.thingsboard.server.queue.TbQueueProducer; | 28 | import org.thingsboard.server.queue.TbQueueProducer; |
29 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | 29 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
30 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 30 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
31 | import org.thingsboard.server.queue.discovery.PartitionService; | 31 | import org.thingsboard.server.queue.discovery.PartitionService; |
32 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 32 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
33 | import org.thingsboard.server.queue.kafka.TBKafkaConsumerTemplate; | 33 | import org.thingsboard.server.queue.kafka.TBKafkaConsumerTemplate; |
34 | import org.thingsboard.server.queue.kafka.TBKafkaProducerTemplate; | 34 | import org.thingsboard.server.queue.kafka.TBKafkaProducerTemplate; |
35 | import org.thingsboard.server.queue.kafka.TbKafkaSettings; | 35 | import org.thingsboard.server.queue.kafka.TbKafkaSettings; |
36 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
36 | 37 | ||
37 | @Component | 38 | @Component |
38 | @ConditionalOnExpression("'${queue.type:null}'=='kafka' && '${service.type:null}'=='tb-rule-engine'") | 39 | @ConditionalOnExpression("'${queue.type:null}'=='kafka' && '${service.type:null}'=='tb-rule-engine'") |
39 | -public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider { | 40 | +public class KafkaTbRuleEngineQueueFactory implements TbRuleEngineQueueFactory { |
40 | 41 | ||
41 | private final PartitionService partitionService; | 42 | private final PartitionService partitionService; |
42 | private final TbKafkaSettings kafkaSettings; | 43 | private final TbKafkaSettings kafkaSettings; |
@@ -44,10 +45,10 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | @@ -44,10 +45,10 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | ||
44 | private final TbQueueCoreSettings coreSettings; | 45 | private final TbQueueCoreSettings coreSettings; |
45 | private final TbQueueRuleEngineSettings ruleEngineSettings; | 46 | private final TbQueueRuleEngineSettings ruleEngineSettings; |
46 | 47 | ||
47 | - public KafkaTbRuleEngineQueueProvider(PartitionService partitionService, TbKafkaSettings kafkaSettings, | ||
48 | - TbServiceInfoProvider serviceInfoProvider, | ||
49 | - TbQueueCoreSettings coreSettings, | ||
50 | - TbQueueRuleEngineSettings ruleEngineSettings) { | 48 | + public KafkaTbRuleEngineQueueFactory(PartitionService partitionService, TbKafkaSettings kafkaSettings, |
49 | + TbServiceInfoProvider serviceInfoProvider, | ||
50 | + TbQueueCoreSettings coreSettings, | ||
51 | + TbQueueRuleEngineSettings ruleEngineSettings) { | ||
51 | this.partitionService = partitionService; | 52 | this.partitionService = partitionService; |
52 | this.kafkaSettings = kafkaSettings; | 53 | this.kafkaSettings = kafkaSettings; |
53 | this.serviceInfoProvider = serviceInfoProvider; | 54 | this.serviceInfoProvider = serviceInfoProvider; |
@@ -56,7 +57,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | @@ -56,7 +57,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | ||
56 | } | 57 | } |
57 | 58 | ||
58 | @Override | 59 | @Override |
59 | - public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer() { | 60 | + public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() { |
60 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToTransportMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 61 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToTransportMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
61 | requestBuilder.settings(kafkaSettings); | 62 | requestBuilder.settings(kafkaSettings); |
62 | requestBuilder.clientId("tb-rule-engine-transport-notifications-" + serviceInfoProvider.getServiceId()); | 63 | requestBuilder.clientId("tb-rule-engine-transport-notifications-" + serviceInfoProvider.getServiceId()); |
@@ -65,7 +66,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | @@ -65,7 +66,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | ||
65 | } | 66 | } |
66 | 67 | ||
67 | @Override | 68 | @Override |
68 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 69 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
69 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 70 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
70 | requestBuilder.settings(kafkaSettings); | 71 | requestBuilder.settings(kafkaSettings); |
71 | requestBuilder.clientId("tb-rule-engine-to-rule-engine-" + serviceInfoProvider.getServiceId()); | 72 | requestBuilder.clientId("tb-rule-engine-to-rule-engine-" + serviceInfoProvider.getServiceId()); |
@@ -74,7 +75,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | @@ -74,7 +75,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | ||
74 | } | 75 | } |
75 | 76 | ||
76 | @Override | 77 | @Override |
77 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 78 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
78 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 79 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
79 | requestBuilder.settings(kafkaSettings); | 80 | requestBuilder.settings(kafkaSettings); |
80 | requestBuilder.clientId("tb-rule-engine-to-rule-engine-notifications-" + serviceInfoProvider.getServiceId()); | 81 | requestBuilder.clientId("tb-rule-engine-to-rule-engine-notifications-" + serviceInfoProvider.getServiceId()); |
@@ -84,7 +85,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | @@ -84,7 +85,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | ||
84 | 85 | ||
85 | 86 | ||
86 | @Override | 87 | @Override |
87 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 88 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
88 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 89 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
89 | requestBuilder.settings(kafkaSettings); | 90 | requestBuilder.settings(kafkaSettings); |
90 | requestBuilder.clientId("tb-rule-engine-to-core-" + serviceInfoProvider.getServiceId()); | 91 | requestBuilder.clientId("tb-rule-engine-to-core-" + serviceInfoProvider.getServiceId()); |
@@ -93,7 +94,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | @@ -93,7 +94,7 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | ||
93 | } | 94 | } |
94 | 95 | ||
95 | @Override | 96 | @Override |
96 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 97 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
97 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 98 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreNotificationMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
98 | requestBuilder.settings(kafkaSettings); | 99 | requestBuilder.settings(kafkaSettings); |
99 | requestBuilder.clientId("tb-rule-engine-to-core-notifications-" + serviceInfoProvider.getServiceId()); | 100 | requestBuilder.clientId("tb-rule-engine-to-core-notifications-" + serviceInfoProvider.getServiceId()); |
@@ -102,18 +103,19 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | @@ -102,18 +103,19 @@ public class KafkaTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider | ||
102 | } | 103 | } |
103 | 104 | ||
104 | @Override | 105 | @Override |
105 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> getToRuleEngineMsgConsumer() { | 106 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) { |
107 | + String queueName = configuration.getName(); | ||
106 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 108 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
107 | consumerBuilder.settings(kafkaSettings); | 109 | consumerBuilder.settings(kafkaSettings); |
108 | consumerBuilder.topic(ruleEngineSettings.getTopic()); | 110 | consumerBuilder.topic(ruleEngineSettings.getTopic()); |
109 | - consumerBuilder.clientId("tb-rule-engine-consumer-" + serviceInfoProvider.getServiceId()); | ||
110 | - consumerBuilder.groupId("tb-rule-engine-node-" + serviceInfoProvider.getServiceId()); | 111 | + consumerBuilder.clientId("re-" + queueName + "-consumer-" + serviceInfoProvider.getServiceId()); |
112 | + consumerBuilder.groupId("re-" + queueName + "-consumer-" + serviceInfoProvider.getServiceId()); | ||
111 | consumerBuilder.decoder(msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); | 113 | consumerBuilder.decoder(msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); |
112 | return consumerBuilder.build(); | 114 | return consumerBuilder.build(); |
113 | } | 115 | } |
114 | 116 | ||
115 | @Override | 117 | @Override |
116 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getToRuleEngineNotificationsMsgConsumer() { | 118 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() { |
117 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); | 119 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> consumerBuilder = TBKafkaConsumerTemplate.builder(); |
118 | consumerBuilder.settings(kafkaSettings); | 120 | consumerBuilder.settings(kafkaSettings); |
119 | consumerBuilder.topic(partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName()); | 121 | consumerBuilder.topic(partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName()); |
common/queue/src/main/java/org/thingsboard/server/queue/provider/KafkaTbTransportQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/KafkaTbTransportQueueProvider.java
@@ -19,12 +19,12 @@ import lombok.extern.slf4j.Slf4j; | @@ -19,12 +19,12 @@ import lombok.extern.slf4j.Slf4j; | ||
19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
20 | import org.springframework.stereotype.Component; | 20 | import org.springframework.stereotype.Component; |
21 | import org.thingsboard.server.queue.TbQueueConsumer; | 21 | import org.thingsboard.server.queue.TbQueueConsumer; |
22 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 22 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
23 | import org.thingsboard.server.queue.TbQueueProducer; | 23 | import org.thingsboard.server.queue.TbQueueProducer; |
24 | import org.thingsboard.server.queue.TbQueueRequestTemplate; | 24 | import org.thingsboard.server.queue.TbQueueRequestTemplate; |
25 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | ||
26 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | ||
27 | -import org.thingsboard.server.queue.TbQueueTransportNotificationSettings; | 25 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
26 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; | ||
27 | +import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings; | ||
28 | import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate; | 28 | import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate; |
29 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 29 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
30 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 30 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
@@ -41,7 +41,7 @@ import org.thingsboard.server.queue.kafka.TbKafkaSettings; | @@ -41,7 +41,7 @@ import org.thingsboard.server.queue.kafka.TbKafkaSettings; | ||
41 | @Component | 41 | @Component |
42 | @ConditionalOnExpression("'${queue.type:null}'=='kafka' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')") | 42 | @ConditionalOnExpression("'${queue.type:null}'=='kafka' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')") |
43 | @Slf4j | 43 | @Slf4j |
44 | -public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | 44 | +public class KafkaTbTransportQueueFactory implements TbTransportQueueFactory { |
45 | 45 | ||
46 | private final TbKafkaSettings kafkaSettings; | 46 | private final TbKafkaSettings kafkaSettings; |
47 | private final TbServiceInfoProvider serviceInfoProvider; | 47 | private final TbServiceInfoProvider serviceInfoProvider; |
@@ -50,12 +50,12 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | @@ -50,12 +50,12 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | ||
50 | private final TbQueueTransportApiSettings transportApiSettings; | 50 | private final TbQueueTransportApiSettings transportApiSettings; |
51 | private final TbQueueTransportNotificationSettings transportNotificationSettings; | 51 | private final TbQueueTransportNotificationSettings transportNotificationSettings; |
52 | 52 | ||
53 | - public KafkaTbTransportQueueProvider(TbKafkaSettings kafkaSettings, | ||
54 | - TbServiceInfoProvider serviceInfoProvider, | ||
55 | - TbQueueCoreSettings coreSettings, | ||
56 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
57 | - TbQueueTransportApiSettings transportApiSettings, | ||
58 | - TbQueueTransportNotificationSettings transportNotificationSettings) { | 53 | + public KafkaTbTransportQueueFactory(TbKafkaSettings kafkaSettings, |
54 | + TbServiceInfoProvider serviceInfoProvider, | ||
55 | + TbQueueCoreSettings coreSettings, | ||
56 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
57 | + TbQueueTransportApiSettings transportApiSettings, | ||
58 | + TbQueueTransportNotificationSettings transportNotificationSettings) { | ||
59 | this.kafkaSettings = kafkaSettings; | 59 | this.kafkaSettings = kafkaSettings; |
60 | this.serviceInfoProvider = serviceInfoProvider; | 60 | this.serviceInfoProvider = serviceInfoProvider; |
61 | this.coreSettings = coreSettings; | 61 | this.coreSettings = coreSettings; |
@@ -65,7 +65,7 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | @@ -65,7 +65,7 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | ||
65 | } | 65 | } |
66 | 66 | ||
67 | @Override | 67 | @Override |
68 | - public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiRequestTemplate() { | 68 | + public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiRequestTemplate() { |
69 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<TransportApiRequestMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 69 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<TransportApiRequestMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
70 | requestBuilder.settings(kafkaSettings); | 70 | requestBuilder.settings(kafkaSettings); |
71 | requestBuilder.clientId("transport-api-request-" + serviceInfoProvider.getServiceId()); | 71 | requestBuilder.clientId("transport-api-request-" + serviceInfoProvider.getServiceId()); |
@@ -90,7 +90,7 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | @@ -90,7 +90,7 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | ||
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | @Override |
93 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 93 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
94 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 94 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToRuleEngineMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
95 | requestBuilder.settings(kafkaSettings); | 95 | requestBuilder.settings(kafkaSettings); |
96 | requestBuilder.clientId("transport-node-rule-engine-"+ serviceInfoProvider.getServiceId()); | 96 | requestBuilder.clientId("transport-node-rule-engine-"+ serviceInfoProvider.getServiceId()); |
@@ -99,7 +99,7 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | @@ -99,7 +99,7 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | ||
99 | } | 99 | } |
100 | 100 | ||
101 | @Override | 101 | @Override |
102 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 102 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
103 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); | 103 | TBKafkaProducerTemplate.TBKafkaProducerTemplateBuilder<TbProtoQueueMsg<ToCoreMsg>> requestBuilder = TBKafkaProducerTemplate.builder(); |
104 | requestBuilder.settings(kafkaSettings); | 104 | requestBuilder.settings(kafkaSettings); |
105 | requestBuilder.clientId("transport-node-core-" + serviceInfoProvider.getServiceId()); | 105 | requestBuilder.clientId("transport-node-core-" + serviceInfoProvider.getServiceId()); |
@@ -108,7 +108,7 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | @@ -108,7 +108,7 @@ public class KafkaTbTransportQueueProvider implements TbTransportQueueProvider { | ||
108 | } | 108 | } |
109 | 109 | ||
110 | @Override | 110 | @Override |
111 | - public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsConsumer() { | 111 | + public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsConsumer() { |
112 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToTransportMsg>> responseBuilder = TBKafkaConsumerTemplate.builder(); | 112 | TBKafkaConsumerTemplate.TBKafkaConsumerTemplateBuilder<TbProtoQueueMsg<ToTransportMsg>> responseBuilder = TBKafkaConsumerTemplate.builder(); |
113 | responseBuilder.settings(kafkaSettings); | 113 | responseBuilder.settings(kafkaSettings); |
114 | responseBuilder.topic(transportNotificationSettings.getNotificationsTopic() + "." + serviceInfoProvider.getServiceId()); | 114 | responseBuilder.topic(transportNotificationSettings.getNotificationsTopic() + "." + serviceInfoProvider.getServiceId()); |
common/queue/src/main/java/org/thingsboard/server/queue/provider/PubSubMonolithQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/PubSubMonolithQueueProvider.java
@@ -27,11 +27,11 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | @@ -27,11 +27,11 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | ||
27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
28 | import org.thingsboard.server.queue.TbQueueAdmin; | 28 | import org.thingsboard.server.queue.TbQueueAdmin; |
29 | import org.thingsboard.server.queue.TbQueueConsumer; | 29 | import org.thingsboard.server.queue.TbQueueConsumer; |
30 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 30 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
31 | import org.thingsboard.server.queue.TbQueueProducer; | 31 | import org.thingsboard.server.queue.TbQueueProducer; |
32 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | ||
33 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | ||
34 | -import org.thingsboard.server.queue.TbQueueTransportNotificationSettings; | 32 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
33 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; | ||
34 | +import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings; | ||
35 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 35 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
36 | import org.thingsboard.server.queue.discovery.PartitionService; | 36 | import org.thingsboard.server.queue.discovery.PartitionService; |
37 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 37 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
@@ -39,10 +39,11 @@ import org.thingsboard.server.queue.pubsub.TbPubSubAdmin; | @@ -39,10 +39,11 @@ import org.thingsboard.server.queue.pubsub.TbPubSubAdmin; | ||
39 | import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate; | 39 | import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate; |
40 | import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate; | 40 | import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate; |
41 | import org.thingsboard.server.queue.pubsub.TbPubSubSettings; | 41 | import org.thingsboard.server.queue.pubsub.TbPubSubSettings; |
42 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
42 | 43 | ||
43 | @Component | 44 | @Component |
44 | @ConditionalOnExpression("'${queue.type:null}'=='pubsub' && '${service.type:null}'=='monolith'") | 45 | @ConditionalOnExpression("'${queue.type:null}'=='pubsub' && '${service.type:null}'=='monolith'") |
45 | -public class PubSubMonolithQueueProvider implements TbCoreQueueProvider, TbRuleEngineQueueProvider { | 46 | +public class PubSubMonolithQueueFactory implements TbCoreQueueFactory, TbRuleEngineQueueFactory { |
46 | 47 | ||
47 | private final TbPubSubSettings pubSubSettings; | 48 | private final TbPubSubSettings pubSubSettings; |
48 | private final TbQueueCoreSettings coreSettings; | 49 | private final TbQueueCoreSettings coreSettings; |
@@ -55,13 +56,13 @@ public class PubSubMonolithQueueProvider implements TbCoreQueueProvider, TbRuleE | @@ -55,13 +56,13 @@ public class PubSubMonolithQueueProvider implements TbCoreQueueProvider, TbRuleE | ||
55 | 56 | ||
56 | private TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> tbCoreProducer; | 57 | private TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> tbCoreProducer; |
57 | 58 | ||
58 | - public PubSubMonolithQueueProvider(TbPubSubSettings pubSubSettings, | ||
59 | - TbQueueCoreSettings coreSettings, | ||
60 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
61 | - TbQueueTransportApiSettings transportApiSettings, | ||
62 | - TbQueueTransportNotificationSettings transportNotificationSettings, | ||
63 | - PartitionService partitionService, | ||
64 | - TbServiceInfoProvider serviceInfoProvider) { | 59 | + public PubSubMonolithQueueFactory(TbPubSubSettings pubSubSettings, |
60 | + TbQueueCoreSettings coreSettings, | ||
61 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
62 | + TbQueueTransportApiSettings transportApiSettings, | ||
63 | + TbQueueTransportNotificationSettings transportNotificationSettings, | ||
64 | + PartitionService partitionService, | ||
65 | + TbServiceInfoProvider serviceInfoProvider) { | ||
65 | this.pubSubSettings = pubSubSettings; | 66 | this.pubSubSettings = pubSubSettings; |
66 | this.coreSettings = coreSettings; | 67 | this.coreSettings = coreSettings; |
67 | this.ruleEngineSettings = ruleEngineSettings; | 68 | this.ruleEngineSettings = ruleEngineSettings; |
@@ -73,65 +74,65 @@ public class PubSubMonolithQueueProvider implements TbCoreQueueProvider, TbRuleE | @@ -73,65 +74,65 @@ public class PubSubMonolithQueueProvider implements TbCoreQueueProvider, TbRuleE | ||
73 | } | 74 | } |
74 | 75 | ||
75 | @Override | 76 | @Override |
76 | - public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer() { | 77 | + public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() { |
77 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, transportNotificationSettings.getNotificationsTopic()); | 78 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, transportNotificationSettings.getNotificationsTopic()); |
78 | } | 79 | } |
79 | 80 | ||
80 | @Override | 81 | @Override |
81 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 82 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
82 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic()); | 83 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic()); |
83 | 84 | ||
84 | } | 85 | } |
85 | 86 | ||
86 | @Override | 87 | @Override |
87 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 88 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
88 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic()); | 89 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic()); |
89 | } | 90 | } |
90 | 91 | ||
91 | @Override | 92 | @Override |
92 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 93 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
93 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 94 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
94 | } | 95 | } |
95 | 96 | ||
96 | @Override | 97 | @Override |
97 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 98 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
98 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 99 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
99 | } | 100 | } |
100 | 101 | ||
101 | @Override | 102 | @Override |
102 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> getToRuleEngineMsgConsumer() { | 103 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) { |
103 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic(), | 104 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic(), |
104 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); | 105 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); |
105 | } | 106 | } |
106 | 107 | ||
107 | @Override | 108 | @Override |
108 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getToRuleEngineNotificationsMsgConsumer() { | 109 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() { |
109 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, | 110 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, |
110 | partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(), | 111 | partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(), |
111 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); | 112 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); |
112 | } | 113 | } |
113 | 114 | ||
114 | @Override | 115 | @Override |
115 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> getToCoreMsgConsumer() { | 116 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() { |
116 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, coreSettings.getTopic(), | 117 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, coreSettings.getTopic(), |
117 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders())); | 118 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders())); |
118 | } | 119 | } |
119 | 120 | ||
120 | @Override | 121 | @Override |
121 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> getToCoreNotificationsMsgConsumer() { | 122 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() { |
122 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, | 123 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, |
123 | partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(), | 124 | partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(), |
124 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); | 125 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); |
125 | } | 126 | } |
126 | 127 | ||
127 | @Override | 128 | @Override |
128 | - public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> getTransportApiRequestConsumer() { | 129 | + public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> createTransportApiRequestConsumer() { |
129 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, transportApiSettings.getRequestsTopic(), | 130 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, transportApiSettings.getRequestsTopic(), |
130 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders())); | 131 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders())); |
131 | } | 132 | } |
132 | 133 | ||
133 | @Override | 134 | @Override |
134 | - public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiResponseProducer() { | 135 | + public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiResponseProducer() { |
135 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, transportApiSettings.getResponsesTopic()); | 136 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, transportApiSettings.getResponsesTopic()); |
136 | } | 137 | } |
137 | } | 138 | } |
common/queue/src/main/java/org/thingsboard/server/queue/provider/PubSubTbCoreQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/PubSubTbCoreQueueProvider.java
@@ -27,9 +27,9 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | @@ -27,9 +27,9 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | ||
27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 27 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
28 | import org.thingsboard.server.queue.TbQueueAdmin; | 28 | import org.thingsboard.server.queue.TbQueueAdmin; |
29 | import org.thingsboard.server.queue.TbQueueConsumer; | 29 | import org.thingsboard.server.queue.TbQueueConsumer; |
30 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 30 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
31 | import org.thingsboard.server.queue.TbQueueProducer; | 31 | import org.thingsboard.server.queue.TbQueueProducer; |
32 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | 32 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; |
33 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 33 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
34 | import org.thingsboard.server.queue.discovery.PartitionService; | 34 | import org.thingsboard.server.queue.discovery.PartitionService; |
35 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 35 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
@@ -39,7 +39,7 @@ import org.thingsboard.server.queue.pubsub.TbPubSubSettings; | @@ -39,7 +39,7 @@ import org.thingsboard.server.queue.pubsub.TbPubSubSettings; | ||
39 | 39 | ||
40 | @Component | 40 | @Component |
41 | @ConditionalOnExpression("'${queue.type:null}'=='pubsub' && '${service.type:null}'=='tb-core'") | 41 | @ConditionalOnExpression("'${queue.type:null}'=='pubsub' && '${service.type:null}'=='tb-core'") |
42 | -public class PubSubTbCoreQueueProvider implements TbCoreQueueProvider { | 42 | +public class PubSubTbCoreQueueFactory implements TbCoreQueueFactory { |
43 | 43 | ||
44 | private final TbPubSubSettings pubSubSettings; | 44 | private final TbPubSubSettings pubSubSettings; |
45 | private final TbQueueCoreSettings coreSettings; | 45 | private final TbQueueCoreSettings coreSettings; |
@@ -48,12 +48,12 @@ public class PubSubTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -48,12 +48,12 @@ public class PubSubTbCoreQueueProvider implements TbCoreQueueProvider { | ||
48 | private final PartitionService partitionService; | 48 | private final PartitionService partitionService; |
49 | private final TbServiceInfoProvider serviceInfoProvider; | 49 | private final TbServiceInfoProvider serviceInfoProvider; |
50 | 50 | ||
51 | - public PubSubTbCoreQueueProvider(TbPubSubSettings pubSubSettings, | ||
52 | - TbQueueCoreSettings coreSettings, | ||
53 | - TbQueueTransportApiSettings transportApiSettings, | ||
54 | - TbQueueAdmin admin, | ||
55 | - PartitionService partitionService, | ||
56 | - TbServiceInfoProvider serviceInfoProvider) { | 51 | + public PubSubTbCoreQueueFactory(TbPubSubSettings pubSubSettings, |
52 | + TbQueueCoreSettings coreSettings, | ||
53 | + TbQueueTransportApiSettings transportApiSettings, | ||
54 | + TbQueueAdmin admin, | ||
55 | + PartitionService partitionService, | ||
56 | + TbServiceInfoProvider serviceInfoProvider) { | ||
57 | this.pubSubSettings = pubSubSettings; | 57 | this.pubSubSettings = pubSubSettings; |
58 | this.coreSettings = coreSettings; | 58 | this.coreSettings = coreSettings; |
59 | this.transportApiSettings = transportApiSettings; | 59 | this.transportApiSettings = transportApiSettings; |
@@ -63,51 +63,51 @@ public class PubSubTbCoreQueueProvider implements TbCoreQueueProvider { | @@ -63,51 +63,51 @@ public class PubSubTbCoreQueueProvider implements TbCoreQueueProvider { | ||
63 | } | 63 | } |
64 | 64 | ||
65 | @Override | 65 | @Override |
66 | - public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer() { | 66 | + public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() { |
67 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 67 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
68 | } | 68 | } |
69 | 69 | ||
70 | @Override | 70 | @Override |
71 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 71 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
72 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 72 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
73 | } | 73 | } |
74 | 74 | ||
75 | @Override | 75 | @Override |
76 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 76 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
77 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 77 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
78 | } | 78 | } |
79 | 79 | ||
80 | @Override | 80 | @Override |
81 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 81 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
82 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 82 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
83 | } | 83 | } |
84 | 84 | ||
85 | @Override | 85 | @Override |
86 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 86 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
87 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 87 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
88 | } | 88 | } |
89 | 89 | ||
90 | @Override | 90 | @Override |
91 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> getToCoreMsgConsumer() { | 91 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer() { |
92 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, coreSettings.getTopic(), | 92 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, coreSettings.getTopic(), |
93 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders())); | 93 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreMsg.parseFrom(msg.getData()), msg.getHeaders())); |
94 | } | 94 | } |
95 | 95 | ||
96 | @Override | 96 | @Override |
97 | - public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> getToCoreNotificationsMsgConsumer() { | 97 | + public TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer() { |
98 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, | 98 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, |
99 | partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(), | 99 | partitionService.getNotificationsTopic(ServiceType.TB_CORE, serviceInfoProvider.getServiceId()).getFullTopicName(), |
100 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); | 100 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToCoreNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); |
101 | } | 101 | } |
102 | 102 | ||
103 | @Override | 103 | @Override |
104 | - public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> getTransportApiRequestConsumer() { | 104 | + public TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> createTransportApiRequestConsumer() { |
105 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, transportApiSettings.getRequestsTopic(), | 105 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, transportApiSettings.getRequestsTopic(), |
106 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders())); | 106 | msg -> new TbProtoQueueMsg<>(msg.getKey(), TransportApiRequestMsg.parseFrom(msg.getData()), msg.getHeaders())); |
107 | } | 107 | } |
108 | 108 | ||
109 | @Override | 109 | @Override |
110 | - public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiResponseProducer() { | 110 | + public TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiResponseProducer() { |
111 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 111 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
112 | } | 112 | } |
113 | } | 113 | } |
common/queue/src/main/java/org/thingsboard/server/queue/provider/PubSubTbRuleEngineQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/PubSubTbRuleEngineQueueProvider.java
@@ -25,19 +25,20 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotifica | @@ -25,19 +25,20 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotifica | ||
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
26 | import org.thingsboard.server.queue.TbQueueAdmin; | 26 | import org.thingsboard.server.queue.TbQueueAdmin; |
27 | import org.thingsboard.server.queue.TbQueueConsumer; | 27 | import org.thingsboard.server.queue.TbQueueConsumer; |
28 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 28 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
29 | import org.thingsboard.server.queue.TbQueueProducer; | 29 | import org.thingsboard.server.queue.TbQueueProducer; |
30 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | 30 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
31 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 31 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
32 | import org.thingsboard.server.queue.discovery.PartitionService; | 32 | import org.thingsboard.server.queue.discovery.PartitionService; |
33 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 33 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
34 | import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate; | 34 | import org.thingsboard.server.queue.pubsub.TbPubSubConsumerTemplate; |
35 | import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate; | 35 | import org.thingsboard.server.queue.pubsub.TbPubSubProducerTemplate; |
36 | import org.thingsboard.server.queue.pubsub.TbPubSubSettings; | 36 | import org.thingsboard.server.queue.pubsub.TbPubSubSettings; |
37 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
37 | 38 | ||
38 | @Component | 39 | @Component |
39 | @ConditionalOnExpression("'${queue.type:null}'=='pubsub' && '${service.type:null}'=='tb-rule-engine'") | 40 | @ConditionalOnExpression("'${queue.type:null}'=='pubsub' && '${service.type:null}'=='tb-rule-engine'") |
40 | -public class PubSubTbRuleEngineQueueProvider implements TbRuleEngineQueueProvider { | 41 | +public class PubSubTbRuleEngineQueueFactory implements TbRuleEngineQueueFactory { |
41 | 42 | ||
42 | private final TbPubSubSettings pubSubSettings; | 43 | private final TbPubSubSettings pubSubSettings; |
43 | private final TbQueueCoreSettings coreSettings; | 44 | private final TbQueueCoreSettings coreSettings; |
@@ -46,12 +47,12 @@ public class PubSubTbRuleEngineQueueProvider implements TbRuleEngineQueueProvide | @@ -46,12 +47,12 @@ public class PubSubTbRuleEngineQueueProvider implements TbRuleEngineQueueProvide | ||
46 | private final PartitionService partitionService; | 47 | private final PartitionService partitionService; |
47 | private final TbServiceInfoProvider serviceInfoProvider; | 48 | private final TbServiceInfoProvider serviceInfoProvider; |
48 | 49 | ||
49 | - public PubSubTbRuleEngineQueueProvider(TbPubSubSettings pubSubSettings, | ||
50 | - TbQueueCoreSettings coreSettings, | ||
51 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
52 | - TbQueueAdmin admin, | ||
53 | - PartitionService partitionService, | ||
54 | - TbServiceInfoProvider serviceInfoProvider) { | 50 | + public PubSubTbRuleEngineQueueFactory(TbPubSubSettings pubSubSettings, |
51 | + TbQueueCoreSettings coreSettings, | ||
52 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
53 | + TbQueueAdmin admin, | ||
54 | + PartitionService partitionService, | ||
55 | + TbServiceInfoProvider serviceInfoProvider) { | ||
55 | this.pubSubSettings = pubSubSettings; | 56 | this.pubSubSettings = pubSubSettings; |
56 | this.coreSettings = coreSettings; | 57 | this.coreSettings = coreSettings; |
57 | this.ruleEngineSettings = ruleEngineSettings; | 58 | this.ruleEngineSettings = ruleEngineSettings; |
@@ -61,39 +62,39 @@ public class PubSubTbRuleEngineQueueProvider implements TbRuleEngineQueueProvide | @@ -61,39 +62,39 @@ public class PubSubTbRuleEngineQueueProvider implements TbRuleEngineQueueProvide | ||
61 | } | 62 | } |
62 | 63 | ||
63 | @Override | 64 | @Override |
64 | - public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer() { | 65 | + public TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer() { |
65 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 66 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
66 | } | 67 | } |
67 | 68 | ||
68 | @Override | 69 | @Override |
69 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 70 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
70 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 71 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
71 | } | 72 | } |
72 | 73 | ||
73 | @Override | 74 | @Override |
74 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer() { | 75 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer() { |
75 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic()); | 76 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic()); |
76 | } | 77 | } |
77 | 78 | ||
78 | @Override | 79 | @Override |
79 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 80 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
80 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 81 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
81 | 82 | ||
82 | } | 83 | } |
83 | 84 | ||
84 | @Override | 85 | @Override |
85 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer() { | 86 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer() { |
86 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 87 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
87 | } | 88 | } |
88 | 89 | ||
89 | @Override | 90 | @Override |
90 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> getToRuleEngineMsgConsumer() { | 91 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration) { |
91 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic(), | 92 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic(), |
92 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); | 93 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineMsg.parseFrom(msg.getData()), msg.getHeaders())); |
93 | } | 94 | } |
94 | 95 | ||
95 | @Override | 96 | @Override |
96 | - public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getToRuleEngineNotificationsMsgConsumer() { | 97 | + public TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer() { |
97 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, | 98 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, |
98 | partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(), | 99 | partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceInfoProvider.getServiceId()).getFullTopicName(), |
99 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); | 100 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToRuleEngineNotificationMsg.parseFrom(msg.getData()), msg.getHeaders())); |
common/queue/src/main/java/org/thingsboard/server/queue/provider/PubSubTransportQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/PubSubTransportQueueProvider.java
@@ -25,12 +25,12 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | @@ -25,12 +25,12 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | ||
25 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 25 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
26 | import org.thingsboard.server.queue.TbQueueAdmin; | 26 | import org.thingsboard.server.queue.TbQueueAdmin; |
27 | import org.thingsboard.server.queue.TbQueueConsumer; | 27 | import org.thingsboard.server.queue.TbQueueConsumer; |
28 | -import org.thingsboard.server.queue.TbQueueCoreSettings; | 28 | +import org.thingsboard.server.queue.settings.TbQueueCoreSettings; |
29 | import org.thingsboard.server.queue.TbQueueProducer; | 29 | import org.thingsboard.server.queue.TbQueueProducer; |
30 | import org.thingsboard.server.queue.TbQueueRequestTemplate; | 30 | import org.thingsboard.server.queue.TbQueueRequestTemplate; |
31 | -import org.thingsboard.server.queue.TbQueueRuleEngineSettings; | ||
32 | -import org.thingsboard.server.queue.TbQueueTransportApiSettings; | ||
33 | -import org.thingsboard.server.queue.TbQueueTransportNotificationSettings; | 31 | +import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
32 | +import org.thingsboard.server.queue.settings.TbQueueTransportApiSettings; | ||
33 | +import org.thingsboard.server.queue.settings.TbQueueTransportNotificationSettings; | ||
34 | import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate; | 34 | import org.thingsboard.server.queue.common.DefaultTbQueueRequestTemplate; |
35 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 35 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
36 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 36 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
@@ -42,7 +42,7 @@ import org.thingsboard.server.queue.pubsub.TbPubSubSettings; | @@ -42,7 +42,7 @@ import org.thingsboard.server.queue.pubsub.TbPubSubSettings; | ||
42 | @Component | 42 | @Component |
43 | @ConditionalOnExpression("'${queue.type:null}'=='pubsub' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')") | 43 | @ConditionalOnExpression("'${queue.type:null}'=='pubsub' && ('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-transport')") |
44 | @Slf4j | 44 | @Slf4j |
45 | -public class PubSubTransportQueueProvider implements TbTransportQueueProvider { | 45 | +public class PubSubTransportQueueFactory implements TbTransportQueueFactory { |
46 | 46 | ||
47 | private final TbPubSubSettings pubSubSettings; | 47 | private final TbPubSubSettings pubSubSettings; |
48 | private final TbServiceInfoProvider serviceInfoProvider; | 48 | private final TbServiceInfoProvider serviceInfoProvider; |
@@ -52,12 +52,12 @@ public class PubSubTransportQueueProvider implements TbTransportQueueProvider { | @@ -52,12 +52,12 @@ public class PubSubTransportQueueProvider implements TbTransportQueueProvider { | ||
52 | private final TbQueueTransportNotificationSettings transportNotificationSettings; | 52 | private final TbQueueTransportNotificationSettings transportNotificationSettings; |
53 | private final TbQueueAdmin admin; | 53 | private final TbQueueAdmin admin; |
54 | 54 | ||
55 | - public PubSubTransportQueueProvider(TbPubSubSettings pubSubSettings, | ||
56 | - TbServiceInfoProvider serviceInfoProvider, | ||
57 | - TbQueueCoreSettings coreSettings, | ||
58 | - TbQueueRuleEngineSettings ruleEngineSettings, | ||
59 | - TbQueueTransportApiSettings transportApiSettings, | ||
60 | - TbQueueTransportNotificationSettings transportNotificationSettings) { | 55 | + public PubSubTransportQueueFactory(TbPubSubSettings pubSubSettings, |
56 | + TbServiceInfoProvider serviceInfoProvider, | ||
57 | + TbQueueCoreSettings coreSettings, | ||
58 | + TbQueueRuleEngineSettings ruleEngineSettings, | ||
59 | + TbQueueTransportApiSettings transportApiSettings, | ||
60 | + TbQueueTransportNotificationSettings transportNotificationSettings) { | ||
61 | this.pubSubSettings = pubSubSettings; | 61 | this.pubSubSettings = pubSubSettings; |
62 | this.serviceInfoProvider = serviceInfoProvider; | 62 | this.serviceInfoProvider = serviceInfoProvider; |
63 | this.coreSettings = coreSettings; | 63 | this.coreSettings = coreSettings; |
@@ -68,7 +68,7 @@ public class PubSubTransportQueueProvider implements TbTransportQueueProvider { | @@ -68,7 +68,7 @@ public class PubSubTransportQueueProvider implements TbTransportQueueProvider { | ||
68 | } | 68 | } |
69 | 69 | ||
70 | @Override | 70 | @Override |
71 | - public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiRequestTemplate() { | 71 | + public TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiRequestTemplate() { |
72 | TbQueueProducer<TbProtoQueueMsg<TransportApiRequestMsg>> producer = new TbPubSubProducerTemplate<>(admin, pubSubSettings, transportApiSettings.getRequestsTopic()); | 72 | TbQueueProducer<TbProtoQueueMsg<TransportApiRequestMsg>> producer = new TbPubSubProducerTemplate<>(admin, pubSubSettings, transportApiSettings.getRequestsTopic()); |
73 | TbQueueConsumer<TbProtoQueueMsg<TransportApiResponseMsg>> consumer = new TbPubSubConsumerTemplate<>(admin, pubSubSettings, | 73 | TbQueueConsumer<TbProtoQueueMsg<TransportApiResponseMsg>> consumer = new TbPubSubConsumerTemplate<>(admin, pubSubSettings, |
74 | transportApiSettings.getResponsesTopic() + "." + serviceInfoProvider.getServiceId(), | 74 | transportApiSettings.getResponsesTopic() + "." + serviceInfoProvider.getServiceId(), |
@@ -86,17 +86,17 @@ public class PubSubTransportQueueProvider implements TbTransportQueueProvider { | @@ -86,17 +86,17 @@ public class PubSubTransportQueueProvider implements TbTransportQueueProvider { | ||
86 | } | 86 | } |
87 | 87 | ||
88 | @Override | 88 | @Override |
89 | - public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer() { | 89 | + public TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer() { |
90 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic()); | 90 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, ruleEngineSettings.getTopic()); |
91 | } | 91 | } |
92 | 92 | ||
93 | @Override | 93 | @Override |
94 | - public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer() { | 94 | + public TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer() { |
95 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); | 95 | return new TbPubSubProducerTemplate<>(admin, pubSubSettings, coreSettings.getTopic()); |
96 | } | 96 | } |
97 | 97 | ||
98 | @Override | 98 | @Override |
99 | - public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsConsumer() { | 99 | + public TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsConsumer() { |
100 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, | 100 | return new TbPubSubConsumerTemplate<>(admin, pubSubSettings, |
101 | transportNotificationSettings.getNotificationsTopic() + "." + serviceInfoProvider.getServiceId(), | 101 | transportNotificationSettings.getNotificationsTopic() + "." + serviceInfoProvider.getServiceId(), |
102 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToTransportMsg.parseFrom(msg.getData()), msg.getHeaders())); | 102 | msg -> new TbProtoQueueMsg<>(msg.getKey(), ToTransportMsg.parseFrom(msg.getData()), msg.getHeaders())); |
common/queue/src/main/java/org/thingsboard/server/queue/provider/TbCoreQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/TbCoreQueueProvider.java
@@ -29,70 +29,70 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponse | @@ -29,70 +29,70 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponse | ||
29 | * Responsible for initialization of various Producers and Consumers used by TB Core Node. | 29 | * Responsible for initialization of various Producers and Consumers used by TB Core Node. |
30 | * Implementation Depends on the queue queue.type from yml or TB_QUEUE_TYPE environment variable | 30 | * Implementation Depends on the queue queue.type from yml or TB_QUEUE_TYPE environment variable |
31 | */ | 31 | */ |
32 | -public interface TbCoreQueueProvider { | 32 | +public interface TbCoreQueueFactory { |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Used to push messages to instances of TB Transport Service | 35 | * Used to push messages to instances of TB Transport Service |
36 | * | 36 | * |
37 | * @return | 37 | * @return |
38 | */ | 38 | */ |
39 | - TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer(); | 39 | + TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer(); |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Used to push messages to instances of TB RuleEngine Service | 42 | * Used to push messages to instances of TB RuleEngine Service |
43 | * | 43 | * |
44 | * @return | 44 | * @return |
45 | */ | 45 | */ |
46 | - TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer(); | 46 | + TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer(); |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Used to push notifications to instances of TB RuleEngine Service | 49 | * Used to push notifications to instances of TB RuleEngine Service |
50 | * | 50 | * |
51 | * @return | 51 | * @return |
52 | */ | 52 | */ |
53 | - TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer(); | 53 | + TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer(); |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Used to push messages to other instances of TB Core Service | 56 | * Used to push messages to other instances of TB Core Service |
57 | * | 57 | * |
58 | * @return | 58 | * @return |
59 | */ | 59 | */ |
60 | - TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer(); | 60 | + TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer(); |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Used to push notifications to other instances of TB Core Service | 63 | * Used to push notifications to other instances of TB Core Service |
64 | * | 64 | * |
65 | * @return | 65 | * @return |
66 | */ | 66 | */ |
67 | - TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer(); | 67 | + TbQueueProducer<TbProtoQueueMsg<ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer(); |
68 | 68 | ||
69 | /** | 69 | /** |
70 | * Used to consume messages by TB Core Service | 70 | * Used to consume messages by TB Core Service |
71 | * | 71 | * |
72 | * @return | 72 | * @return |
73 | */ | 73 | */ |
74 | - TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> getToCoreMsgConsumer(); | 74 | + TbQueueConsumer<TbProtoQueueMsg<ToCoreMsg>> createToCoreMsgConsumer(); |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * Used to consume high priority messages by TB Core Service | 77 | * Used to consume high priority messages by TB Core Service |
78 | * | 78 | * |
79 | * @return | 79 | * @return |
80 | */ | 80 | */ |
81 | - TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> getToCoreNotificationsMsgConsumer(); | 81 | + TbQueueConsumer<TbProtoQueueMsg<ToCoreNotificationMsg>> createToCoreNotificationsMsgConsumer(); |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Used to consume Transport API Calls | 84 | * Used to consume Transport API Calls |
85 | * | 85 | * |
86 | * @return | 86 | * @return |
87 | */ | 87 | */ |
88 | - TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> getTransportApiRequestConsumer(); | 88 | + TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> createTransportApiRequestConsumer(); |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Used to push replies to Transport API Calls | 91 | * Used to push replies to Transport API Calls |
92 | * | 92 | * |
93 | * @return | 93 | * @return |
94 | */ | 94 | */ |
95 | - TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiResponseProducer(); | 95 | + TbQueueProducer<TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiResponseProducer(); |
96 | 96 | ||
97 | 97 | ||
98 | } | 98 | } |
@@ -27,24 +27,24 @@ import javax.annotation.PostConstruct; | @@ -27,24 +27,24 @@ import javax.annotation.PostConstruct; | ||
27 | @ConditionalOnExpression("'${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") | 27 | @ConditionalOnExpression("'${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") |
28 | public class TbCoreQueueProducerProvider implements TbQueueProducerProvider { | 28 | public class TbCoreQueueProducerProvider implements TbQueueProducerProvider { |
29 | 29 | ||
30 | - private final TbCoreQueueProvider tbQueueProvider; | 30 | + private final TbCoreQueueFactory tbQueueProvider; |
31 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> toTransport; | 31 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> toTransport; |
32 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> toRuleEngine; | 32 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> toRuleEngine; |
33 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> toTbCore; | 33 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> toTbCore; |
34 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> toRuleEngineNotifications; | 34 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineNotificationMsg>> toRuleEngineNotifications; |
35 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> toTbCoreNotifications; | 35 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> toTbCoreNotifications; |
36 | 36 | ||
37 | - public TbCoreQueueProducerProvider(TbCoreQueueProvider tbQueueProvider) { | 37 | + public TbCoreQueueProducerProvider(TbCoreQueueFactory tbQueueProvider) { |
38 | this.tbQueueProvider = tbQueueProvider; | 38 | this.tbQueueProvider = tbQueueProvider; |
39 | } | 39 | } |
40 | 40 | ||
41 | @PostConstruct | 41 | @PostConstruct |
42 | public void init() { | 42 | public void init() { |
43 | - this.toTbCore = tbQueueProvider.getTbCoreMsgProducer(); | ||
44 | - this.toTransport = tbQueueProvider.getTransportNotificationsMsgProducer(); | ||
45 | - this.toRuleEngine = tbQueueProvider.getRuleEngineMsgProducer(); | ||
46 | - this.toRuleEngineNotifications = tbQueueProvider.getRuleEngineNotificationsMsgProducer(); | ||
47 | - this.toTbCoreNotifications = tbQueueProvider.getTbCoreNotificationsMsgProducer(); | 43 | + this.toTbCore = tbQueueProvider.createTbCoreMsgProducer(); |
44 | + this.toTransport = tbQueueProvider.createTransportNotificationsMsgProducer(); | ||
45 | + this.toRuleEngine = tbQueueProvider.createRuleEngineMsgProducer(); | ||
46 | + this.toRuleEngineNotifications = tbQueueProvider.createRuleEngineNotificationsMsgProducer(); | ||
47 | + this.toTbCoreNotifications = tbQueueProvider.createTbCoreNotificationsMsgProducer(); | ||
48 | } | 48 | } |
49 | 49 | ||
50 | @Override | 50 | @Override |
@@ -27,7 +27,7 @@ import javax.annotation.PostConstruct; | @@ -27,7 +27,7 @@ import javax.annotation.PostConstruct; | ||
27 | @ConditionalOnExpression("'${service.type:null}'=='tb-rule-engine'") | 27 | @ConditionalOnExpression("'${service.type:null}'=='tb-rule-engine'") |
28 | public class TbRuleEngineProducerProvider implements TbQueueProducerProvider { | 28 | public class TbRuleEngineProducerProvider implements TbQueueProducerProvider { |
29 | 29 | ||
30 | - private final TbRuleEngineQueueProvider tbQueueProvider; | 30 | + private final TbRuleEngineQueueFactory tbQueueProvider; |
31 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> toTransport; | 31 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> toTransport; |
32 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> toRuleEngine; | 32 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> toRuleEngine; |
33 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> toTbCore; | 33 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> toTbCore; |
@@ -35,17 +35,17 @@ public class TbRuleEngineProducerProvider implements TbQueueProducerProvider { | @@ -35,17 +35,17 @@ public class TbRuleEngineProducerProvider implements TbQueueProducerProvider { | ||
35 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> toTbCoreNotifications; | 35 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> toTbCoreNotifications; |
36 | 36 | ||
37 | 37 | ||
38 | - public TbRuleEngineProducerProvider(TbRuleEngineQueueProvider tbQueueProvider) { | 38 | + public TbRuleEngineProducerProvider(TbRuleEngineQueueFactory tbQueueProvider) { |
39 | this.tbQueueProvider = tbQueueProvider; | 39 | this.tbQueueProvider = tbQueueProvider; |
40 | } | 40 | } |
41 | 41 | ||
42 | @PostConstruct | 42 | @PostConstruct |
43 | public void init() { | 43 | public void init() { |
44 | - this.toTbCore = tbQueueProvider.getTbCoreMsgProducer(); | ||
45 | - this.toTransport = tbQueueProvider.getTransportNotificationsMsgProducer(); | ||
46 | - this.toRuleEngine = tbQueueProvider.getRuleEngineMsgProducer(); | ||
47 | - this.toRuleEngineNotifications = tbQueueProvider.getRuleEngineNotificationsMsgProducer(); | ||
48 | - this.toTbCoreNotifications = tbQueueProvider.getTbCoreNotificationsMsgProducer(); | 44 | + this.toTbCore = tbQueueProvider.createTbCoreMsgProducer(); |
45 | + this.toTransport = tbQueueProvider.createTransportNotificationsMsgProducer(); | ||
46 | + this.toRuleEngine = tbQueueProvider.createRuleEngineMsgProducer(); | ||
47 | + this.toRuleEngineNotifications = tbQueueProvider.createRuleEngineNotificationsMsgProducer(); | ||
48 | + this.toTbCoreNotifications = tbQueueProvider.createTbCoreNotificationsMsgProducer(); | ||
49 | } | 49 | } |
50 | 50 | ||
51 | @Override | 51 | @Override |
common/queue/src/main/java/org/thingsboard/server/queue/provider/TbRuleEngineQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/TbRuleEngineQueueProvider.java
@@ -23,60 +23,63 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | @@ -23,60 +23,63 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | ||
23 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 23 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
24 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 24 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
25 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; | 25 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg; |
26 | +import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | ||
26 | 27 | ||
27 | /** | 28 | /** |
28 | * Responsible for initialization of various Producers and Consumers used by TB Core Node. | 29 | * Responsible for initialization of various Producers and Consumers used by TB Core Node. |
29 | * Implementation Depends on the queue queue.type from yml or TB_QUEUE_TYPE environment variable | 30 | * Implementation Depends on the queue queue.type from yml or TB_QUEUE_TYPE environment variable |
30 | */ | 31 | */ |
31 | -public interface TbRuleEngineQueueProvider { | 32 | +public interface TbRuleEngineQueueFactory { |
32 | 33 | ||
33 | /** | 34 | /** |
34 | * Used to push messages to instances of TB Transport Service | 35 | * Used to push messages to instances of TB Transport Service |
35 | * | 36 | * |
36 | * @return | 37 | * @return |
37 | */ | 38 | */ |
38 | - TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsMsgProducer(); | 39 | + TbQueueProducer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsMsgProducer(); |
39 | 40 | ||
40 | /** | 41 | /** |
41 | * Used to push messages to instances of TB RuleEngine Service | 42 | * Used to push messages to instances of TB RuleEngine Service |
42 | * | 43 | * |
43 | * @return | 44 | * @return |
44 | */ | 45 | */ |
45 | - TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer(); | 46 | + TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer(); |
46 | 47 | ||
47 | /** | 48 | /** |
48 | * Used to push notifications to instances of TB RuleEngine Service | 49 | * Used to push notifications to instances of TB RuleEngine Service |
49 | * | 50 | * |
50 | * @return | 51 | * @return |
51 | */ | 52 | */ |
52 | - TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getRuleEngineNotificationsMsgProducer(); | 53 | + TbQueueProducer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createRuleEngineNotificationsMsgProducer(); |
53 | 54 | ||
54 | /** | 55 | /** |
55 | * Used to push messages to other instances of TB Core Service | 56 | * Used to push messages to other instances of TB Core Service |
56 | * | 57 | * |
57 | * @return | 58 | * @return |
58 | */ | 59 | */ |
59 | - TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer(); | 60 | + TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer(); |
60 | 61 | ||
61 | /** | 62 | /** |
62 | * Used to push notifications to other instances of TB Core Service | 63 | * Used to push notifications to other instances of TB Core Service |
63 | * | 64 | * |
64 | * @return | 65 | * @return |
65 | */ | 66 | */ |
66 | - TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> getTbCoreNotificationsMsgProducer(); | 67 | + TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreNotificationMsg>> createTbCoreNotificationsMsgProducer(); |
67 | 68 | ||
68 | /** | 69 | /** |
69 | * Used to consume messages by TB Core Service | 70 | * Used to consume messages by TB Core Service |
70 | * | 71 | * |
71 | * @return | 72 | * @return |
73 | + * @param configuration | ||
72 | */ | 74 | */ |
73 | - TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> getToRuleEngineMsgConsumer(); | 75 | + //TODO 2.5 ybondarenko: make sure you use queueName to distinct consumers where necessary |
76 | + TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineMsg>> createToRuleEngineMsgConsumer(TbRuleEngineQueueConfiguration configuration); | ||
74 | 77 | ||
75 | /** | 78 | /** |
76 | * Used to consume high priority messages by TB Core Service | 79 | * Used to consume high priority messages by TB Core Service |
77 | * | 80 | * |
78 | * @return | 81 | * @return |
79 | */ | 82 | */ |
80 | - TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> getToRuleEngineNotificationsMsgConsumer(); | 83 | + TbQueueConsumer<TbProtoQueueMsg<ToRuleEngineNotificationMsg>> createToRuleEngineNotificationsMsgConsumer(); |
81 | 84 | ||
82 | } | 85 | } |
common/queue/src/main/java/org/thingsboard/server/queue/provider/TbTransportQueueFactory.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/provider/TbTransportQueueProvider.java
@@ -25,14 +25,14 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | @@ -25,14 +25,14 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | ||
25 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; | 25 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg; |
26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 26 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
27 | 27 | ||
28 | -public interface TbTransportQueueProvider { | 28 | +public interface TbTransportQueueFactory { |
29 | 29 | ||
30 | - TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> getTransportApiRequestTemplate(); | 30 | + TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> createTransportApiRequestTemplate(); |
31 | 31 | ||
32 | - TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> getRuleEngineMsgProducer(); | 32 | + TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> createRuleEngineMsgProducer(); |
33 | 33 | ||
34 | - TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> getTbCoreMsgProducer(); | 34 | + TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> createTbCoreMsgProducer(); |
35 | 35 | ||
36 | - TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> getTransportNotificationsConsumer(); | 36 | + TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> createTransportNotificationsConsumer(); |
37 | 37 | ||
38 | } | 38 | } |
@@ -28,19 +28,19 @@ import javax.annotation.PostConstruct; | @@ -28,19 +28,19 @@ import javax.annotation.PostConstruct; | ||
28 | @ConditionalOnExpression("'${service.type:null}'=='tb-transport'") | 28 | @ConditionalOnExpression("'${service.type:null}'=='tb-transport'") |
29 | public class TbTransportQueueProducerProvider implements TbQueueProducerProvider { | 29 | public class TbTransportQueueProducerProvider implements TbQueueProducerProvider { |
30 | 30 | ||
31 | - private final TbTransportQueueProvider tbQueueProvider; | 31 | + private final TbTransportQueueFactory tbQueueProvider; |
32 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> toTransport; | 32 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToTransportMsg>> toTransport; |
33 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> toRuleEngine; | 33 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToRuleEngineMsg>> toRuleEngine; |
34 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> toTbCore; | 34 | private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> toTbCore; |
35 | 35 | ||
36 | - public TbTransportQueueProducerProvider(TbTransportQueueProvider tbQueueProvider) { | 36 | + public TbTransportQueueProducerProvider(TbTransportQueueFactory tbQueueProvider) { |
37 | this.tbQueueProvider = tbQueueProvider; | 37 | this.tbQueueProvider = tbQueueProvider; |
38 | } | 38 | } |
39 | 39 | ||
40 | @PostConstruct | 40 | @PostConstruct |
41 | public void init() { | 41 | public void init() { |
42 | - this.toTbCore = tbQueueProvider.getTbCoreMsgProducer(); | ||
43 | - this.toRuleEngine = tbQueueProvider.getRuleEngineMsgProducer(); | 42 | + this.toTbCore = tbQueueProvider.createTbCoreMsgProducer(); |
43 | + this.toRuleEngine = tbQueueProvider.createRuleEngineMsgProducer(); | ||
44 | } | 44 | } |
45 | 45 | ||
46 | @Override | 46 | @Override |
common/queue/src/main/java/org/thingsboard/server/queue/settings/TbQueueCoreSettings.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueCoreSettings.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.queue; | 16 | +package org.thingsboard.server.queue.settings; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.springframework.beans.factory.annotation.Value; | 19 | import org.springframework.beans.factory.annotation.Value; |
common/queue/src/main/java/org/thingsboard/server/queue/settings/TbQueueRuleEngineSettings.java
0 → 100644
1 | +/** | ||
2 | + * Copyright © 2016-2020 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.queue.settings; | ||
17 | + | ||
18 | +import lombok.Data; | ||
19 | +import lombok.extern.slf4j.Slf4j; | ||
20 | +import org.springframework.beans.factory.annotation.Value; | ||
21 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
22 | +import org.springframework.context.annotation.Configuration; | ||
23 | + | ||
24 | +import javax.annotation.PostConstruct; | ||
25 | +import java.util.List; | ||
26 | + | ||
27 | +@Slf4j | ||
28 | +@Data | ||
29 | +@Configuration | ||
30 | +@ConfigurationProperties(prefix = "queue.rule-engine") | ||
31 | +public class TbQueueRuleEngineSettings { | ||
32 | + | ||
33 | + private String topic; | ||
34 | + private List<TbRuleEngineQueueConfiguration> queues; | ||
35 | + | ||
36 | + //TODO 2.5 ybondarenko: make sure the queue names are valid to all queue providers. See how ther are used in TbRuleEngineQueueFactory.createToRuleEngineMsgConsumer and all producers | ||
37 | + @PostConstruct | ||
38 | + public void validate() { | ||
39 | + queues.stream().filter(queue -> queue.getName().equals("Main")).findFirst().orElseThrow(() -> { | ||
40 | + log.warn("Main queue is not configured in thingsboard.yml"); | ||
41 | + return new RuntimeException("No \"Main\" queue configured!"); | ||
42 | + }); | ||
43 | + } | ||
44 | + | ||
45 | +} |
common/queue/src/main/java/org/thingsboard/server/queue/settings/TbQueueTransportApiSettings.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueTransportApiSettings.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.queue; | 16 | +package org.thingsboard.server.queue.settings; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.springframework.beans.factory.annotation.Value; | 19 | import org.springframework.beans.factory.annotation.Value; |
common/queue/src/main/java/org/thingsboard/server/queue/settings/TbQueueTransportNotificationSettings.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueTransportNotificationSettings.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.queue; | 16 | +package org.thingsboard.server.queue.settings; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.springframework.beans.factory.annotation.Value; | 19 | import org.springframework.beans.factory.annotation.Value; |
1 | +/** | ||
2 | + * Copyright © 2016-2020 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.queue.settings; | ||
17 | + | ||
18 | +import lombok.Data; | ||
19 | + | ||
20 | +@Data | ||
21 | +public class TbRuleEngineQueueAckStrategyConfiguration { | ||
22 | + | ||
23 | +// @Value("${type}") | ||
24 | + private String type; | ||
25 | +// @Value("${retries:3}") | ||
26 | + private int retries; | ||
27 | +// @Value("${failure_percentage:0}") | ||
28 | + private double failurePercentage; | ||
29 | +// @Value("${pause_between_retries:3}") | ||
30 | + private long pauseBetweenRetries; | ||
31 | + | ||
32 | +} |
common/queue/src/main/java/org/thingsboard/server/queue/settings/TbRuleEngineQueueConfiguration.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueRuleEngineSettings.java
@@ -13,19 +13,18 @@ | @@ -13,19 +13,18 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.queue; | 16 | +package org.thingsboard.server.queue.settings; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.springframework.beans.factory.annotation.Value; | ||
20 | -import org.springframework.stereotype.Component; | ||
21 | 19 | ||
22 | @Data | 20 | @Data |
23 | -@Component | ||
24 | -public class TbQueueRuleEngineSettings { | 21 | +public class TbRuleEngineQueueConfiguration { |
25 | 22 | ||
26 | - @Value("${queue.rule_engine.topic}") | 23 | + private String name; |
27 | private String topic; | 24 | private String topic; |
28 | - | ||
29 | - @Value("${queue.rule_engine.partitions}") | 25 | + private int pollInterval; |
30 | private int partitions; | 26 | private int partitions; |
27 | + private String packProcessingTimeout; | ||
28 | + private TbRuleEngineQueueAckStrategyConfiguration ackStrategy; | ||
29 | + | ||
31 | } | 30 | } |
@@ -19,6 +19,12 @@ package transport; | @@ -19,6 +19,12 @@ package transport; | ||
19 | option java_package = "org.thingsboard.server.gen.transport"; | 19 | option java_package = "org.thingsboard.server.gen.transport"; |
20 | option java_outer_classname = "TransportProtos"; | 20 | option java_outer_classname = "TransportProtos"; |
21 | 21 | ||
22 | +message QueueInfo { | ||
23 | + string name = 1; | ||
24 | + string topic = 2; | ||
25 | + int32 partitions = 3; | ||
26 | +} | ||
27 | + | ||
22 | /** | 28 | /** |
23 | * Service Discovery Data Structures; | 29 | * Service Discovery Data Structures; |
24 | */ | 30 | */ |
@@ -27,6 +33,7 @@ message ServiceInfo { | @@ -27,6 +33,7 @@ message ServiceInfo { | ||
27 | repeated string serviceTypes = 2; | 33 | repeated string serviceTypes = 2; |
28 | int64 tenantIdMSB = 3; | 34 | int64 tenantIdMSB = 3; |
29 | int64 tenantIdLSB = 4; | 35 | int64 tenantIdLSB = 4; |
36 | + repeated QueueInfo ruleEngineQueues = 5; | ||
30 | } | 37 | } |
31 | 38 | ||
32 | /** | 39 | /** |
@@ -380,6 +387,7 @@ message ToRuleEngineMsg { | @@ -380,6 +387,7 @@ message ToRuleEngineMsg { | ||
380 | int64 tenantIdMSB = 1; | 387 | int64 tenantIdMSB = 1; |
381 | int64 tenantIdLSB = 2; | 388 | int64 tenantIdLSB = 2; |
382 | bytes tbMsg = 3; | 389 | bytes tbMsg = 3; |
390 | + repeated string relationTypes = 4; | ||
383 | } | 391 | } |
384 | 392 | ||
385 | message ToRuleEngineNotificationMsg { | 393 | message ToRuleEngineNotificationMsg { |
@@ -23,9 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | @@ -23,9 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
23 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
24 | import org.thingsboard.common.util.ThingsBoardThreadFactory; | 24 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
25 | import org.thingsboard.server.common.msg.TbMsg; | 25 | import org.thingsboard.server.common.msg.TbMsg; |
26 | -import org.thingsboard.server.common.msg.TbMsgDataType; | ||
27 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 26 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
28 | -import org.thingsboard.server.common.msg.queue.TbMsgCallback; | ||
29 | import org.thingsboard.server.common.msg.session.SessionMsgType; | 27 | import org.thingsboard.server.common.msg.session.SessionMsgType; |
30 | import org.thingsboard.server.common.transport.util.JsonUtils; | 28 | import org.thingsboard.server.common.transport.util.JsonUtils; |
31 | import org.thingsboard.server.queue.TbQueueCallback; | 29 | import org.thingsboard.server.queue.TbQueueCallback; |
@@ -46,7 +44,7 @@ import org.thingsboard.server.queue.discovery.PartitionService; | @@ -46,7 +44,7 @@ import org.thingsboard.server.queue.discovery.PartitionService; | ||
46 | import org.thingsboard.server.common.msg.queue.ServiceType; | 44 | import org.thingsboard.server.common.msg.queue.ServiceType; |
47 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 45 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
48 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | 46 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
49 | -import org.thingsboard.server.queue.provider.TbTransportQueueProvider; | 47 | +import org.thingsboard.server.queue.provider.TbTransportQueueFactory; |
50 | import org.thingsboard.server.gen.transport.TransportProtos; | 48 | import org.thingsboard.server.gen.transport.TransportProtos; |
51 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 49 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
52 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 50 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
@@ -92,7 +90,7 @@ public class DefaultTransportService implements TransportService { | @@ -92,7 +90,7 @@ public class DefaultTransportService implements TransportService { | ||
92 | private int notificationsPollDuration; | 90 | private int notificationsPollDuration; |
93 | 91 | ||
94 | private final Gson gson = new Gson(); | 92 | private final Gson gson = new Gson(); |
95 | - private final TbTransportQueueProvider queueProvider; | 93 | + private final TbTransportQueueFactory queueProvider; |
96 | private final TbQueueProducerProvider producerProvider; | 94 | private final TbQueueProducerProvider producerProvider; |
97 | private final PartitionService partitionService; | 95 | private final PartitionService partitionService; |
98 | 96 | ||
@@ -112,7 +110,7 @@ public class DefaultTransportService implements TransportService { | @@ -112,7 +110,7 @@ public class DefaultTransportService implements TransportService { | ||
112 | private ExecutorService mainConsumerExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("transport-consumer")); | 110 | private ExecutorService mainConsumerExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("transport-consumer")); |
113 | private volatile boolean stopped = false; | 111 | private volatile boolean stopped = false; |
114 | 112 | ||
115 | - public DefaultTransportService(TbTransportQueueProvider queueProvider, TbQueueProducerProvider producerProvider, PartitionService partitionService) { | 113 | + public DefaultTransportService(TbTransportQueueFactory queueProvider, TbQueueProducerProvider producerProvider, PartitionService partitionService) { |
116 | this.queueProvider = queueProvider; | 114 | this.queueProvider = queueProvider; |
117 | this.producerProvider = producerProvider; | 115 | this.producerProvider = producerProvider; |
118 | this.partitionService = partitionService; | 116 | this.partitionService = partitionService; |
@@ -128,10 +126,10 @@ public class DefaultTransportService implements TransportService { | @@ -128,10 +126,10 @@ public class DefaultTransportService implements TransportService { | ||
128 | this.schedulerExecutor = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName("transport-scheduler")); | 126 | this.schedulerExecutor = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName("transport-scheduler")); |
129 | this.transportCallbackExecutor = Executors.newWorkStealingPool(20); | 127 | this.transportCallbackExecutor = Executors.newWorkStealingPool(20); |
130 | this.schedulerExecutor.scheduleAtFixedRate(this::checkInactivityAndReportActivity, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS); | 128 | this.schedulerExecutor.scheduleAtFixedRate(this::checkInactivityAndReportActivity, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS); |
131 | - transportApiRequestTemplate = queueProvider.getTransportApiRequestTemplate(); | 129 | + transportApiRequestTemplate = queueProvider.createTransportApiRequestTemplate(); |
132 | ruleEngineMsgProducer = producerProvider.getRuleEngineMsgProducer(); | 130 | ruleEngineMsgProducer = producerProvider.getRuleEngineMsgProducer(); |
133 | tbCoreMsgProducer = producerProvider.getTbCoreMsgProducer(); | 131 | tbCoreMsgProducer = producerProvider.getTbCoreMsgProducer(); |
134 | - transportNotificationsConsumer = queueProvider.getTransportNotificationsConsumer(); | 132 | + transportNotificationsConsumer = queueProvider.createTransportNotificationsConsumer(); |
135 | transportNotificationsConsumer.subscribe(); | 133 | transportNotificationsConsumer.subscribe(); |
136 | transportApiRequestTemplate.init(); | 134 | transportApiRequestTemplate.init(); |
137 | mainConsumerExecutor.execute(() -> { | 135 | mainConsumerExecutor.execute(() -> { |
@@ -251,8 +249,7 @@ public class DefaultTransportService implements TransportService { | @@ -251,8 +249,7 @@ public class DefaultTransportService implements TransportService { | ||
251 | metaData.putValue("deviceType", sessionInfo.getDeviceType()); | 249 | metaData.putValue("deviceType", sessionInfo.getDeviceType()); |
252 | metaData.putValue("ts", tsKv.getTs() + ""); | 250 | metaData.putValue("ts", tsKv.getTs() + ""); |
253 | JsonObject json = JsonUtils.getJsonObject(tsKv.getKvList()); | 251 | JsonObject json = JsonUtils.getJsonObject(tsKv.getKvList()); |
254 | - TbMsg tbMsg = new TbMsg(UUID.randomUUID(), SessionMsgType.POST_TELEMETRY_REQUEST.name(), | ||
255 | - deviceId, metaData, TbMsgDataType.JSON, gson.toJson(json), null, null, TbMsgCallback.EMPTY); | 252 | + TbMsg tbMsg = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, metaData, gson.toJson(json)); |
256 | sendToRuleEngine(tenantId, tbMsg, packCallback); | 253 | sendToRuleEngine(tenantId, tbMsg, packCallback); |
257 | } | 254 | } |
258 | } | 255 | } |
@@ -268,8 +265,7 @@ public class DefaultTransportService implements TransportService { | @@ -268,8 +265,7 @@ public class DefaultTransportService implements TransportService { | ||
268 | TbMsgMetaData metaData = new TbMsgMetaData(); | 265 | TbMsgMetaData metaData = new TbMsgMetaData(); |
269 | metaData.putValue("deviceName", sessionInfo.getDeviceName()); | 266 | metaData.putValue("deviceName", sessionInfo.getDeviceName()); |
270 | metaData.putValue("deviceType", sessionInfo.getDeviceType()); | 267 | metaData.putValue("deviceType", sessionInfo.getDeviceType()); |
271 | - TbMsg tbMsg = new TbMsg(UUID.randomUUID(), SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), deviceId, metaData, | ||
272 | - TbMsgDataType.JSON, gson.toJson(json), null, null, TbMsgCallback.EMPTY); | 268 | + TbMsg tbMsg = TbMsg.newMsg(SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), deviceId, metaData, gson.toJson(json)); |
273 | sendToRuleEngine(tenantId, tbMsg, new TransportTbQueueCallback(callback)); | 269 | sendToRuleEngine(tenantId, tbMsg, new TransportTbQueueCallback(callback)); |
274 | } | 270 | } |
275 | } | 271 | } |
@@ -29,6 +29,7 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -29,6 +29,7 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
29 | import org.thingsboard.server.common.data.rule.RuleNode; | 29 | import org.thingsboard.server.common.data.rule.RuleNode; |
30 | import org.thingsboard.server.common.msg.TbMsg; | 30 | import org.thingsboard.server.common.msg.TbMsg; |
31 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 31 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
32 | +import org.thingsboard.server.common.msg.queue.TbMsgCallback; | ||
32 | import org.thingsboard.server.dao.alarm.AlarmService; | 33 | import org.thingsboard.server.dao.alarm.AlarmService; |
33 | import org.thingsboard.server.dao.asset.AssetService; | 34 | import org.thingsboard.server.dao.asset.AssetService; |
34 | import org.thingsboard.server.dao.attributes.AttributesService; | 35 | import org.thingsboard.server.dao.attributes.AttributesService; |
@@ -45,27 +46,80 @@ import org.thingsboard.server.dao.timeseries.TimeseriesService; | @@ -45,27 +46,80 @@ import org.thingsboard.server.dao.timeseries.TimeseriesService; | ||
45 | import org.thingsboard.server.dao.user.UserService; | 46 | import org.thingsboard.server.dao.user.UserService; |
46 | 47 | ||
47 | import java.util.Set; | 48 | import java.util.Set; |
49 | +import java.util.function.Consumer; | ||
48 | 50 | ||
49 | /** | 51 | /** |
50 | * Created by ashvayka on 13.01.18. | 52 | * Created by ashvayka on 13.01.18. |
51 | */ | 53 | */ |
52 | public interface TbContext { | 54 | public interface TbContext { |
53 | 55 | ||
56 | + /* | ||
57 | + * | ||
58 | + * METHODS TO CONTROL THE MESSAGE FLOW | ||
59 | + * | ||
60 | + */ | ||
61 | + | ||
62 | + /** | ||
63 | + * Sends message to all Rule Nodes in the Rule Chain | ||
64 | + * that are connected to the current Rule Node using specified relationType. | ||
65 | + * | ||
66 | + * @param msg | ||
67 | + * @param relationType | ||
68 | + */ | ||
54 | void tellNext(TbMsg msg, String relationType); | 69 | void tellNext(TbMsg msg, String relationType); |
55 | 70 | ||
56 | - void tellNext(TbMsg msg, String relationType, Throwable th); | ||
57 | - | 71 | + /** |
72 | + * Sends message to all Rule Nodes in the Rule Chain | ||
73 | + * that are connected to the current Rule Node using one of specified relationTypes. | ||
74 | + * | ||
75 | + * @param msg | ||
76 | + * @param relationTypes | ||
77 | + */ | ||
58 | void tellNext(TbMsg msg, Set<String> relationTypes); | 78 | void tellNext(TbMsg msg, Set<String> relationTypes); |
59 | 79 | ||
80 | + /** | ||
81 | + * Sends message to the current Rule Node with specified delay in milliseconds. | ||
82 | + * Note: this message is not queued and may be lost in case of a server restart. | ||
83 | + * | ||
84 | + * @param msg | ||
85 | + */ | ||
60 | void tellSelf(TbMsg msg, long delayMs); | 86 | void tellSelf(TbMsg msg, long delayMs); |
61 | 87 | ||
62 | - boolean isLocalEntity(EntityId entityId); | ||
63 | - | 88 | + /** |
89 | + * Notifies Rule Engine about failure to process current message. | ||
90 | + * | ||
91 | + * @param msg - message | ||
92 | + * @param th - exception | ||
93 | + */ | ||
64 | void tellFailure(TbMsg msg, Throwable th); | 94 | void tellFailure(TbMsg msg, Throwable th); |
65 | 95 | ||
66 | - void updateSelf(RuleNode self); | 96 | + /** |
97 | + * Puts new message to queue for processing by the Root Rule Chain | ||
98 | + * | ||
99 | + * @param msg - message | ||
100 | + */ | ||
101 | + void enqueue(TbMsg msg, Runnable onSuccess, Consumer<Throwable> onFailure); | ||
102 | + | ||
103 | + /** | ||
104 | + * Puts new message to custom queue for processing | ||
105 | + * | ||
106 | + * @param msg - message | ||
107 | + */ | ||
108 | + void enqueue(TbMsg msg, String queueName, Runnable onSuccess, Consumer<Throwable> onFailure); | ||
109 | + | ||
110 | + void enqueueForTellNext(TbMsg msg, String relationType); | ||
111 | + | ||
112 | + void enqueueForTellNext(TbMsg msg, Set<String> relationTypes); | ||
113 | + | ||
114 | + void enqueueForTellNext(TbMsg msg, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure); | ||
67 | 115 | ||
68 | - void sendTbMsgToRuleEngine(TbMsg msg); | 116 | + void enqueueForTellNext(TbMsg msg, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure); |
117 | + | ||
118 | + void enqueueForTellNext(TbMsg msg, String queueName, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure); | ||
119 | + | ||
120 | + void enqueueForTellNext(TbMsg msg, String queueName, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure); | ||
121 | + | ||
122 | + void ack(TbMsg tbMsg); | ||
69 | 123 | ||
70 | TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data); | 124 | TbMsg newMsg(String type, EntityId originator, TbMsgMetaData metaData, String data); |
71 | 125 | ||
@@ -77,8 +131,17 @@ public interface TbContext { | @@ -77,8 +131,17 @@ public interface TbContext { | ||
77 | 131 | ||
78 | TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId); | 132 | TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId); |
79 | 133 | ||
134 | + // TODO: Does this changes the message? | ||
80 | TbMsg alarmCreatedMsg(Alarm alarm, RuleNodeId ruleNodeId); | 135 | TbMsg alarmCreatedMsg(Alarm alarm, RuleNodeId ruleNodeId); |
81 | 136 | ||
137 | + /* | ||
138 | + * | ||
139 | + * METHODS TO PROCESS THE MESSAGES | ||
140 | + * | ||
141 | + */ | ||
142 | + | ||
143 | + boolean isLocalEntity(EntityId entityId); | ||
144 | + | ||
82 | RuleNodeId getSelfId(); | 145 | RuleNodeId getSelfId(); |
83 | 146 | ||
84 | TenantId getTenantId(); | 147 | TenantId getTenantId(); |
@@ -129,7 +192,7 @@ public interface TbContext { | @@ -129,7 +192,7 @@ public interface TbContext { | ||
129 | 192 | ||
130 | void logJsEvalFailure(); | 193 | void logJsEvalFailure(); |
131 | 194 | ||
132 | - String getNodeId(); | 195 | + String getServiceId(); |
133 | 196 | ||
134 | RuleChainTransactionService getRuleChainTransactionService(); | 197 | RuleChainTransactionService getRuleChainTransactionService(); |
135 | 198 | ||
@@ -139,7 +202,7 @@ public interface TbContext { | @@ -139,7 +202,7 @@ public interface TbContext { | ||
139 | 202 | ||
140 | ResultSetFuture submitCassandraTask(CassandraStatementTask task); | 203 | ResultSetFuture submitCassandraTask(CassandraStatementTask task); |
141 | 204 | ||
205 | + //TODO 2.5: - need to remove this. | ||
142 | RedisTemplate<String, Object> getRedisTemplate(); | 206 | RedisTemplate<String, Object> getRedisTemplate(); |
143 | 207 | ||
144 | - String getServerAddress(); | ||
145 | } | 208 | } |
@@ -29,8 +29,6 @@ import org.thingsboard.server.common.data.alarm.Alarm; | @@ -29,8 +29,6 @@ import org.thingsboard.server.common.data.alarm.Alarm; | ||
29 | import org.thingsboard.server.common.msg.TbMsg; | 29 | import org.thingsboard.server.common.msg.TbMsg; |
30 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 30 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
31 | 31 | ||
32 | -import javax.script.ScriptException; | ||
33 | - | ||
34 | import static org.thingsboard.common.util.DonAsynchron.withCallback; | 32 | import static org.thingsboard.common.util.DonAsynchron.withCallback; |
35 | 33 | ||
36 | 34 | ||
@@ -63,16 +61,16 @@ public abstract class TbAbstractAlarmNode<C extends TbAbstractAlarmNodeConfigura | @@ -63,16 +61,16 @@ public abstract class TbAbstractAlarmNode<C extends TbAbstractAlarmNodeConfigura | ||
63 | if (alarmResult.alarm == null) { | 61 | if (alarmResult.alarm == null) { |
64 | ctx.tellNext(msg, "False"); | 62 | ctx.tellNext(msg, "False"); |
65 | } else if (alarmResult.isCreated) { | 63 | } else if (alarmResult.isCreated) { |
66 | - ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), "Created"); | ||
67 | - ctx.sendTbMsgToRuleEngine(ctx.alarmCreatedMsg(alarmResult.alarm, ctx.getSelfId())); | 64 | + ctx.enqueue(ctx.alarmCreatedMsg(alarmResult.alarm, ctx.getSelfId()), |
65 | + () -> ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), "Created"), | ||
66 | + throwable -> ctx.tellFailure(toAlarmMsg(ctx, alarmResult, msg), throwable)); | ||
68 | } else if (alarmResult.isUpdated) { | 67 | } else if (alarmResult.isUpdated) { |
69 | ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), "Updated"); | 68 | ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), "Updated"); |
70 | } else if (alarmResult.isCleared) { | 69 | } else if (alarmResult.isCleared) { |
71 | ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), "Cleared"); | 70 | ctx.tellNext(toAlarmMsg(ctx, alarmResult, msg), "Cleared"); |
72 | } | 71 | } |
73 | }, | 72 | }, |
74 | - t -> ctx.tellFailure(msg, t) | ||
75 | - , ctx.getDbCallbackExecutor()); | 73 | + t -> ctx.tellFailure(msg, t), ctx.getDbCallbackExecutor()); |
76 | } | 74 | } |
77 | 75 | ||
78 | protected abstract ListenableFuture<AlarmResult> processAlarm(TbContext ctx, TbMsg msg); | 76 | protected abstract ListenableFuture<AlarmResult> processAlarm(TbContext ctx, TbMsg msg); |
@@ -122,7 +122,9 @@ public abstract class TbAbstractCustomerActionNode<C extends TbAbstractCustomerA | @@ -122,7 +122,9 @@ public abstract class TbAbstractCustomerActionNode<C extends TbAbstractCustomerA | ||
122 | newCustomer.setTitle(key.getCustomerTitle()); | 122 | newCustomer.setTitle(key.getCustomerTitle()); |
123 | newCustomer.setTenantId(ctx.getTenantId()); | 123 | newCustomer.setTenantId(ctx.getTenantId()); |
124 | Customer savedCustomer = service.saveCustomer(newCustomer); | 124 | Customer savedCustomer = service.saveCustomer(newCustomer); |
125 | - ctx.sendTbMsgToRuleEngine(ctx.customerCreatedMsg(savedCustomer, ctx.getSelfId())); | 125 | + ctx.enqueue(ctx.customerCreatedMsg(savedCustomer, ctx.getSelfId()), |
126 | + () -> log.trace("Pushed Customer Created message: {}", savedCustomer), | ||
127 | + throwable -> log.warn("Failed to push Customer Created message: {}", savedCustomer, throwable)); | ||
126 | return Optional.of(savedCustomer.getId()); | 128 | return Optional.of(savedCustomer.getId()); |
127 | } | 129 | } |
128 | return Optional.empty(); | 130 | return Optional.empty(); |
@@ -186,7 +186,9 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | @@ -186,7 +186,9 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | ||
186 | newDevice.setType(entitykey.getType()); | 186 | newDevice.setType(entitykey.getType()); |
187 | newDevice.setTenantId(ctx.getTenantId()); | 187 | newDevice.setTenantId(ctx.getTenantId()); |
188 | Device savedDevice = deviceService.saveDevice(newDevice); | 188 | Device savedDevice = deviceService.saveDevice(newDevice); |
189 | - ctx.sendTbMsgToRuleEngine(ctx.deviceCreatedMsg(savedDevice, ctx.getSelfId())); | 189 | + ctx.enqueue(ctx.deviceCreatedMsg(savedDevice, ctx.getSelfId()), |
190 | + () -> log.trace("Pushed Device Created message: {}", savedDevice), | ||
191 | + throwable -> log.warn("Failed to push Device Created message: {}", savedDevice, throwable)); | ||
190 | targetEntity.setEntityId(savedDevice.getId()); | 192 | targetEntity.setEntityId(savedDevice.getId()); |
191 | } | 193 | } |
192 | break; | 194 | break; |
@@ -201,7 +203,9 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | @@ -201,7 +203,9 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | ||
201 | newAsset.setType(entitykey.getType()); | 203 | newAsset.setType(entitykey.getType()); |
202 | newAsset.setTenantId(ctx.getTenantId()); | 204 | newAsset.setTenantId(ctx.getTenantId()); |
203 | Asset savedAsset = assetService.saveAsset(newAsset); | 205 | Asset savedAsset = assetService.saveAsset(newAsset); |
204 | - ctx.sendTbMsgToRuleEngine(ctx.assetCreatedMsg(savedAsset, ctx.getSelfId())); | 206 | + ctx.enqueue(ctx.assetCreatedMsg(savedAsset, ctx.getSelfId()), |
207 | + () -> log.trace("Pushed Asset Created message: {}", savedAsset), | ||
208 | + throwable -> log.warn("Failed to push Asset Created message: {}", savedAsset, throwable)); | ||
205 | targetEntity.setEntityId(savedAsset.getId()); | 209 | targetEntity.setEntityId(savedAsset.getId()); |
206 | } | 210 | } |
207 | break; | 211 | break; |
@@ -215,7 +219,9 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | @@ -215,7 +219,9 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | ||
215 | newCustomer.setTitle(entitykey.getEntityName()); | 219 | newCustomer.setTitle(entitykey.getEntityName()); |
216 | newCustomer.setTenantId(ctx.getTenantId()); | 220 | newCustomer.setTenantId(ctx.getTenantId()); |
217 | Customer savedCustomer = customerService.saveCustomer(newCustomer); | 221 | Customer savedCustomer = customerService.saveCustomer(newCustomer); |
218 | - ctx.sendTbMsgToRuleEngine(ctx.customerCreatedMsg(savedCustomer, ctx.getSelfId())); | 222 | + ctx.enqueue(ctx.customerCreatedMsg(savedCustomer, ctx.getSelfId()), |
223 | + () -> log.trace("Pushed Customer Created message: {}", savedCustomer), | ||
224 | + throwable -> log.warn("Failed to push Customer Created message: {}", savedCustomer, throwable)); | ||
219 | targetEntity.setEntityId(savedCustomer.getId()); | 225 | targetEntity.setEntityId(savedCustomer.getId()); |
220 | } | 226 | } |
221 | break; | 227 | break; |
@@ -68,7 +68,7 @@ public class TbMsgCountNode implements TbNode { | @@ -68,7 +68,7 @@ public class TbMsgCountNode implements TbNode { | ||
68 | public void onMsg(TbContext ctx, TbMsg msg) { | 68 | public void onMsg(TbContext ctx, TbMsg msg) { |
69 | if (msg.getType().equals(TB_MSG_COUNT_NODE_MSG) && msg.getId().equals(nextTickId)) { | 69 | if (msg.getType().equals(TB_MSG_COUNT_NODE_MSG) && msg.getId().equals(nextTickId)) { |
70 | JsonObject telemetryJson = new JsonObject(); | 70 | JsonObject telemetryJson = new JsonObject(); |
71 | - telemetryJson.addProperty(this.telemetryPrefix + "_" + ctx.getNodeId(), messagesProcessed.longValue()); | 71 | + telemetryJson.addProperty(this.telemetryPrefix + "_" + ctx.getServiceId(), messagesProcessed.longValue()); |
72 | 72 | ||
73 | messagesProcessed = new AtomicLong(0); | 73 | messagesProcessed = new AtomicLong(0); |
74 | 74 | ||
@@ -76,11 +76,12 @@ public class TbMsgCountNode implements TbNode { | @@ -76,11 +76,12 @@ public class TbMsgCountNode implements TbNode { | ||
76 | metaData.putValue("delta", Long.toString(System.currentTimeMillis() - lastScheduledTs + delay)); | 76 | metaData.putValue("delta", Long.toString(System.currentTimeMillis() - lastScheduledTs + delay)); |
77 | 77 | ||
78 | //TODO 2.5: Callback? | 78 | //TODO 2.5: Callback? |
79 | - TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), SessionMsgType.POST_TELEMETRY_REQUEST.name(), ctx.getTenantId(), metaData, TbMsgDataType.JSON, gson.toJson(telemetryJson), null, null, null); | ||
80 | - ctx.tellNext(tbMsg, SUCCESS); | 79 | + TbMsg tbMsg = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), ctx.getTenantId(), metaData, gson.toJson(telemetryJson)); |
80 | + ctx.enqueueForTellNext(tbMsg, SUCCESS, null, null); | ||
81 | scheduleTickMsg(ctx); | 81 | scheduleTickMsg(ctx); |
82 | } else { | 82 | } else { |
83 | messagesProcessed.incrementAndGet(); | 83 | messagesProcessed.incrementAndGet(); |
84 | + ctx.ack(msg); | ||
84 | } | 85 | } |
85 | } | 86 | } |
86 | 87 |
@@ -73,7 +73,7 @@ public class TbMsgDelayNode implements TbNode { | @@ -73,7 +73,7 @@ public class TbMsgDelayNode implements TbNode { | ||
73 | TbMsg tickMsg = ctx.newMsg(TB_MSG_DELAY_NODE_MSG, ctx.getSelfId(), new TbMsgMetaData(), msg.getId().toString()); | 73 | TbMsg tickMsg = ctx.newMsg(TB_MSG_DELAY_NODE_MSG, ctx.getSelfId(), new TbMsgMetaData(), msg.getId().toString()); |
74 | ctx.tellSelf(tickMsg, getDelay(msg)); | 74 | ctx.tellSelf(tickMsg, getDelay(msg)); |
75 | } else { | 75 | } else { |
76 | - ctx.tellNext(msg, FAILURE, new RuntimeException("Max limit of pending messages reached!")); | 76 | + ctx.tellFailure(msg, new RuntimeException("Max limit of pending messages reached!")); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | } | 79 | } |
@@ -66,7 +66,7 @@ public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofe | @@ -66,7 +66,7 @@ public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofe | ||
66 | EntityGeofencingState entityState = entityStates.computeIfAbsent(msg.getOriginator(), key -> { | 66 | EntityGeofencingState entityState = entityStates.computeIfAbsent(msg.getOriginator(), key -> { |
67 | try { | 67 | try { |
68 | Optional<AttributeKvEntry> entry = ctx.getAttributesService() | 68 | Optional<AttributeKvEntry> entry = ctx.getAttributesService() |
69 | - .find(ctx.getTenantId(), msg.getOriginator(), DataConstants.SERVER_SCOPE, ctx.getNodeId()) | 69 | + .find(ctx.getTenantId(), msg.getOriginator(), DataConstants.SERVER_SCOPE, ctx.getServiceId()) |
70 | .get(1, TimeUnit.MINUTES); | 70 | .get(1, TimeUnit.MINUTES); |
71 | if (entry.isPresent()) { | 71 | if (entry.isPresent()) { |
72 | JsonObject element = parser.parse(entry.get().getValueAsString()).getAsJsonObject(); | 72 | JsonObject element = parser.parse(entry.get().getValueAsString()).getAsJsonObject(); |
@@ -108,7 +108,7 @@ public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofe | @@ -108,7 +108,7 @@ public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofe | ||
108 | object.addProperty("inside", entityState.isInside()); | 108 | object.addProperty("inside", entityState.isInside()); |
109 | object.addProperty("stateSwitchTime", entityState.getStateSwitchTime()); | 109 | object.addProperty("stateSwitchTime", entityState.getStateSwitchTime()); |
110 | object.addProperty("stayed", entityState.isStayed()); | 110 | object.addProperty("stayed", entityState.isStayed()); |
111 | - AttributeKvEntry entry = new BaseAttributeKvEntry(new StringDataEntry(ctx.getNodeId(), gson.toJson(object)), System.currentTimeMillis()); | 111 | + AttributeKvEntry entry = new BaseAttributeKvEntry(new StringDataEntry(ctx.getServiceId(), gson.toJson(object)), System.currentTimeMillis()); |
112 | List<AttributeKvEntry> attributeKvEntryList = Collections.singletonList(entry); | 112 | List<AttributeKvEntry> attributeKvEntryList = Collections.singletonList(entry); |
113 | ctx.getAttributesService().save(ctx.getTenantId(), entityId, DataConstants.SERVER_SCOPE, attributeKvEntryList); | 113 | ctx.getAttributesService().save(ctx.getTenantId(), entityId, DataConstants.SERVER_SCOPE, attributeKvEntryList); |
114 | } | 114 | } |
@@ -25,7 +25,6 @@ import org.thingsboard.server.common.msg.TbMsgMetaData; | @@ -25,7 +25,6 @@ import org.thingsboard.server.common.msg.TbMsgMetaData; | ||
25 | 25 | ||
26 | import java.util.Properties; | 26 | import java.util.Properties; |
27 | import java.util.concurrent.ExecutionException; | 27 | import java.util.concurrent.ExecutionException; |
28 | -import java.util.concurrent.atomic.AtomicInteger; | ||
29 | 28 | ||
30 | @Slf4j | 29 | @Slf4j |
31 | @RuleNode( | 30 | @RuleNode( |
@@ -55,7 +54,7 @@ public class TbKafkaNode implements TbNode { | @@ -55,7 +54,7 @@ public class TbKafkaNode implements TbNode { | ||
55 | public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { | 54 | public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { |
56 | this.config = TbNodeUtils.convert(configuration, TbKafkaNodeConfiguration.class); | 55 | this.config = TbNodeUtils.convert(configuration, TbKafkaNodeConfiguration.class); |
57 | Properties properties = new Properties(); | 56 | Properties properties = new Properties(); |
58 | - properties.put(ProducerConfig.CLIENT_ID_CONFIG, "producer-tb-kafka-node-" + ctx.getSelfId().getId().toString() + "-" + ctx.getNodeId()); | 57 | + properties.put(ProducerConfig.CLIENT_ID_CONFIG, "producer-tb-kafka-node-" + ctx.getSelfId().getId().toString() + "-" + ctx.getServiceId()); |
59 | properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, config.getBootstrapServers()); | 58 | properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, config.getBootstrapServers()); |
60 | properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, config.getValueSerializer()); | 59 | properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, config.getValueSerializer()); |
61 | properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, config.getKeySerializer()); | 60 | properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, config.getKeySerializer()); |
@@ -105,7 +105,7 @@ class TbRedisQueueProcessor { | @@ -105,7 +105,7 @@ class TbRedisQueueProcessor { | ||
105 | } | 105 | } |
106 | 106 | ||
107 | private String constructRedisKey() { | 107 | private String constructRedisKey() { |
108 | - return ctx.getServerAddress() + ctx.getSelfId(); | 108 | + return ctx.getServiceId() + ctx.getSelfId(); |
109 | } | 109 | } |
110 | 110 | ||
111 | private int validateMaxQueueSize() { | 111 | private int validateMaxQueueSize() { |
@@ -58,8 +58,7 @@ public class TbSynchronizationBeginNode implements TbNode { | @@ -58,8 +58,7 @@ public class TbSynchronizationBeginNode implements TbNode { | ||
58 | 58 | ||
59 | TbMsgTransactionData transactionData = new TbMsgTransactionData(msg.getId(), msg.getOriginator()); | 59 | TbMsgTransactionData transactionData = new TbMsgTransactionData(msg.getId(), msg.getOriginator()); |
60 | //TODO 2.5: Callback? | 60 | //TODO 2.5: Callback? |
61 | - TbMsg tbMsg = new TbMsg(msg.getId(), msg.getType(), msg.getOriginator(), msg.getMetaData(), TbMsgDataType.JSON, | ||
62 | - msg.getData(), transactionData, msg.getRuleChainId(), msg.getRuleNodeId(), null); | 61 | + TbMsg tbMsg = TbMsg.transformMsg(msg, msg.getType(), msg.getOriginator(), msg.getMetaData(), msg.getData()); |
63 | 62 | ||
64 | ctx.getRuleChainTransactionService().beginTransaction(tbMsg, startMsg -> { | 63 | ctx.getRuleChainTransactionService().beginTransaction(tbMsg, startMsg -> { |
65 | log.trace("Transaction starting...[{}][{}]", startMsg.getId(), startMsg.getType()); | 64 | log.trace("Transaction starting...[{}][{}]", startMsg.getId(), startMsg.getType()); |
@@ -101,7 +101,7 @@ public class TbAlarmNodeTest { | @@ -101,7 +101,7 @@ public class TbAlarmNodeTest { | ||
101 | public void newAlarmCanBeCreated() throws ScriptException, IOException { | 101 | public void newAlarmCanBeCreated() throws ScriptException, IOException { |
102 | initWithCreateAlarmScript(); | 102 | initWithCreateAlarmScript(); |
103 | metaData.putValue("key", "value"); | 103 | metaData.putValue("key", "value"); |
104 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId, null); | 104 | + TbMsg msg = TbMsg.newMsg("USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); |
105 | 105 | ||
106 | when(detailsJs.executeJsonAsync(msg)).thenReturn(Futures.immediateFuture(null)); | 106 | when(detailsJs.executeJsonAsync(msg)).thenReturn(Futures.immediateFuture(null)); |
107 | when(alarmService.findLatestByOriginatorAndType(tenantId, originator, "SomeType")).thenReturn(Futures.immediateFuture(null)); | 107 | when(alarmService.findLatestByOriginatorAndType(tenantId, originator, "SomeType")).thenReturn(Futures.immediateFuture(null)); |
@@ -143,7 +143,7 @@ public class TbAlarmNodeTest { | @@ -143,7 +143,7 @@ public class TbAlarmNodeTest { | ||
143 | public void buildDetailsThrowsException() throws ScriptException, IOException { | 143 | public void buildDetailsThrowsException() throws ScriptException, IOException { |
144 | initWithCreateAlarmScript(); | 144 | initWithCreateAlarmScript(); |
145 | metaData.putValue("key", "value"); | 145 | metaData.putValue("key", "value"); |
146 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId, null); | 146 | + TbMsg msg = TbMsg.newMsg("USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); |
147 | 147 | ||
148 | when(detailsJs.executeJsonAsync(msg)).thenReturn(Futures.immediateFailedFuture(new NotImplementedException("message"))); | 148 | when(detailsJs.executeJsonAsync(msg)).thenReturn(Futures.immediateFailedFuture(new NotImplementedException("message"))); |
149 | when(alarmService.findLatestByOriginatorAndType(tenantId, originator, "SomeType")).thenReturn(Futures.immediateFuture(null)); | 149 | when(alarmService.findLatestByOriginatorAndType(tenantId, originator, "SomeType")).thenReturn(Futures.immediateFuture(null)); |
@@ -166,7 +166,7 @@ public class TbAlarmNodeTest { | @@ -166,7 +166,7 @@ public class TbAlarmNodeTest { | ||
166 | public void ifAlarmClearedCreateNew() throws ScriptException, IOException { | 166 | public void ifAlarmClearedCreateNew() throws ScriptException, IOException { |
167 | initWithCreateAlarmScript(); | 167 | initWithCreateAlarmScript(); |
168 | metaData.putValue("key", "value"); | 168 | metaData.putValue("key", "value"); |
169 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId, null); | 169 | + TbMsg msg = TbMsg.newMsg("USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); |
170 | 170 | ||
171 | Alarm clearedAlarm = Alarm.builder().status(CLEARED_ACK).build(); | 171 | Alarm clearedAlarm = Alarm.builder().status(CLEARED_ACK).build(); |
172 | 172 | ||
@@ -211,7 +211,7 @@ public class TbAlarmNodeTest { | @@ -211,7 +211,7 @@ public class TbAlarmNodeTest { | ||
211 | public void alarmCanBeUpdated() throws ScriptException, IOException { | 211 | public void alarmCanBeUpdated() throws ScriptException, IOException { |
212 | initWithCreateAlarmScript(); | 212 | initWithCreateAlarmScript(); |
213 | metaData.putValue("key", "value"); | 213 | metaData.putValue("key", "value"); |
214 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId, null); | 214 | + TbMsg msg = TbMsg.newMsg("USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); |
215 | 215 | ||
216 | long oldEndDate = System.currentTimeMillis(); | 216 | long oldEndDate = System.currentTimeMillis(); |
217 | Alarm activeAlarm = Alarm.builder().type("SomeType").tenantId(tenantId).originator(originator).status(ACTIVE_UNACK).severity(WARNING).endTs(oldEndDate).build(); | 217 | Alarm activeAlarm = Alarm.builder().type("SomeType").tenantId(tenantId).originator(originator).status(ACTIVE_UNACK).severity(WARNING).endTs(oldEndDate).build(); |
@@ -258,7 +258,7 @@ public class TbAlarmNodeTest { | @@ -258,7 +258,7 @@ public class TbAlarmNodeTest { | ||
258 | public void alarmCanBeCleared() throws ScriptException, IOException { | 258 | public void alarmCanBeCleared() throws ScriptException, IOException { |
259 | initWithClearAlarmScript(); | 259 | initWithClearAlarmScript(); |
260 | metaData.putValue("key", "value"); | 260 | metaData.putValue("key", "value"); |
261 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId, null); | 261 | + TbMsg msg = TbMsg.newMsg( "USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); |
262 | 262 | ||
263 | long oldEndDate = System.currentTimeMillis(); | 263 | long oldEndDate = System.currentTimeMillis(); |
264 | Alarm activeAlarm = Alarm.builder().type("SomeType").tenantId(tenantId).originator(originator).status(ACTIVE_UNACK).severity(WARNING).endTs(oldEndDate).build(); | 264 | Alarm activeAlarm = Alarm.builder().type("SomeType").tenantId(tenantId).originator(originator).status(ACTIVE_UNACK).severity(WARNING).endTs(oldEndDate).build(); |
@@ -59,7 +59,7 @@ public class TbJsFilterNodeTest { | @@ -59,7 +59,7 @@ public class TbJsFilterNodeTest { | ||
59 | @Test | 59 | @Test |
60 | public void falseEvaluationDoNotSendMsg() throws TbNodeException, ScriptException { | 60 | public void falseEvaluationDoNotSendMsg() throws TbNodeException, ScriptException { |
61 | initWithScript(); | 61 | initWithScript(); |
62 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 62 | + TbMsg msg = TbMsg.newMsg("USER", null, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
63 | mockJsExecutor(); | 63 | mockJsExecutor(); |
64 | when(scriptEngine.executeFilterAsync(msg)).thenReturn(Futures.immediateFuture(false)); | 64 | when(scriptEngine.executeFilterAsync(msg)).thenReturn(Futures.immediateFuture(false)); |
65 | 65 | ||
@@ -72,7 +72,7 @@ public class TbJsFilterNodeTest { | @@ -72,7 +72,7 @@ public class TbJsFilterNodeTest { | ||
72 | public void exceptionInJsThrowsException() throws TbNodeException, ScriptException { | 72 | public void exceptionInJsThrowsException() throws TbNodeException, ScriptException { |
73 | initWithScript(); | 73 | initWithScript(); |
74 | TbMsgMetaData metaData = new TbMsgMetaData(); | 74 | TbMsgMetaData metaData = new TbMsgMetaData(); |
75 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 75 | + TbMsg msg = TbMsg.newMsg("USER", null, metaData, TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
76 | mockJsExecutor(); | 76 | mockJsExecutor(); |
77 | when(scriptEngine.executeFilterAsync(msg)).thenReturn(Futures.immediateFailedFuture(new ScriptException("error"))); | 77 | when(scriptEngine.executeFilterAsync(msg)).thenReturn(Futures.immediateFailedFuture(new ScriptException("error"))); |
78 | 78 | ||
@@ -85,7 +85,7 @@ public class TbJsFilterNodeTest { | @@ -85,7 +85,7 @@ public class TbJsFilterNodeTest { | ||
85 | public void metadataConditionCanBeTrue() throws TbNodeException, ScriptException { | 85 | public void metadataConditionCanBeTrue() throws TbNodeException, ScriptException { |
86 | initWithScript(); | 86 | initWithScript(); |
87 | TbMsgMetaData metaData = new TbMsgMetaData(); | 87 | TbMsgMetaData metaData = new TbMsgMetaData(); |
88 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 88 | + TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
89 | mockJsExecutor(); | 89 | mockJsExecutor(); |
90 | when(scriptEngine.executeFilterAsync(msg)).thenReturn(Futures.immediateFuture(true)); | 90 | when(scriptEngine.executeFilterAsync(msg)).thenReturn(Futures.immediateFuture(true)); |
91 | 91 |
@@ -66,7 +66,7 @@ public class TbJsSwitchNodeTest { | @@ -66,7 +66,7 @@ public class TbJsSwitchNodeTest { | ||
66 | metaData.putValue("humidity", "99"); | 66 | metaData.putValue("humidity", "99"); |
67 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5}"; | 67 | String rawJson = "{\"name\": \"Vit\", \"passed\": 5}"; |
68 | 68 | ||
69 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId, null); | 69 | + TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); |
70 | mockJsExecutor(); | 70 | mockJsExecutor(); |
71 | when(scriptEngine.executeSwitch(msg)).thenReturn(Sets.newHashSet("one", "three")); | 71 | when(scriptEngine.executeSwitch(msg)).thenReturn(Sets.newHashSet("one", "three")); |
72 | 72 |
@@ -63,7 +63,7 @@ public class TbMsgToEmailNodeTest { | @@ -63,7 +63,7 @@ public class TbMsgToEmailNodeTest { | ||
63 | metaData.putValue("name", "temp"); | 63 | metaData.putValue("name", "temp"); |
64 | metaData.putValue("passed", "5"); | 64 | metaData.putValue("passed", "5"); |
65 | metaData.putValue("count", "100"); | 65 | metaData.putValue("count", "100"); |
66 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId, null); | 66 | + TbMsg msg = TbMsg.newMsg( "USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); |
67 | 67 | ||
68 | emailNode.onMsg(ctx, msg); | 68 | emailNode.onMsg(ctx, msg); |
69 | 69 |
@@ -103,7 +103,7 @@ public class TbGetCustomerAttributeNodeTest { | @@ -103,7 +103,7 @@ public class TbGetCustomerAttributeNodeTest { | ||
103 | User user = new User(); | 103 | User user = new User(); |
104 | user.setCustomerId(customerId); | 104 | user.setCustomerId(customerId); |
105 | 105 | ||
106 | - msg = new TbMsg(UUIDs.timeBased(), "USER", userId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 106 | + msg = TbMsg.newMsg( "USER", userId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
107 | 107 | ||
108 | when(ctx.getUserService()).thenReturn(userService); | 108 | when(ctx.getUserService()).thenReturn(userService); |
109 | when(userService.findUserByIdAsync(any(), eq(userId))).thenReturn(Futures.immediateFuture(user)); | 109 | when(userService.findUserByIdAsync(any(), eq(userId))).thenReturn(Futures.immediateFuture(user)); |
@@ -128,7 +128,7 @@ public class TbGetCustomerAttributeNodeTest { | @@ -128,7 +128,7 @@ public class TbGetCustomerAttributeNodeTest { | ||
128 | User user = new User(); | 128 | User user = new User(); |
129 | user.setCustomerId(customerId); | 129 | user.setCustomerId(customerId); |
130 | 130 | ||
131 | - msg = new TbMsg(UUIDs.timeBased(), "USER", userId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 131 | + msg = TbMsg.newMsg( "USER", userId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
132 | 132 | ||
133 | when(ctx.getUserService()).thenReturn(userService); | 133 | when(ctx.getUserService()).thenReturn(userService); |
134 | when(userService.findUserByIdAsync(any(), eq(userId))).thenReturn(Futures.immediateFuture(user)); | 134 | when(userService.findUserByIdAsync(any(), eq(userId))).thenReturn(Futures.immediateFuture(user)); |
@@ -153,7 +153,7 @@ public class TbGetCustomerAttributeNodeTest { | @@ -153,7 +153,7 @@ public class TbGetCustomerAttributeNodeTest { | ||
153 | User user = new User(); | 153 | User user = new User(); |
154 | user.setCustomerId(customerId); | 154 | user.setCustomerId(customerId); |
155 | 155 | ||
156 | - msg = new TbMsg(UUIDs.timeBased(), "USER", userId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId, null); | 156 | + msg = TbMsg.newMsg( "USER", userId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId); |
157 | 157 | ||
158 | when(ctx.getUserService()).thenReturn(userService); | 158 | when(ctx.getUserService()).thenReturn(userService); |
159 | when(userService.findUserByIdAsync(any(), eq(userId))).thenReturn(Futures.immediateFuture(null)); | 159 | when(userService.findUserByIdAsync(any(), eq(userId))).thenReturn(Futures.immediateFuture(null)); |
@@ -167,7 +167,7 @@ public class TbGetCustomerAttributeNodeTest { | @@ -167,7 +167,7 @@ public class TbGetCustomerAttributeNodeTest { | ||
167 | @Test | 167 | @Test |
168 | public void customerAttributeAddedInMetadata() { | 168 | public void customerAttributeAddedInMetadata() { |
169 | CustomerId customerId = new CustomerId(UUIDs.timeBased()); | 169 | CustomerId customerId = new CustomerId(UUIDs.timeBased()); |
170 | - msg = new TbMsg(UUIDs.timeBased(), "CUSTOMER", customerId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 170 | + msg = TbMsg.newMsg( "CUSTOMER", customerId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
171 | entityAttributeFetched(customerId); | 171 | entityAttributeFetched(customerId); |
172 | } | 172 | } |
173 | 173 | ||
@@ -178,7 +178,7 @@ public class TbGetCustomerAttributeNodeTest { | @@ -178,7 +178,7 @@ public class TbGetCustomerAttributeNodeTest { | ||
178 | User user = new User(); | 178 | User user = new User(); |
179 | user.setCustomerId(customerId); | 179 | user.setCustomerId(customerId); |
180 | 180 | ||
181 | - msg = new TbMsg(UUIDs.timeBased(), "USER", userId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 181 | + msg = TbMsg.newMsg( "USER", userId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
182 | 182 | ||
183 | when(ctx.getUserService()).thenReturn(userService); | 183 | when(ctx.getUserService()).thenReturn(userService); |
184 | when(userService.findUserByIdAsync(any(), eq(userId))).thenReturn(Futures.immediateFuture(user)); | 184 | when(userService.findUserByIdAsync(any(), eq(userId))).thenReturn(Futures.immediateFuture(user)); |
@@ -193,7 +193,7 @@ public class TbGetCustomerAttributeNodeTest { | @@ -193,7 +193,7 @@ public class TbGetCustomerAttributeNodeTest { | ||
193 | Asset asset = new Asset(); | 193 | Asset asset = new Asset(); |
194 | asset.setCustomerId(customerId); | 194 | asset.setCustomerId(customerId); |
195 | 195 | ||
196 | - msg = new TbMsg(UUIDs.timeBased(), "USER", assetId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 196 | + msg = TbMsg.newMsg( "USER", assetId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
197 | 197 | ||
198 | when(ctx.getAssetService()).thenReturn(assetService); | 198 | when(ctx.getAssetService()).thenReturn(assetService); |
199 | when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(asset)); | 199 | when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(asset)); |
@@ -208,7 +208,7 @@ public class TbGetCustomerAttributeNodeTest { | @@ -208,7 +208,7 @@ public class TbGetCustomerAttributeNodeTest { | ||
208 | Device device = new Device(); | 208 | Device device = new Device(); |
209 | device.setCustomerId(customerId); | 209 | device.setCustomerId(customerId); |
210 | 210 | ||
211 | - msg = new TbMsg(UUIDs.timeBased(), "USER", deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 211 | + msg = TbMsg.newMsg( "USER", deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
212 | 212 | ||
213 | when(ctx.getDeviceService()).thenReturn(deviceService); | 213 | when(ctx.getDeviceService()).thenReturn(deviceService); |
214 | when(deviceService.findDeviceByIdAsync(any(), eq(deviceId))).thenReturn(Futures.immediateFuture(device)); | 214 | when(deviceService.findDeviceByIdAsync(any(), eq(deviceId))).thenReturn(Futures.immediateFuture(device)); |
@@ -235,7 +235,7 @@ public class TbGetCustomerAttributeNodeTest { | @@ -235,7 +235,7 @@ public class TbGetCustomerAttributeNodeTest { | ||
235 | Device device = new Device(); | 235 | Device device = new Device(); |
236 | device.setCustomerId(customerId); | 236 | device.setCustomerId(customerId); |
237 | 237 | ||
238 | - msg = new TbMsg(UUIDs.timeBased(), "USER", deviceId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId, null); | 238 | + msg = TbMsg.newMsg( "USER", deviceId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId); |
239 | 239 | ||
240 | when(ctx.getDeviceService()).thenReturn(deviceService); | 240 | when(ctx.getDeviceService()).thenReturn(deviceService); |
241 | when(deviceService.findDeviceByIdAsync(any(), eq(deviceId))).thenReturn(Futures.immediateFuture(device)); | 241 | when(deviceService.findDeviceByIdAsync(any(), eq(deviceId))).thenReturn(Futures.immediateFuture(device)); |
@@ -92,7 +92,7 @@ public class TbChangeOriginatorNodeTest { | @@ -92,7 +92,7 @@ public class TbChangeOriginatorNodeTest { | ||
92 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); | 92 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); |
93 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); | 93 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); |
94 | 94 | ||
95 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId, null); | 95 | + TbMsg msg = TbMsg.newMsg( "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId); |
96 | 96 | ||
97 | when(ctx.getAssetService()).thenReturn(assetService); | 97 | when(ctx.getAssetService()).thenReturn(assetService); |
98 | when(assetService.findAssetByIdAsync(any(),eq( assetId))).thenReturn(Futures.immediateFuture(asset)); | 98 | when(assetService.findAssetByIdAsync(any(),eq( assetId))).thenReturn(Futures.immediateFuture(asset)); |
@@ -120,7 +120,7 @@ public class TbChangeOriginatorNodeTest { | @@ -120,7 +120,7 @@ public class TbChangeOriginatorNodeTest { | ||
120 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); | 120 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); |
121 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); | 121 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); |
122 | 122 | ||
123 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId, null); | 123 | + TbMsg msg = TbMsg.newMsg( "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId); |
124 | 124 | ||
125 | when(ctx.getAssetService()).thenReturn(assetService); | 125 | when(ctx.getAssetService()).thenReturn(assetService); |
126 | when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(asset)); | 126 | when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(asset)); |
@@ -147,7 +147,7 @@ public class TbChangeOriginatorNodeTest { | @@ -147,7 +147,7 @@ public class TbChangeOriginatorNodeTest { | ||
147 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); | 147 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); |
148 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); | 148 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); |
149 | 149 | ||
150 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId, null); | 150 | + TbMsg msg = TbMsg.newMsg( "ASSET", assetId, new TbMsgMetaData(), TbMsgDataType.JSON,"{}", ruleChainId, ruleNodeId); |
151 | 151 | ||
152 | when(ctx.getAssetService()).thenReturn(assetService); | 152 | when(ctx.getAssetService()).thenReturn(assetService); |
153 | when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(null)); | 153 | when(assetService.findAssetByIdAsync(any(), eq(assetId))).thenReturn(Futures.immediateFuture(null)); |
@@ -63,8 +63,8 @@ public class TbTransformMsgNodeTest { | @@ -63,8 +63,8 @@ public class TbTransformMsgNodeTest { | ||
63 | 63 | ||
64 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); | 64 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); |
65 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); | 65 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); |
66 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON,rawJson, ruleChainId, ruleNodeId, null); | ||
67 | - TbMsg transformedMsg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, "{new}", ruleChainId, ruleNodeId, null); | 66 | + TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON,rawJson, ruleChainId, ruleNodeId); |
67 | + TbMsg transformedMsg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, "{new}", ruleChainId, ruleNodeId); | ||
68 | mockJsExecutor(); | 68 | mockJsExecutor(); |
69 | when(scriptEngine.executeUpdateAsync(msg)).thenReturn(Futures.immediateFuture(transformedMsg)); | 69 | when(scriptEngine.executeUpdateAsync(msg)).thenReturn(Futures.immediateFuture(transformedMsg)); |
70 | 70 | ||
@@ -85,7 +85,7 @@ public class TbTransformMsgNodeTest { | @@ -85,7 +85,7 @@ public class TbTransformMsgNodeTest { | ||
85 | 85 | ||
86 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); | 86 | RuleChainId ruleChainId = new RuleChainId(UUIDs.timeBased()); |
87 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); | 87 | RuleNodeId ruleNodeId = new RuleNodeId(UUIDs.timeBased()); |
88 | - TbMsg msg = new TbMsg(UUIDs.timeBased(), "USER", null, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId, null); | 88 | + TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); |
89 | mockJsExecutor(); | 89 | mockJsExecutor(); |
90 | when(scriptEngine.executeUpdateAsync(msg)).thenReturn(Futures.immediateFailedFuture(new IllegalStateException("error"))); | 90 | when(scriptEngine.executeUpdateAsync(msg)).thenReturn(Futures.immediateFailedFuture(new IllegalStateException("error"))); |
91 | 91 |