use of org.thingsboard.server.extensions.kafka.action.KafkaActionPayload in project thingsboard by thingsboard.
the class KafkaMsgHandler method process.
@Override
public void process(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) throws RuleException {
if (!(msg instanceof KafkaActionMsg)) {
throw new RuleException("Unsupported message type " + msg.getClass().getName() + "!");
}
KafkaActionPayload payload = ((KafkaActionMsg) msg).getPayload();
log.debug("Processing kafka payload: {}", payload);
try {
producer.send(new ProducerRecord<>(payload.getTopic(), payload.getMsgBody()), (metadata, e) -> {
if (payload.isSync()) {
if (metadata != null) {
ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId())));
} else {
ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onError(payload.getMsgType(), payload.getRequestId(), e)));
}
}
});
} catch (Exception e) {
throw new RuleException(e.getMessage(), e);
}
}
Aggregations