Commit a52b88802bf466fd045348067f92ca23d66e4629
1 parent
b63087d5
Use default rule chain and queue from device profile in edge session
Showing
4 changed files
with
68 additions
and
28 deletions
@@ -552,12 +552,6 @@ public final class EdgeGrpcSession implements Closeable { | @@ -552,12 +552,6 @@ public final class EdgeGrpcSession implements Closeable { | ||
552 | case UPDATED: | 552 | case UPDATED: |
553 | DeviceProfile deviceProfile = ctx.getDeviceProfileService().findDeviceProfileById(edgeEvent.getTenantId(), deviceProfileId); | 553 | DeviceProfile deviceProfile = ctx.getDeviceProfileService().findDeviceProfileById(edgeEvent.getTenantId(), deviceProfileId); |
554 | if (deviceProfile != null) { | 554 | if (deviceProfile != null) { |
555 | - | ||
556 | - // TODO: voba HACK | ||
557 | -// PageData<RuleChain> ruleChainsByTenantIdAndEdgeId = ctx.getRuleChainService().findRuleChainsByTenantIdAndEdgeId(edgeEvent.getTenantId(), edgeEvent.getEdgeId(), new TimePageLink(100)); | ||
558 | -// RuleChain ruleChain = ruleChainsByTenantIdAndEdgeId.getData().get(0); | ||
559 | -// deviceProfile.setDefaultRuleChainId(ruleChain.getId()); | ||
560 | - | ||
561 | DeviceProfileUpdateMsg deviceProfileUpdateMsg = | 555 | DeviceProfileUpdateMsg deviceProfileUpdateMsg = |
562 | ctx.getDeviceProfileMsgConstructor().constructDeviceProfileUpdatedMsg(msgType, deviceProfile); | 556 | ctx.getDeviceProfileMsgConstructor().constructDeviceProfileUpdatedMsg(msgType, deviceProfile); |
563 | downlinkMsg = DownlinkMsg.newBuilder() | 557 | downlinkMsg = DownlinkMsg.newBuilder() |
@@ -916,57 +910,57 @@ public final class EdgeGrpcSession implements Closeable { | @@ -916,57 +910,57 @@ public final class EdgeGrpcSession implements Closeable { | ||
916 | private ListenableFuture<List<Void>> processUplinkMsg(UplinkMsg uplinkMsg) { | 910 | private ListenableFuture<List<Void>> processUplinkMsg(UplinkMsg uplinkMsg) { |
917 | List<ListenableFuture<Void>> result = new ArrayList<>(); | 911 | List<ListenableFuture<Void>> result = new ArrayList<>(); |
918 | try { | 912 | try { |
919 | - if (uplinkMsg.getEntityDataList() != null && !uplinkMsg.getEntityDataList().isEmpty()) { | 913 | + if (uplinkMsg.getEntityDataCount() > 0) { |
920 | for (EntityDataProto entityData : uplinkMsg.getEntityDataList()) { | 914 | for (EntityDataProto entityData : uplinkMsg.getEntityDataList()) { |
921 | result.addAll(ctx.getTelemetryProcessor().onTelemetryUpdate(edge.getTenantId(), entityData)); | 915 | result.addAll(ctx.getTelemetryProcessor().onTelemetryUpdate(edge.getTenantId(), entityData)); |
922 | } | 916 | } |
923 | } | 917 | } |
924 | - if (uplinkMsg.getDeviceUpdateMsgList() != null && !uplinkMsg.getDeviceUpdateMsgList().isEmpty()) { | 918 | + if (uplinkMsg.getDeviceUpdateMsgCount() > 0) { |
925 | for (DeviceUpdateMsg deviceUpdateMsg : uplinkMsg.getDeviceUpdateMsgList()) { | 919 | for (DeviceUpdateMsg deviceUpdateMsg : uplinkMsg.getDeviceUpdateMsgList()) { |
926 | result.add(ctx.getDeviceProcessor().onDeviceUpdate(edge.getTenantId(), edge, deviceUpdateMsg)); | 920 | result.add(ctx.getDeviceProcessor().onDeviceUpdate(edge.getTenantId(), edge, deviceUpdateMsg)); |
927 | } | 921 | } |
928 | } | 922 | } |
929 | - if (uplinkMsg.getDeviceCredentialsUpdateMsgList() != null && !uplinkMsg.getDeviceCredentialsUpdateMsgList().isEmpty()) { | 923 | + if (uplinkMsg.getDeviceCredentialsUpdateMsgCount() > 0) { |
930 | for (DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg : uplinkMsg.getDeviceCredentialsUpdateMsgList()) { | 924 | for (DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg : uplinkMsg.getDeviceCredentialsUpdateMsgList()) { |
931 | result.add(ctx.getDeviceProcessor().onDeviceCredentialsUpdate(edge.getTenantId(), deviceCredentialsUpdateMsg)); | 925 | result.add(ctx.getDeviceProcessor().onDeviceCredentialsUpdate(edge.getTenantId(), deviceCredentialsUpdateMsg)); |
932 | } | 926 | } |
933 | } | 927 | } |
934 | - if (uplinkMsg.getAlarmUpdateMsgList() != null && !uplinkMsg.getAlarmUpdateMsgList().isEmpty()) { | 928 | + if (uplinkMsg.getAlarmUpdateMsgCount() > 0) { |
935 | for (AlarmUpdateMsg alarmUpdateMsg : uplinkMsg.getAlarmUpdateMsgList()) { | 929 | for (AlarmUpdateMsg alarmUpdateMsg : uplinkMsg.getAlarmUpdateMsgList()) { |
936 | result.add(ctx.getAlarmProcessor().onAlarmUpdate(edge.getTenantId(), alarmUpdateMsg)); | 930 | result.add(ctx.getAlarmProcessor().onAlarmUpdate(edge.getTenantId(), alarmUpdateMsg)); |
937 | } | 931 | } |
938 | } | 932 | } |
939 | - if (uplinkMsg.getRelationUpdateMsgList() != null && !uplinkMsg.getRelationUpdateMsgList().isEmpty()) { | 933 | + if (uplinkMsg.getRelationUpdateMsgCount() > 0) { |
940 | for (RelationUpdateMsg relationUpdateMsg : uplinkMsg.getRelationUpdateMsgList()) { | 934 | for (RelationUpdateMsg relationUpdateMsg : uplinkMsg.getRelationUpdateMsgList()) { |
941 | result.add(ctx.getRelationProcessor().onRelationUpdate(edge.getTenantId(), relationUpdateMsg)); | 935 | result.add(ctx.getRelationProcessor().onRelationUpdate(edge.getTenantId(), relationUpdateMsg)); |
942 | } | 936 | } |
943 | } | 937 | } |
944 | - if (uplinkMsg.getRuleChainMetadataRequestMsgList() != null && !uplinkMsg.getRuleChainMetadataRequestMsgList().isEmpty()) { | 938 | + if (uplinkMsg.getRuleChainMetadataRequestMsgCount() > 0) { |
945 | for (RuleChainMetadataRequestMsg ruleChainMetadataRequestMsg : uplinkMsg.getRuleChainMetadataRequestMsgList()) { | 939 | for (RuleChainMetadataRequestMsg ruleChainMetadataRequestMsg : uplinkMsg.getRuleChainMetadataRequestMsgList()) { |
946 | result.add(ctx.getSyncEdgeService().processRuleChainMetadataRequestMsg(edge, ruleChainMetadataRequestMsg)); | 940 | result.add(ctx.getSyncEdgeService().processRuleChainMetadataRequestMsg(edge, ruleChainMetadataRequestMsg)); |
947 | } | 941 | } |
948 | } | 942 | } |
949 | - if (uplinkMsg.getAttributesRequestMsgList() != null && !uplinkMsg.getAttributesRequestMsgList().isEmpty()) { | 943 | + if (uplinkMsg.getAttributesRequestMsgCount() > 0) { |
950 | for (AttributesRequestMsg attributesRequestMsg : uplinkMsg.getAttributesRequestMsgList()) { | 944 | for (AttributesRequestMsg attributesRequestMsg : uplinkMsg.getAttributesRequestMsgList()) { |
951 | result.add(ctx.getSyncEdgeService().processAttributesRequestMsg(edge, attributesRequestMsg)); | 945 | result.add(ctx.getSyncEdgeService().processAttributesRequestMsg(edge, attributesRequestMsg)); |
952 | } | 946 | } |
953 | } | 947 | } |
954 | - if (uplinkMsg.getRelationRequestMsgList() != null && !uplinkMsg.getRelationRequestMsgList().isEmpty()) { | 948 | + if (uplinkMsg.getRelationRequestMsgCount() > 0) { |
955 | for (RelationRequestMsg relationRequestMsg : uplinkMsg.getRelationRequestMsgList()) { | 949 | for (RelationRequestMsg relationRequestMsg : uplinkMsg.getRelationRequestMsgList()) { |
956 | result.add(ctx.getSyncEdgeService().processRelationRequestMsg(edge, relationRequestMsg)); | 950 | result.add(ctx.getSyncEdgeService().processRelationRequestMsg(edge, relationRequestMsg)); |
957 | } | 951 | } |
958 | } | 952 | } |
959 | - if (uplinkMsg.getUserCredentialsRequestMsgList() != null && !uplinkMsg.getUserCredentialsRequestMsgList().isEmpty()) { | 953 | + if (uplinkMsg.getUserCredentialsRequestMsgCount() > 0) { |
960 | for (UserCredentialsRequestMsg userCredentialsRequestMsg : uplinkMsg.getUserCredentialsRequestMsgList()) { | 954 | for (UserCredentialsRequestMsg userCredentialsRequestMsg : uplinkMsg.getUserCredentialsRequestMsgList()) { |
961 | result.add(ctx.getSyncEdgeService().processUserCredentialsRequestMsg(edge, userCredentialsRequestMsg)); | 955 | result.add(ctx.getSyncEdgeService().processUserCredentialsRequestMsg(edge, userCredentialsRequestMsg)); |
962 | } | 956 | } |
963 | } | 957 | } |
964 | - if (uplinkMsg.getDeviceCredentialsRequestMsgList() != null && !uplinkMsg.getDeviceCredentialsRequestMsgList().isEmpty()) { | 958 | + if (uplinkMsg.getDeviceCredentialsRequestMsgCount() > 0) { |
965 | for (DeviceCredentialsRequestMsg deviceCredentialsRequestMsg : uplinkMsg.getDeviceCredentialsRequestMsgList()) { | 959 | for (DeviceCredentialsRequestMsg deviceCredentialsRequestMsg : uplinkMsg.getDeviceCredentialsRequestMsgList()) { |
966 | result.add(ctx.getSyncEdgeService().processDeviceCredentialsRequestMsg(edge, deviceCredentialsRequestMsg)); | 960 | result.add(ctx.getSyncEdgeService().processDeviceCredentialsRequestMsg(edge, deviceCredentialsRequestMsg)); |
967 | } | 961 | } |
968 | } | 962 | } |
969 | - if (uplinkMsg.getDeviceRpcCallMsgList() != null && !uplinkMsg.getDeviceRpcCallMsgList().isEmpty()) { | 963 | + if (uplinkMsg.getDeviceRpcCallMsgCount() > 0) { |
970 | for (DeviceRpcCallMsg deviceRpcCallMsg : uplinkMsg.getDeviceRpcCallMsgList()) { | 964 | for (DeviceRpcCallMsg deviceRpcCallMsg : uplinkMsg.getDeviceRpcCallMsgList()) { |
971 | result.add(ctx.getDeviceProcessor().processDeviceRpcCallResponseMsg(edge.getTenantId(), deviceRpcCallMsg)); | 965 | result.add(ctx.getDeviceProcessor().processDeviceRpcCallResponseMsg(edge.getTenantId(), deviceRpcCallMsg)); |
972 | } | 966 | } |
@@ -44,13 +44,14 @@ public class DeviceProfileMsgConstructor { | @@ -44,13 +44,14 @@ public class DeviceProfileMsgConstructor { | ||
44 | .setTransportType(deviceProfile.getTransportType().name()) | 44 | .setTransportType(deviceProfile.getTransportType().name()) |
45 | .setProvisionType(deviceProfile.getProvisionType().name()) | 45 | .setProvisionType(deviceProfile.getProvisionType().name()) |
46 | .setProfileDataBytes(ByteString.copyFrom(dataDecodingEncodingService.encode(deviceProfile.getProfileData()))); | 46 | .setProfileDataBytes(ByteString.copyFrom(dataDecodingEncodingService.encode(deviceProfile.getProfileData()))); |
47 | - if (deviceProfile.getDefaultRuleChainId() != null) { | ||
48 | - builder.setDefaultRuleChainIdMSB(deviceProfile.getDefaultRuleChainId().getId().getMostSignificantBits()) | ||
49 | - .setDefaultRuleChainIdLSB(deviceProfile.getDefaultRuleChainId().getId().getLeastSignificantBits()); | ||
50 | - } | ||
51 | - if (deviceProfile.getDefaultQueueName() != null) { | ||
52 | - builder.setDefaultQueueName(deviceProfile.getDefaultQueueName()); | ||
53 | - } | 47 | + // TODO: voba - should this be always null at the moment?? |
48 | +// if (deviceProfile.getDefaultRuleChainId() != null) { | ||
49 | +// builder.setDefaultRuleChainIdMSB(deviceProfile.getDefaultRuleChainId().getId().getMostSignificantBits()) | ||
50 | +// .setDefaultRuleChainIdLSB(deviceProfile.getDefaultRuleChainId().getId().getLeastSignificantBits()); | ||
51 | +// } | ||
52 | +// if (deviceProfile.getDefaultQueueName() != null) { | ||
53 | +// builder.setDefaultQueueName(deviceProfile.getDefaultQueueName()); | ||
54 | +// } | ||
54 | if (deviceProfile.getProvisionDeviceKey() != null) { | 55 | if (deviceProfile.getProvisionDeviceKey() != null) { |
55 | builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey()); | 56 | builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey()); |
56 | } | 57 | } |
@@ -42,6 +42,8 @@ import org.thingsboard.server.dao.entityview.EntityViewService; | @@ -42,6 +42,8 @@ import org.thingsboard.server.dao.entityview.EntityViewService; | ||
42 | import org.thingsboard.server.dao.relation.RelationService; | 42 | import org.thingsboard.server.dao.relation.RelationService; |
43 | import org.thingsboard.server.dao.user.UserService; | 43 | import org.thingsboard.server.dao.user.UserService; |
44 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; | 44 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
45 | +import org.thingsboard.server.service.profile.DefaultTbDeviceProfileCache; | ||
46 | +import org.thingsboard.server.service.profile.TbDeviceProfileCache; | ||
45 | import org.thingsboard.server.service.queue.TbClusterService; | 47 | import org.thingsboard.server.service.queue.TbClusterService; |
46 | import org.thingsboard.server.service.state.DeviceStateService; | 48 | import org.thingsboard.server.service.state.DeviceStateService; |
47 | 49 | ||
@@ -57,6 +59,9 @@ public abstract class BaseProcessor { | @@ -57,6 +59,9 @@ public abstract class BaseProcessor { | ||
57 | protected DeviceService deviceService; | 59 | protected DeviceService deviceService; |
58 | 60 | ||
59 | @Autowired | 61 | @Autowired |
62 | + protected TbDeviceProfileCache deviceProfileCache; | ||
63 | + | ||
64 | + @Autowired | ||
60 | protected DashboardService dashboardService; | 65 | protected DashboardService dashboardService; |
61 | 66 | ||
62 | @Autowired | 67 | @Autowired |
@@ -21,11 +21,15 @@ import com.google.common.util.concurrent.ListenableFuture; | @@ -21,11 +21,15 @@ import com.google.common.util.concurrent.ListenableFuture; | ||
21 | import com.google.common.util.concurrent.SettableFuture; | 21 | import com.google.common.util.concurrent.SettableFuture; |
22 | import com.google.gson.Gson; | 22 | import com.google.gson.Gson; |
23 | import com.google.gson.JsonObject; | 23 | import com.google.gson.JsonObject; |
24 | +import groovy.lang.Tuple; | ||
24 | import lombok.extern.slf4j.Slf4j; | 25 | import lombok.extern.slf4j.Slf4j; |
26 | +import org.javatuples.Pair; | ||
27 | +import org.passay.Rule; | ||
25 | import org.springframework.stereotype.Component; | 28 | import org.springframework.stereotype.Component; |
26 | import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; | 29 | import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; |
27 | import org.thingsboard.server.common.data.DataConstants; | 30 | import org.thingsboard.server.common.data.DataConstants; |
28 | import org.thingsboard.server.common.data.Device; | 31 | import org.thingsboard.server.common.data.Device; |
32 | +import org.thingsboard.server.common.data.DeviceProfile; | ||
29 | import org.thingsboard.server.common.data.EntityType; | 33 | import org.thingsboard.server.common.data.EntityType; |
30 | import org.thingsboard.server.common.data.EntityView; | 34 | import org.thingsboard.server.common.data.EntityView; |
31 | import org.thingsboard.server.common.data.asset.Asset; | 35 | import org.thingsboard.server.common.data.asset.Asset; |
@@ -33,14 +37,18 @@ import org.thingsboard.server.common.data.id.AssetId; | @@ -33,14 +37,18 @@ import org.thingsboard.server.common.data.id.AssetId; | ||
33 | import org.thingsboard.server.common.data.id.CustomerId; | 37 | import org.thingsboard.server.common.data.id.CustomerId; |
34 | import org.thingsboard.server.common.data.id.DashboardId; | 38 | import org.thingsboard.server.common.data.id.DashboardId; |
35 | import org.thingsboard.server.common.data.id.DeviceId; | 39 | import org.thingsboard.server.common.data.id.DeviceId; |
40 | +import org.thingsboard.server.common.data.id.DeviceProfileId; | ||
36 | import org.thingsboard.server.common.data.id.EntityId; | 41 | import org.thingsboard.server.common.data.id.EntityId; |
37 | import org.thingsboard.server.common.data.id.EntityViewId; | 42 | import org.thingsboard.server.common.data.id.EntityViewId; |
43 | +import org.thingsboard.server.common.data.id.RuleChainId; | ||
38 | import org.thingsboard.server.common.data.id.TenantId; | 44 | import org.thingsboard.server.common.data.id.TenantId; |
39 | import org.thingsboard.server.common.data.id.UserId; | 45 | import org.thingsboard.server.common.data.id.UserId; |
40 | import org.thingsboard.server.common.data.kv.AttributeKey; | 46 | import org.thingsboard.server.common.data.kv.AttributeKey; |
41 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 47 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
48 | +import org.thingsboard.server.common.data.rule.RuleChain; | ||
42 | import org.thingsboard.server.common.msg.TbMsg; | 49 | import org.thingsboard.server.common.msg.TbMsg; |
43 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 50 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
51 | +import org.thingsboard.server.common.msg.queue.ServiceQueue; | ||
44 | import org.thingsboard.server.common.msg.session.SessionMsgType; | 52 | import org.thingsboard.server.common.msg.session.SessionMsgType; |
45 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; | 53 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
46 | import org.thingsboard.server.common.transport.util.JsonUtils; | 54 | import org.thingsboard.server.common.transport.util.JsonUtils; |
@@ -70,7 +78,9 @@ public class TelemetryProcessor extends BaseProcessor { | @@ -70,7 +78,9 @@ public class TelemetryProcessor extends BaseProcessor { | ||
70 | List<ListenableFuture<Void>> result = new ArrayList<>(); | 78 | List<ListenableFuture<Void>> result = new ArrayList<>(); |
71 | EntityId entityId = constructEntityId(entityData); | 79 | EntityId entityId = constructEntityId(entityData); |
72 | if ((entityData.hasPostAttributesMsg() || entityData.hasPostTelemetryMsg() || entityData.hasAttributesUpdatedMsg()) && entityId != null) { | 80 | if ((entityData.hasPostAttributesMsg() || entityData.hasPostTelemetryMsg() || entityData.hasAttributesUpdatedMsg()) && entityId != null) { |
73 | - TbMsgMetaData metaData = constructBaseMsgMetadata(tenantId, entityId); | 81 | + // TODO: voba - in terms of performance we should not fetch device from DB by id |
82 | + // TbMsgMetaData metaData = constructBaseMsgMetadata(tenantId, entityId); | ||
83 | + TbMsgMetaData metaData = new TbMsgMetaData(); | ||
74 | metaData.putValue(DataConstants.MSG_SOURCE_KEY, DataConstants.EDGE_MSG_SOURCE); | 84 | metaData.putValue(DataConstants.MSG_SOURCE_KEY, DataConstants.EDGE_MSG_SOURCE); |
75 | if (entityData.hasPostAttributesMsg()) { | 85 | if (entityData.hasPostAttributesMsg()) { |
76 | result.add(processPostAttributes(tenantId, entityId, entityData.getPostAttributesMsg(), metaData)); | 86 | result.add(processPostAttributes(tenantId, entityId, entityData.getPostAttributesMsg(), metaData)); |
@@ -120,12 +130,36 @@ public class TelemetryProcessor extends BaseProcessor { | @@ -120,12 +130,36 @@ public class TelemetryProcessor extends BaseProcessor { | ||
120 | return metaData; | 130 | return metaData; |
121 | } | 131 | } |
122 | 132 | ||
133 | + private Pair<String, RuleChainId> getDefaultQueueNameAndRuleChainId(TenantId tenantId, EntityId entityId) { | ||
134 | + if (EntityType.DEVICE.equals(entityId.getEntityType())) { | ||
135 | + DeviceProfile deviceProfile = deviceProfileCache.get(tenantId, new DeviceId(entityId.getId())); | ||
136 | + RuleChainId ruleChainId; | ||
137 | + String queueName; | ||
138 | + | ||
139 | + if (deviceProfile == null) { | ||
140 | + log.warn("[{}] Device profile is null!", entityId); | ||
141 | + ruleChainId = null; | ||
142 | + queueName = ServiceQueue.MAIN; | ||
143 | + } else { | ||
144 | + ruleChainId = deviceProfile.getDefaultRuleChainId(); | ||
145 | + String defaultQueueName = deviceProfile.getDefaultQueueName(); | ||
146 | + queueName = defaultQueueName != null ? defaultQueueName : ServiceQueue.MAIN; | ||
147 | + } | ||
148 | + return new Pair<>(queueName, ruleChainId); | ||
149 | + } else { | ||
150 | + return new Pair<>(ServiceQueue.MAIN, null); | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
123 | private ListenableFuture<Void> processPostTelemetry(TenantId tenantId, EntityId entityId, TransportProtos.PostTelemetryMsg msg, TbMsgMetaData metaData) { | 154 | private ListenableFuture<Void> processPostTelemetry(TenantId tenantId, EntityId entityId, TransportProtos.PostTelemetryMsg msg, TbMsgMetaData metaData) { |
124 | SettableFuture<Void> futureToSet = SettableFuture.create(); | 155 | SettableFuture<Void> futureToSet = SettableFuture.create(); |
125 | for (TransportProtos.TsKvListProto tsKv : msg.getTsKvListList()) { | 156 | for (TransportProtos.TsKvListProto tsKv : msg.getTsKvListList()) { |
126 | JsonObject json = JsonUtils.getJsonObject(tsKv.getKvList()); | 157 | JsonObject json = JsonUtils.getJsonObject(tsKv.getKvList()); |
127 | metaData.putValue("ts", tsKv.getTs() + ""); | 158 | metaData.putValue("ts", tsKv.getTs() + ""); |
128 | - TbMsg tbMsg = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), entityId, metaData, gson.toJson(json)); | 159 | + Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId); |
160 | + String queueName = defaultQueueAndRuleChain.getValue0(); | ||
161 | + RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue1(); | ||
162 | + TbMsg tbMsg = TbMsg.newMsg(queueName, SessionMsgType.POST_TELEMETRY_REQUEST.name(), entityId, metaData, gson.toJson(json), ruleChainId, null); | ||
129 | tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() { | 163 | tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() { |
130 | @Override | 164 | @Override |
131 | public void onSuccess(TbQueueMsgMetadata metadata) { | 165 | public void onSuccess(TbQueueMsgMetadata metadata) { |
@@ -145,7 +179,10 @@ public class TelemetryProcessor extends BaseProcessor { | @@ -145,7 +179,10 @@ public class TelemetryProcessor extends BaseProcessor { | ||
145 | private ListenableFuture<Void> processPostAttributes(TenantId tenantId, EntityId entityId, TransportProtos.PostAttributeMsg msg, TbMsgMetaData metaData) { | 179 | private ListenableFuture<Void> processPostAttributes(TenantId tenantId, EntityId entityId, TransportProtos.PostAttributeMsg msg, TbMsgMetaData metaData) { |
146 | SettableFuture<Void> futureToSet = SettableFuture.create(); | 180 | SettableFuture<Void> futureToSet = SettableFuture.create(); |
147 | JsonObject json = JsonUtils.getJsonObject(msg.getKvList()); | 181 | JsonObject json = JsonUtils.getJsonObject(msg.getKvList()); |
148 | - TbMsg tbMsg = TbMsg.newMsg(SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), entityId, metaData, gson.toJson(json)); | 182 | + Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId); |
183 | + String queueName = defaultQueueAndRuleChain.getValue0(); | ||
184 | + RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue1(); | ||
185 | + TbMsg tbMsg = TbMsg.newMsg(queueName, SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), entityId, metaData, gson.toJson(json), ruleChainId, null); | ||
149 | tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() { | 186 | tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() { |
150 | @Override | 187 | @Override |
151 | public void onSuccess(TbQueueMsgMetadata metadata) { | 188 | public void onSuccess(TbQueueMsgMetadata metadata) { |
@@ -169,7 +206,10 @@ public class TelemetryProcessor extends BaseProcessor { | @@ -169,7 +206,10 @@ public class TelemetryProcessor extends BaseProcessor { | ||
169 | Futures.addCallback(future, new FutureCallback<List<Void>>() { | 206 | Futures.addCallback(future, new FutureCallback<List<Void>>() { |
170 | @Override | 207 | @Override |
171 | public void onSuccess(@Nullable List<Void> voids) { | 208 | public void onSuccess(@Nullable List<Void> voids) { |
172 | - TbMsg tbMsg = TbMsg.newMsg(DataConstants.ATTRIBUTES_UPDATED, entityId, metaData, gson.toJson(json)); | 209 | + Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId); |
210 | + String queueName = defaultQueueAndRuleChain.getValue0(); | ||
211 | + RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue1(); | ||
212 | + TbMsg tbMsg = TbMsg.newMsg(queueName, DataConstants.ATTRIBUTES_UPDATED, entityId, metaData, gson.toJson(json), ruleChainId, null); | ||
173 | tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() { | 213 | tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() { |
174 | @Override | 214 | @Override |
175 | public void onSuccess(TbQueueMsgMetadata metadata) { | 215 | public void onSuccess(TbQueueMsgMetadata metadata) { |