@Override public PublishResult retriableCall() throws Exception { PublishRequest publishRequest = new PublishRequest(topic_arn, msg) .withMessageAttributes(messageAttributes); return snsClient.publish(publishRequest); } }.call();
/** * 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)); }
@Override public void emit(final Event event) { requireNonNull(event, "Cannot emit a null event!"); service.serialize(event).ifPresent(json -> { try { sns.publish(topic, json); } catch (final Exception ex) { LOGGER.error("Error writing to SNS topic {}: {}", topic, ex.getMessage()); } }); } }
@Override protected boolean sendInternal(Message<?> message, long timeout) { PublishRequest publishRequest = new PublishRequest(this.topicArn, message.getPayload().toString(), findNotificationSubject(message)); Map<String, MessageAttributeValue> messageAttributes = getMessageAttributes(message); if (!messageAttributes.isEmpty()) { publishRequest.withMessageAttributes(messageAttributes); } this.amazonSns.publish(publishRequest); return true; }
@Override protected boolean sendInternal(Message<?> message, long timeout) { PublishRequest publishRequest = new PublishRequest(this.topicArn, message.getPayload().toString(), findNotificationSubject(message)); Map<String, MessageAttributeValue> messageAttributes = getMessageAttributes(message); if (!messageAttributes.isEmpty()) { publishRequest.withMessageAttributes(messageAttributes); } this.amazonSns.publish(publishRequest); return true; }
@Override public void stashCompleted(StashMetadata info, Date completeTime) { Map<String, Object> message = ImmutableMap.<String, Object>of( "id", info.getId(), "status", "completed", "destinations", FluentIterable.from(info.getDestinations()) .transform(Functions.toStringFunction()) .toList(), "completedTime", completeTime); try { _amazonSNS.publish(_completedTopic.get(), JsonHelper.asJson(message)); } catch (Exception e) { _log.error("Failed to send SNS notification of scan completed: id={}", info.getId(), e); } }
@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)); } }
private void publishNotification( final String arn, final SNSMessage<?> message, final String counterKey ) throws Exception { PublishResult result = null; try { result = this.client.publish(arn, this.mapper.writeValueAsString(message)); } catch (InvalidParameterException | InvalidParameterValueException exception) { log.error("SNS Publish message exceeded the size threshold", exception); notificationMetric.counterIncrement( Metrics.CounterSNSNotificationPublishMessageSizeExceeded.getMetricName()); final SNSMessage<Void> voidMessage = new SNSMessage<>(message.getId(), message.getTimestamp(), message.getRequestId(), message.getType(), message.getName(), null); result = this.client.publish(arn, this.mapper.writeValueAsString(voidMessage)); } log.info("Successfully published message to topic {} with id {}", arn, result.getMessageId()); log.debug("Successfully published message {} to topic {} with id {}", message, arn, result.getMessageId()); notificationMetric.counterIncrement(counterKey); notificationMetric.recordTime(message, Metrics.TimerNotificationsPublishDelay.getMetricName()); } }
@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)); } }
public PublishResult sendPushMessage(AmazonSNS snsClient, PushPlatform platform, String targetArn, String message, Map<String, MessageAttributeValue> messageAttributes) throws IOException { Map<String, String> messageMap = new HashMap<String, String>(); messageMap.put(platform.name(), message); message = ServerUtil.asJson(messageMap); PublishRequest publishRequest = new PublishRequest(); publishRequest.setMessageStructure("json"); if (messageAttributes != null) { publishRequest.setMessageAttributes(messageAttributes); } publishRequest.setTargetArn(targetArn); publishRequest.setMessage(message); PublishResult publishResult = snsClient.publish(publishRequest); return publishResult; } }
protected void send(String topicName, String topicArn, IPubSubMessage pubSubMessage, ITraceContext trace) { trace.trace("ABOUT-TO-PUBLISH", "SNS_TOPIC", topicName); try { PublishRequest publishRequest = new PublishRequest(topicArn, pubSubMessage.getPayload()); if(!pubSubMessage.getAttributes().isEmpty()) { Map<String, MessageAttributeValue> messageAttributes = new HashMap<>(); for(Entry<String, String> entry : pubSubMessage.getAttributes().entrySet()) { messageAttributes.put(entry.getKey(), new MessageAttributeValue() .withDataType("String") .withStringValue(entry.getValue())); } publishRequest.withMessageAttributes(messageAttributes); } snsClient_.publish(publishRequest); trace.trace("PUBLISHED", "SNS_TOPIC", topicName); } catch (RuntimeException e) { throw new TransactionFault(e); } }
attempt++; try { PublishResult pr = producer.publish(request); context.output(pr); break;
@Override protected void sendSNSMessage(NevadoTopic topic, String serializedMessage) throws JMSException { String arn = getTopicARN(topic); PublishRequest request = new PublishRequest(arn, serializedMessage); try { if (isAsync()) { ((AmazonSNSAsync)_amazonSNS).publishAsync(request); } else { _amazonSNS.publish(request); } } catch (AmazonClientException e) { throw handleAWSException("Unable to send message to topic: " + arn, e); } }
@Override protected Void run() throws Exception { final String topicArn = this.step.getTopicArn(); final String subject = this.step.getSubject(); final String message = this.step.getMessage(); final Map<String, String> messageAttributes = this.step.getMessageAttributes(); TaskListener listener = this.getContext().get(TaskListener.class); AmazonSNS snsClient = AWSClientFactory.create(AmazonSNSClientBuilder.standard(), this.getContext()); listener.getLogger().format("Publishing notification %s to %s %n", subject, topicArn); PublishRequest publishRequest = new PublishRequest() .withTopicArn(topicArn).withMessage(message).withSubject(subject); if (messageAttributes != null && !messageAttributes.isEmpty()) { for (Map.Entry<String, String> entry : messageAttributes.entrySet()) { MessageAttributeValue value = new MessageAttributeValue(); value.setStringValue(entry.getValue()); value.setDataType(STRING_DATATYPE); publishRequest.addMessageAttributesEntry(entry.getKey(), value); } } PublishResult result = snsClient.publish(publishRequest); listener.getLogger().format("Message published as %s %n", result.getMessageId()); return null; }
@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"); } 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); }
return snsClient.publish(publishRequest);
sqs.setQueueAttributes(new SetQueueAttributesRequest().withQueueUrl(sqsUrl).addAttributesEntry("Policy", allowSnsToPostToSqsPolicy.toJson())); String sqsSubscriptionArn = sns.subscribe(snsTopicArn, "sqs", sqsArn).getSubscriptionArn(); sns.publish(snsTopicArn, "Hello world"); ReceiveMessageResult receiveResp = sqs.receiveMessage(new ReceiveMessageRequest(sqsUrl).withWaitTimeSeconds(10)); for (Message message: receiveResp.getMessages()) {