Example usage for com.amazonaws.services.sns.model PublishResult getMessageId

List of usage examples for com.amazonaws.services.sns.model PublishResult getMessageId

Introduction

In this page you can find the example usage for com.amazonaws.services.sns.model PublishResult getMessageId.

Prototype


public String getMessageId() 

Source Link

Document

Unique identifier assigned to the published message.

Usage

From source file:org.springframework.integration.aws.outbound.SnsMessageHandler.java

License:Apache License

@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
    Object payload = requestMessage.getPayload();

    PublishRequest publishRequest = null;

    if (payload instanceof PublishRequest) {
        publishRequest = (PublishRequest) payload;
    } else {/*from w  w  w.j  a v a2  s . co m*/
        Assert.state(this.topicArnExpression != null, "'topicArn' or 'topicArnExpression' must be specified.");
        publishRequest = new PublishRequest();
        String topicArn = this.topicArnExpression.getValue(this.evaluationContext, requestMessage,
                String.class);
        if (this.resourceIdResolver != null) {
            topicArn = this.resourceIdResolver.resolveToPhysicalResourceId(topicArn);
        }
        publishRequest.setTopicArn(topicArn);

        if (this.subjectExpression != null) {
            String subject = this.subjectExpression.getValue(this.evaluationContext, requestMessage,
                    String.class);
            publishRequest.setSubject(subject);
        }

        Object snsMessage = requestMessage.getPayload();

        if (this.bodyExpression != null) {
            snsMessage = this.bodyExpression.getValue(this.evaluationContext, requestMessage);
        }

        if (snsMessage instanceof SnsBodyBuilder) {
            publishRequest.withMessageStructure("json").setMessage(((SnsBodyBuilder) snsMessage).build());
        } else {
            publishRequest.setMessage(getConversionService().convert(snsMessage, String.class));
        }
    }

    PublishResult publishResult = this.amazonSns.publish(publishRequest);

    if (this.produceReply) {
        return getMessageBuilderFactory().withPayload(publishRequest)
                .setHeader(AwsHeaders.TOPIC, publishRequest.getTopicArn())
                .setHeader(AwsHeaders.SNS_PUBLISHED_MESSAGE_ID, publishResult.getMessageId());
    } else {
        return null;
    }
}

From source file:org.thingsboard.rule.engine.aws.sns.TbSnsNode.java

License:Apache License

private TbMsg processPublishResult(TbContext ctx, TbMsg origMsg, PublishResult result) {
    TbMsgMetaData metaData = origMsg.getMetaData().copy();
    metaData.putValue(MESSAGE_ID, result.getMessageId());
    metaData.putValue(REQUEST_ID, result.getSdkResponseMetadata().getRequestId());
    return ctx.transformMsg(origMsg, origMsg.getType(), origMsg.getOriginator(), metaData, origMsg.getData());
}

From source file:org.traccar.database.DataManager.java

License:Apache License

public void sendSnsMessage(Position position) throws SQLException, IOException {
    Device device = getDeviceById(position.getDeviceId());
    if (device != null && device.getSnsTopicName() != null && !device.getSnsTopicName().equals("")) {
        //publish to an SNS topic
        String msg = gson.toJson(SNSMessage.fromPosition(position, device.getImei(), device.getExternalId()));
        Log.info("Sending SNS message:" + msg + " to topic: " + device.getSnsTopicName());
        PublishRequest publishRequest = new PublishRequest(device.getSnsTopicName(), msg);
        PublishResult publishResult = snsClient.publish(publishRequest);
        Log.info("SNS Message id:" + publishResult.getMessageId());
    }//www. ja v  a  2  s. c om
}

From source file:shnakkydoodle.notifying.provider.aws.AwsProvider.java

License:Open Source License

/**
 * Publish a notification//from  w ww.j  av a 2  s.  co m
 */
@Override
public String insertNotification(String topicName, String subject, String message) {

    AmazonSNSClient snsClient = getSNSClient();

    // find the topic
    NotificationTopic notificationTopic = this.retrieveNotificationTopic(topicName);
    if (notificationTopic == null) {
        this.insertNotificationTopic(topicName, "");
    }

    // publish to an SNS topic
    PublishRequest publishRequest = new PublishRequest(this.retrieveNotificationTopic(topicName).getTopicId(),
            subject);
    PublishResult publishResult = snsClient.publish(publishRequest);
    return publishResult.getMessageId();
}

From source file:smartthings.brave.sns.PublishRequestTracingHandler.java

License:Apache License

@Override
public void afterResponse(Request<?> request, Response<?> response) {
    if (response.getAwsResponse() instanceof PublishResult) {
        PublishResult publishResult = (PublishResult) response.getAwsResponse();

        Span span = tracing.tracer().currentSpan();

        if (publishResult != null && publishResult.getMessageId() != null) {
            span.tag(SNS_MESSAGE_ID, publishResult.getMessageId());
            span.flush();/*from  www  .j av  a 2 s . c o  m*/
        }
    }
}

From source file:tools.AmazonSNSClientWrapper.java

License:Open Source License

public void demoNotification(Platform platform, String platformToken,
        Map<Platform, Map<String, MessageAttributeValue>> attrsMap, String platformApplicationArn) {

    // 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);
    if (publishResult != null) {
        System.out.println("Published! \n{MessageId=" + publishResult.getMessageId() + "}");
    }/*from   ww  w.  j  a  va 2  s .  c  o m*/
}

From source file:ws.argo.transport.probe.standard.AmazonSNSTransport.java

License:MIT License

@Override
public void sendProbe(Probe probe) throws TransportException {
    String msg;/*from   w ww  .  ja  v  a2 s . c  om*/
    try {
        msg = probe.asXML();
    } catch (JAXBException e) {
        throw new TransportException("Error trying to send probe payload", e);
    }
    PublishRequest publishRequest = new PublishRequest(argoTopicName, msg);
    PublishResult publishResult = snsClient.publish(publishRequest);
    // print MessageId of message published to SNS topic
    LOGGER.debug("Send probe payload as message id [" + publishResult.getMessageId() + "]: " + msg);

}