1
votes

I'm looking for a working example of a Spring app that receives and sends messages to a queue using Spring Integration + Amazon SQS service.

1
The readme on their github page is a really good starting point (github.com/spring-projects/spring-integration-aws). Is there anything specifically missing from there you need assistance with?Not a JD
What do you mean with " two way message exchange"? Request/Reply? Inbound and Outbound Gateways? Then it so no. There is no such an implementation.Artem Bilan
I wanted to see how to configre Spring integration to send to and receive messages using sqs queue. I'm having trouble using code snippets from spring-integration-aws github wiki.Sebastian Dusza

1 Answers

3
votes

This is an example how to configure an outbound channel adapter with an XML:

 <int-aws:sqs-outbound-channel-adapter sqs="sqs"
                                      auto-startup="false"
                                      channel="errorChannel"
                                      phase="100"
                                      id="sqsOutboundChannelAdapter"
                                      queue="foo"
                                      delay-expression="'200'"
                                      message-deduplication-id="foo"
                                      message-group-id-expression="'bar'"
                                      send-timeout="202"
                                      sync="false"
                                      error-message-strategy="errorMessageStrategy"
                                      failure-channel="failureChannel"
                                      success-channel="successChannel"
                                      message-converter="messageConverter"
                                      async-handler="asyncHandler"
                                      resource-id-resolver="resourceIdResolver"/>

The inbound channel adapter looks like this:

<int-aws:sqs-message-driven-channel-adapter sqs="sqs"
                                      auto-startup="false"
                                      channel="errorChannel"
                                      error-channel="nullChannel"
                                      task-executor="taskExecutor"
                                      phase="100"
                                      id="sqsMessageDrivenChannelAdapter"
                                      queues="foo, bar"
                                      message-deletion-policy="NEVER"
                                      max-number-of-messages="5"
                                      visibility-timeout="200"
                                      wait-time-out="40"
                                      send-timeout="2000"
                                      queue-stop-timeout="11000"
                                      destination-resolver="destinationResolver"
                                      resource-id-resolver="resourceIdResolver"/>

And here is Java variant for them:

    @Bean
    @ServiceActivator(inputChannel = "sqsSendChannelWithAutoCreate")
    public MessageHandler sqsMessageHandlerWithAutoQueueCreate() {
        DynamicQueueUrlDestinationResolver destinationResolver = new DynamicQueueUrlDestinationResolver(amazonSqs(), null);
        destinationResolver.setAutoCreate(true);
        return new SqsMessageHandler(amazonSqs(), destinationResolver);
    }


    @Bean
    public MessageProducer sqsMessageDrivenChannelAdapter() {
        SqsMessageDrivenChannelAdapter adapter = new SqsMessageDrivenChannelAdapter(amazonSqs(), "testQueue");
        adapter.setOutputChannel(inputChannel());
        return adapter;
    }

You can find more samples in the tests of the project: https://github.com/spring-projects/spring-integration-aws/tree/master/src/test/java/org/springframework/integration/aws