|
|
|
@ -52,6 +52,8 @@ import org.thingsboard.server.common.data.kv.AttributeKey; |
|
|
|
import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
|
|
|
import org.thingsboard.server.common.msg.TbMsg; |
|
|
|
import org.thingsboard.server.common.msg.TbMsgMetaData; |
|
|
|
import org.thingsboard.server.common.msg.queue.ServiceType; |
|
|
|
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
|
|
|
import org.thingsboard.server.common.msg.session.SessionMsgType; |
|
|
|
import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
|
|
|
import org.thingsboard.server.common.transport.util.JsonUtils; |
|
|
|
@ -61,9 +63,12 @@ import org.thingsboard.server.gen.edge.v1.EntityDataProto; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos; |
|
|
|
import org.thingsboard.server.queue.TbQueueCallback; |
|
|
|
import org.thingsboard.server.queue.TbQueueMsgMetadata; |
|
|
|
import org.thingsboard.server.queue.TbQueueProducer; |
|
|
|
import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
|
|
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
|
|
|
|
|
|
import javax.annotation.Nullable; |
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.List; |
|
|
|
@ -77,14 +82,19 @@ public class TelemetryEdgeProcessor extends BaseEdgeProcessor { |
|
|
|
|
|
|
|
private final Gson gson = new Gson(); |
|
|
|
|
|
|
|
private TbQueueProducer<TbProtoQueueMsg<TransportProtos.ToCoreMsg>> tbCoreMsgProducer; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() { |
|
|
|
tbCoreMsgProducer = producerProvider.getTbCoreMsgProducer(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<ListenableFuture<Void>> processTelemetryFromEdge(TenantId tenantId, CustomerId customerId, EntityDataProto entityData) { |
|
|
|
log.trace("[{}] onTelemetryUpdate [{}]", tenantId, entityData); |
|
|
|
List<ListenableFuture<Void>> result = new ArrayList<>(); |
|
|
|
EntityId entityId = constructEntityId(entityData); |
|
|
|
if ((entityData.hasPostAttributesMsg() || entityData.hasPostTelemetryMsg() || entityData.hasAttributesUpdatedMsg()) && entityId != null) { |
|
|
|
// @voba - in terms of performance we should not fetch device from DB by id
|
|
|
|
// TbMsgMetaData metaData = constructBaseMsgMetadata(tenantId, entityId);
|
|
|
|
TbMsgMetaData metaData = new TbMsgMetaData(); |
|
|
|
TbMsgMetaData metaData = constructBaseMsgMetadata(tenantId, entityId); |
|
|
|
metaData.putValue(DataConstants.MSG_SOURCE_KEY, DataConstants.EDGE_MSG_SOURCE); |
|
|
|
if (entityData.hasPostAttributesMsg()) { |
|
|
|
result.add(processPostAttributes(tenantId, customerId, entityId, entityData.getPostAttributesMsg(), metaData)); |
|
|
|
@ -96,6 +106,20 @@ public class TelemetryEdgeProcessor extends BaseEdgeProcessor { |
|
|
|
if (entityData.hasPostTelemetryMsg()) { |
|
|
|
result.add(processPostTelemetry(tenantId, customerId, entityId, entityData.getPostTelemetryMsg(), metaData)); |
|
|
|
} |
|
|
|
if (EntityType.DEVICE.equals(entityId.getEntityType())) { |
|
|
|
DeviceId deviceId = new DeviceId(entityId.getId()); |
|
|
|
|
|
|
|
TransportProtos.DeviceActivityProto deviceActivityMsg = TransportProtos.DeviceActivityProto.newBuilder() |
|
|
|
.setTenantIdMSB(tenantId.getId().getMostSignificantBits()) |
|
|
|
.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()) |
|
|
|
.setDeviceIdMSB(deviceId.getId().getMostSignificantBits()) |
|
|
|
.setDeviceIdLSB(deviceId.getId().getLeastSignificantBits()) |
|
|
|
.setLastActivityTime(System.currentTimeMillis()).build(); |
|
|
|
|
|
|
|
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, deviceId); |
|
|
|
tbCoreMsgProducer.send(tpi, new TbProtoQueueMsg<>(deviceId.getId(), |
|
|
|
TransportProtos.ToCoreMsg.newBuilder().setDeviceActivityMsg(deviceActivityMsg).build()), null); |
|
|
|
} |
|
|
|
} |
|
|
|
if (entityData.hasAttributeDeleteMsg()) { |
|
|
|
result.add(processAttributeDeleteMsg(tenantId, entityId, entityData.getAttributeDeleteMsg(), entityData.getEntityType())); |
|
|
|
|