List of usage examples for com.amazonaws.services.sns AmazonSNS publish
PublishResult publish(PublishRequest publishRequest);
Sends a message to an Amazon SNS topic or sends a text message (SMS message) directly to a phone number.
From source file:ch.admin.isb.hermes5.tools.filebackup.FileBackup.java
License:Apache License
private void sendMessageThroughSNS(String topicArn, AmazonSNS sns, String message, String subject) { if (message.isEmpty()) { return;// w w w .j a v a 2 s . c o m } PublishRequest publishRequest = new PublishRequest(); publishRequest.setTopicArn(topicArn); publishRequest.setSubject(subject); publishRequest.setMessage(truncateUTF8(message, 8192)); sns.publish(publishRequest); }
From source file:ch.admin.isb.hermes5.tools.lognotification.LogNotification.java
License:Apache License
private void sendMessageThroughSNS(String topicArn, AmazonSNS sns, String message, String subject) { if (message.isEmpty()) { return;//from w w w . ja v a2s . c om } PublishRequest publishRequest = new PublishRequest(); publishRequest.setTopicArn(topicArn); publishRequest.setSubject(subject); publishRequest.setMessage(truncateUTF8Tail(message, 8192)); sns.publish(publishRequest); }
From source file:com.easarrive.aws.plugins.common.service.impl.SNSService.java
License:Open Source License
/** * {@inheritDoc}// ww w .jav a 2 s. c o m */ @Override public PublishResult publish2Topic(AmazonSNS client, SNSPublish2TopicRequest publish2TopicRequest) { if (publish2TopicRequest == null) { return null; } // publish to an SNS topic PublishRequest publishRequest = new PublishRequest(publish2TopicRequest.getTopicArn(), publish2TopicRequest.getMessage()); PublishResult result = client.publish(publishRequest); return result; }
From source file:com.logpig.mweagle.rolling.S3RollingFileAppender.java
License:Apache License
private void writeErrorMessage(String message) { final String __subject = "[ERROR] S3RollingFileAppender"; System.err.println(String.format("%s - %s", __subject, message)); try {//from ww w.j a v a 2s . c o m final AmazonSNS snsClient = new AmazonSNSClient(s3Settings.getAWSCredentials()); final PublishRequest __request = new PublishRequest().withTopicArn(s3Settings.getSnsTopicArn()) .withMessage(message).withSubject(__subject); snsClient.publish(__request); } catch (Exception e) { System.err.println(String.format( "[ERROR] Unable to send notification of S3RollingFileAppender failure. %s", e.getMessage())); } }
From source file:com.oneops.antenna.senders.aws.SNSService.java
License:Apache License
/** * Sends using the sns publisher/*from w w w. j av a 2 s . c o m*/ */ @Override public boolean postMessage(NotificationMessage nMsg, BasicSubscriber subscriber) { SNSSubscriber sub; if (subscriber instanceof SNSSubscriber) { sub = (SNSSubscriber) subscriber; } else { throw new ClassCastException("invalid subscriber " + subscriber.getClass().getName()); } SNSMessage msg = buildSNSMessage(nMsg); AmazonSNS sns = new AmazonSNSClient(new BasicAWSCredentials(sub.getAwsAccessKey(), sub.getAwsSecretKey())); if (sub.getSnsEndpoint() != null) { sns.setEndpoint(sub.getSnsEndpoint()); } CreateTopicRequest tRequest = new CreateTopicRequest(); tRequest.setName(msg.getTopicName()); CreateTopicResult result = sns.createTopic(tRequest); PublishRequest pr = new PublishRequest(result.getTopicArn(), msg.getTxtMessage()) .withSubject(msg.getSubject()); try { PublishResult pubresult = sns.publish(pr); logger.info("Published msg with id - " + pubresult.getMessageId()); } catch (AmazonClientException ace) { logger.error(ace.getMessage()); return false; } return true; }
From source file:jp.classmethod.aws.gradle.sns.AmazonSNSPublishMessageTask.java
License:Apache License
@TaskAction public void publishMessage() { String topicArn = getTopicArn(); String message = getMessage(); String subject = getSubject(); String messageStructure = getMessageStructure(); if (topicArn == null) { throw new GradleException("Must specify SNS topicArn"); }/* w w w .j a v a 2s .c o m*/ if (message == null) { throw new GradleException("Must provide message to send to SNS"); } AmazonSNSPluginExtension ext = getProject().getExtensions().getByType(AmazonSNSPluginExtension.class); AmazonSNS sns = ext.getClient(); PublishRequest request = new PublishRequest().withTopicArn(topicArn).withMessage(message); if (subject != null) { request.setSubject(subject); } if (messageStructure != null) { request.setMessageStructure(messageStructure); } sns.publish(request); }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public void publish(INotificationEndpoint notificationEndpoint, String json) { Preconditions.checkArgument((notificationEndpoint != null), "Endpoint must not be null"); Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null), "Endpoint is missing a notification URL definition"); Preconditions.checkArgument((!notificationEndpoint.isPendingConfirmation()), "Endpoint has not yet been confirmed"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1);/*from w w w . j av a 2 s. c o m*/ try { String subject = "SMART COSMOS Objects Event Notification"; JSONObject jsonObject = null; try { jsonObject = new JSONObject(json); if (jsonObject.has(EVENT_TYPE)) { String eventType = jsonObject.getString(EVENT_TYPE); subject = "Objects Event: " + eventType; } } catch (JSONException e) { e.printStackTrace(); } PublishRequest request = new PublishRequest(notificationEndpoint.getTopicArn(), json, subject); PublishResult result = sns.publish(request); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), result.getMessageId()); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationBroadcast, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } }
From source file:org.finra.herd.dao.impl.SnsOperationsImpl.java
License:Apache License
@Override public PublishResult publish(String topicArn, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSNS amazonSNS) { return amazonSNS.publish(new PublishRequest().withTopicArn(topicArn).withMessage(messageText) .withMessageAttributes(messageAttributes)); }
From source file:org.smap.notifications.interfaces.EmitNotifications.java
License:Open Source License
public void publish(int event, String msg, String subject) { //create a new SNS client AmazonSNS sns = AmazonSNSClient.builder().withRegion("ap-southeast-1") .withCredentials(new ClasspathPropertiesFileCredentialsProvider()).build(); String topic = getTopic(event); if (topic != null) { PublishRequest publishRequest = new PublishRequest(topic, msg, subject); PublishResult publishResult = sns.publish(publishRequest); log.info("Publish: " + subject + " MessageId - " + publishResult.getMessageId()); }//from w ww.j a v a 2 s . c o m }