Search in sources :

Example 1 with SnsTopicActionMsg

use of org.thingsboard.server.extensions.sns.action.SnsTopicActionMsg in project thingsboard by thingsboard.

the class SnsMessageHandler method process.

@Override
public void process(PluginContext ctx, TenantId tenantId, RuleId ruleId, RuleToPluginMsg<?> msg) throws RuleException {
    if (msg instanceof SnsTopicActionMsg) {
        SnsTopicActionPayload payload = ((SnsTopicActionMsg) msg).getPayload();
        PublishRequest publishRequest = new PublishRequest().withTopicArn(payload.getTopicArn()).withMessage(payload.getMsgBody());
        sns.publish(publishRequest);
        if (payload.isSync()) {
            ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId())));
        }
        return;
    }
    throw new RuleException("Unsupported message type " + msg.getClass().getName() + "!");
}
Also used : SnsTopicActionMsg(org.thingsboard.server.extensions.sns.action.SnsTopicActionMsg) ResponsePluginToRuleMsg(org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg) PublishRequest(com.amazonaws.services.sns.model.PublishRequest) RuleException(org.thingsboard.server.extensions.api.rules.RuleException) SnsTopicActionPayload(org.thingsboard.server.extensions.sns.action.SnsTopicActionPayload)

Aggregations

PublishRequest (com.amazonaws.services.sns.model.PublishRequest)1 ResponsePluginToRuleMsg (org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg)1 RuleException (org.thingsboard.server.extensions.api.rules.RuleException)1 SnsTopicActionMsg (org.thingsboard.server.extensions.sns.action.SnsTopicActionMsg)1 SnsTopicActionPayload (org.thingsboard.server.extensions.sns.action.SnsTopicActionPayload)1