Example usage for com.amazonaws.services.sns AmazonSNSClientBuilder defaultClient

List of usage examples for com.amazonaws.services.sns AmazonSNSClientBuilder defaultClient

Introduction

In this page you can find the example usage for com.amazonaws.services.sns AmazonSNSClientBuilder defaultClient.

Prototype

public static AmazonSNS defaultClient() 

Source Link

Usage

From source file:org.duracloud.common.sns.config.SnsSubscriptionManagerConfig.java

License:Apache License

@Bean(destroyMethod = "disconnect", initMethod = "connect")
public SnsSubscriptionManager snsSubscriptionManager(GlobalPropertiesRepo globalPropertiesRepo,
        final List<AccountComponentCache<?>> componentCaches, String appName) {
    try {//from  w  w  w.jav a 2 s. com

        GlobalProperties props = globalPropertiesRepo.findAll().get(0);
        String queueName = "node-queue-" + appName + "-"
                + Inet4Address.getLocalHost().getHostName().replace(".", "_");
        SnsSubscriptionManager subscriptionManager = new SnsSubscriptionManager(
                AmazonSQSClientBuilder.defaultClient(), AmazonSNSClientBuilder.defaultClient(),
                props.getInstanceNotificationTopicArn(), queueName);

        subscriptionManager.addListener(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                log.info("message received: " + message);
                log.debug("message body: " + message.getBody());
                JsonFactory factory = new JsonFactory();
                ObjectMapper mapper = new ObjectMapper(factory);
                TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {
                };
                String body = message.getBody();
                try {
                    Map<String, String> map = mapper.readValue(body, typeRef);
                    AccountChangeEvent event = AccountChangeEvent.deserialize(map.get("Message"));
                    for (AccountComponentCache<?> cache : componentCaches) {
                        cache.onEvent(event);
                    }
                } catch (IOException e) {
                    log.warn("unable to dispatch message: " + message + " : " + e.getMessage(), e);
                }
            }
        });

        return subscriptionManager;
    } catch (UnknownHostException e) {
        throw new DuraCloudRuntimeException(e);
    }
}

From source file:org.duracloud.common.sns.impl.AccountChangeNotifierImpl.java

License:Apache License

/**
 * @param globalPropertiesConfigService/*from  w  w  w  .j  a va 2 s  . c  om*/
 */
@Autowired
public AccountChangeNotifierImpl(GlobalPropertiesRepo globalPropertiesRepo) {
    this.snsClient = AmazonSNSClientBuilder.defaultClient();
    this.globalPropertiesRepo = globalPropertiesRepo;
}