use of org.thingsboard.server.extensions.api.plugins.msg.TelemetryUploadRequestRuleToPluginMsg in project thingsboard by thingsboard.
the class TelemetryRuleMsgHandler method handleTelemetryUploadRequest.
@Override
public void handleTelemetryUploadRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, TelemetryUploadRequestRuleToPluginMsg msg) {
TelemetryUploadRequest request = msg.getPayload();
List<TsKvEntry> tsKvEntries = new ArrayList<>();
for (Map.Entry<Long, List<KvEntry>> entry : request.getData().entrySet()) {
for (KvEntry kv : entry.getValue()) {
tsKvEntries.add(new BasicTsKvEntry(entry.getKey(), kv));
}
}
ctx.saveTsData(msg.getDeviceId(), tsKvEntries, msg.getTtl(), new PluginCallback<Void>() {
@Override
public void onSuccess(PluginContext ctx, Void data) {
ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onSuccess(request.getMsgType(), request.getRequestId())));
subscriptionManager.onLocalSubscriptionUpdate(ctx, msg.getDeviceId(), SubscriptionType.TIMESERIES, s -> prepareSubscriptionUpdate(request, s));
}
@Override
public void onFailure(PluginContext ctx, Exception e) {
log.error("Failed to process telemetry upload request", e);
ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onError(request.getMsgType(), request.getRequestId(), e)));
}
});
}
Aggregations