Search in sources :

Example 6 with TbQueueMsgMetadata

use of org.thingsboard.server.queue.TbQueueMsgMetadata in project thingsboard by thingsboard.

the class DeviceEdgeProcessor method pushDeviceCreatedEventToRuleEngine.

private void pushDeviceCreatedEventToRuleEngine(TenantId tenantId, Edge edge, Device device) {
    try {
        DeviceId deviceId = device.getId();
        ObjectNode entityNode = mapper.valueToTree(device);
        TbMsg tbMsg = TbMsg.newMsg(DataConstants.ENTITY_CREATED, deviceId, device.getCustomerId(), getActionTbMsgMetaData(edge, device.getCustomerId()), TbMsgDataType.JSON, mapper.writeValueAsString(entityNode));
        tbClusterService.pushMsgToRuleEngine(tenantId, deviceId, tbMsg, new TbQueueCallback() {

            @Override
            public void onSuccess(TbQueueMsgMetadata metadata) {
                log.debug("Successfully send ENTITY_CREATED EVENT to rule engine [{}]", device);
            }

            @Override
            public void onFailure(Throwable t) {
                log.debug("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", device, t);
            }
        });
    } catch (JsonProcessingException | IllegalArgumentException e) {
        log.warn("[{}] Failed to push device action to rule engine: {}", device.getId(), DataConstants.ENTITY_CREATED, e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TbQueueCallback(org.thingsboard.server.queue.TbQueueCallback) DeviceId(org.thingsboard.server.common.data.id.DeviceId) TbQueueMsgMetadata(org.thingsboard.server.queue.TbQueueMsgMetadata) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TbMsg(org.thingsboard.server.common.msg.TbMsg)

Example 7 with TbQueueMsgMetadata

use of org.thingsboard.server.queue.TbQueueMsgMetadata in project thingsboard by thingsboard.

the class TelemetryEdgeProcessor method processPostTelemetry.

private ListenableFuture<Void> processPostTelemetry(TenantId tenantId, CustomerId customerId, EntityId entityId, TransportProtos.PostTelemetryMsg msg, TbMsgMetaData metaData) {
    SettableFuture<Void> futureToSet = SettableFuture.create();
    for (TransportProtos.TsKvListProto tsKv : msg.getTsKvListList()) {
        JsonObject json = JsonUtils.getJsonObject(tsKv.getKvList());
        metaData.putValue("ts", tsKv.getTs() + "");
        Pair<String, RuleChainId> defaultQueueAndRuleChain = getDefaultQueueNameAndRuleChainId(tenantId, entityId);
        String queueName = defaultQueueAndRuleChain.getKey();
        RuleChainId ruleChainId = defaultQueueAndRuleChain.getValue();
        TbMsg tbMsg = TbMsg.newMsg(queueName, SessionMsgType.POST_TELEMETRY_REQUEST.name(), entityId, customerId, metaData, gson.toJson(json), ruleChainId, null);
        tbClusterService.pushMsgToRuleEngine(tenantId, tbMsg.getOriginator(), tbMsg, new TbQueueCallback() {

            @Override
            public void onSuccess(TbQueueMsgMetadata metadata) {
                futureToSet.set(null);
            }

            @Override
            public void onFailure(Throwable t) {
                log.error("Can't process post telemetry [{}]", msg, t);
                futureToSet.setException(t);
            }
        });
    }
    return futureToSet;
}
Also used : TbQueueCallback(org.thingsboard.server.queue.TbQueueCallback) JsonObject(com.google.gson.JsonObject) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) TbQueueMsgMetadata(org.thingsboard.server.queue.TbQueueMsgMetadata) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) TbMsg(org.thingsboard.server.common.msg.TbMsg)

Aggregations

TbQueueCallback (org.thingsboard.server.queue.TbQueueCallback)7 TbQueueMsgMetadata (org.thingsboard.server.queue.TbQueueMsgMetadata)7 TbMsg (org.thingsboard.server.common.msg.TbMsg)4 JsonObject (com.google.gson.JsonObject)3 DeviceId (org.thingsboard.server.common.data.id.DeviceId)3 RuleChainId (org.thingsboard.server.common.data.id.RuleChainId)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 UUID (java.util.UUID)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1 AttributeKey (org.thingsboard.server.common.data.kv.AttributeKey)1 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)1 FromDeviceRpcResponse (org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse)1 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)1 FromDeviceRpcResponseActorMsg (org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg)1