All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.chilldev.commons.aws.sns.TopicClient Maven / Gradle / Ivy

The newest version!
// Generated by delombok at Wed Oct 31 01:50:25 UTC 2018
/*
 * This file is part of the ChillDev-Commons.
 *
 * @license http://mit-license.org/ The MIT license
 * @copyright 2017 © by Rafał Wrzeszcz - Wrzasq.pl.
 */
package pl.chilldev.commons.aws.sns;

import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClientBuilder;
import com.amazonaws.services.sns.model.PublishResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Topic-wrapped AWS SNS client.
 */
public class TopicClient {
    /**
     * AWS SNS client.
     */
    private AmazonSNS sns;
    /**
     * JSON (de-)serialization handler.
     */
    private ObjectMapper objectMapper;
    /**
     * Topic ARN.
     */
    private String topicArn;

    /**
     * Initializes client wrapper with the default SNS client.
     *
     * 

* This is a simplified version for AWS internal services, like AWS Lambda, which relies on environment * permissions. *

* * @param objectMapper JSON handler. * @param topicArn SNS topic ARN. */ public TopicClient(ObjectMapper objectMapper, String topicArn) { this(AmazonSNSClientBuilder.standard().build(), objectMapper, topicArn); } /** * Publishes message to associated SNS topic. * * @param message Message to publish (will always be serialized to JSON, even if it's plain string). * @return Operation results. * @throws JsonProcessingException When message could not be serialized. */ public PublishResult publish(Object message) throws JsonProcessingException { return this.sns.publish(this.topicArn, this.objectMapper.writeValueAsString(message)); } @SuppressWarnings("all") public TopicClient(final AmazonSNS sns, final ObjectMapper objectMapper, final String topicArn) { this.sns = sns; this.objectMapper = objectMapper; this.topicArn = topicArn; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy