List of usage examples for com.amazonaws.services.sns.model PublishResult getMessageId
public String getMessageId()
Unique identifier assigned to the published message.
From source file:com.onemenu.server.util.awsnotification.tools.AmazonSNSClientWrapper.java
License:Open Source License
public void notification(Platform platform, String principal, String credential, String platformToken, String applicationName, Map<Platform, Map<String, MessageAttributeValue>> attrsMap, String message) { // Create Platform Application. This corresponds to an app on a // platform./* w ww . j a va 2s. c o m*/ CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); System.out.println(platformApplicationResult); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); // Publish a push notification to an Endpoint. PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform, attrsMap, message); System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}"); // Delete the Platform Application since we will no longer be using it. deletePlatformApplication(platformApplicationArn); }
From source file:com.oneops.antenna.senders.aws.SNSService.java
License:Apache License
/** * Sends using the sns publisher/*from w ww . java 2s. c om*/ */ @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:com.zotoh.cloudapi.aws.SNS.java
License:Open Source License
@Override public String publish(String topic, String subject, String message) throws CloudException, InternalException { tstEStrArg("message", message); tstEStrArg("topic-name", topic); tstEStrArg("subject", subject); PublishResult res = _svc.getCloud().getSNS() .publish(new PublishRequest().withTopicArn(topic).withSubject(subject).withMessage(message)); return res == null ? null : res.getMessageId(); }
From source file:io.starter.messaging.tools.AmazonSNSClientWrapper.java
License:Open Source License
public void starterNotification(Platform platform, String principal, String credential, String platformToken, String applicationName, Map<Platform, Map<String, MessageAttributeValue>> attrsMap, String message) { // Create Platform Application. This corresponds to an app on a // platform./*from w w w. jav a 2 s. co m*/ CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(applicationName, platform, principal, credential); System.out.println(platformApplicationResult); // The Platform Application Arn can be used to uniquely identify the // Platform Application. String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn(); // Create an Endpoint. This corresponds to an app on a device. CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(platform, "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn); System.out.println(platformEndpointResult); // Publish a push notification to an Endpoint. PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform, attrsMap, message); System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}"); // Delete the Platform Application since we will no longer be using it. deletePlatformApplication(platformApplicationArn); }
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 a v a 2s .c om*/ 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.apache.beam.sdk.io.aws.sns.AmazonSNSMockSuccess.java
License:Apache License
@Override public PublishResult publish(PublishRequest publishRequest) { PublishResult result = Mockito.mock(PublishResult.class); SdkHttpMetadata metadata = Mockito.mock(SdkHttpMetadata.class); Mockito.when(metadata.getHttpHeaders()).thenReturn(new HashMap<>()); Mockito.when(metadata.getHttpStatusCode()).thenReturn(200); Mockito.when(result.getSdkHttpMetadata()).thenReturn(metadata); Mockito.when(result.getMessageId()).thenReturn(UUID.randomUUID().toString()); return result; }
From source file:org.apache.beam.sdk.io.aws.sns.PublishResultCoder.java
License:Apache License
@Override public void encode(PublishResult value, OutputStream outStream) throws CoderException, IOException { StringUtf8Coder.of().encode(value.getMessageId(), outStream); }
From source file:org.apache.camel.component.aws.sns.SnsProducer.java
License:Apache License
public void process(Exchange exchange) throws Exception { PublishRequest request = new PublishRequest(); request.setTopicArn(getConfiguration().getTopicArn()); request.setMessage(exchange.getIn().getBody(String.class)); request.setSubject(determineSubject(exchange)); LOG.trace("Sending request [{}] from exchange [{}]...", request, exchange); PublishResult result = getEndpoint().getSNSClient().publish(request); LOG.trace("Received result [{}]", result); Message message = getMessageForResponse(exchange); message.setHeader(SnsConstants.MESSAGE_ID, result.getMessageId()); }
From source file:org.apache.usergrid.persistence.queue.impl.SNSQueueManagerImpl.java
License:Apache License
@Override public <T extends Serializable> void sendMessageToAllRegions(final T body) throws IOException { if (snsAsync == null) { logger.error("SNS client is null, perhaps it failed to initialize successfully"); return;//from w w w .ja v a 2 s . c o m } final String stringBody = toString(body); String topicArn = getWriteTopicArn(); if (logger.isTraceEnabled()) { logger.trace("Publishing Message...{} to arn: {}", stringBody, topicArn); } PublishRequest publishRequest = new PublishRequest(topicArn, stringBody); snsAsync.publishAsync(publishRequest, new AsyncHandler<PublishRequest, PublishResult>() { @Override public void onError(Exception e) { logger.error("Error publishing message... {}", e); } @Override public void onSuccess(PublishRequest request, PublishResult result) { if (logger.isTraceEnabled()) { logger.trace("Successfully published... messageID=[{}], arn=[{}]", result.getMessageId(), request.getTopicArn()); } } }); }
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 ww w .j ava 2 s. c o m }