Search in sources :

Example 1 with RabbitMqActionMsg

use of org.thingsboard.server.extensions.rabbitmq.action.RabbitMqActionMsg in project thingsboard by thingsboard.

the class RabbitMqMsgHandler method process.

@Override
public void process(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) throws RuleException {
    if (!(msg instanceof RabbitMqActionMsg)) {
        throw new RuleException("Unsupported message type " + msg.getClass().getName() + "!");
    }
    RabbitMqActionPayload payload = ((RabbitMqActionMsg) msg).getPayload();
    AMQP.BasicProperties properties = convert(payload.getMessageProperties());
    try {
        channel.basicPublish(payload.getExchange() != null ? payload.getExchange() : "", payload.getQueueName(), properties, payload.getPayload().getBytes(UTF8));
        if (payload.isSync()) {
            ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId())));
        }
    } catch (IOException e) {
        throw new RuleException(e.getMessage(), e);
    }
}
Also used : RabbitMqActionMsg(org.thingsboard.server.extensions.rabbitmq.action.RabbitMqActionMsg) AMQP(com.rabbitmq.client.AMQP) ResponsePluginToRuleMsg(org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg) IOException(java.io.IOException) RuleException(org.thingsboard.server.extensions.api.rules.RuleException) RabbitMqActionPayload(org.thingsboard.server.extensions.rabbitmq.action.RabbitMqActionPayload)

Aggregations

AMQP (com.rabbitmq.client.AMQP)1 IOException (java.io.IOException)1 ResponsePluginToRuleMsg (org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg)1 RuleException (org.thingsboard.server.extensions.api.rules.RuleException)1 RabbitMqActionMsg (org.thingsboard.server.extensions.rabbitmq.action.RabbitMqActionMsg)1 RabbitMqActionPayload (org.thingsboard.server.extensions.rabbitmq.action.RabbitMqActionPayload)1