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.
Asked
Active
Viewed 4,365 times
2

Gary Russell
- 166,535
- 14
- 146
- 179

Sebastian Dusza
- 2,470
- 2
- 30
- 54
-
1The readme on their github page is a really good starting point (https://github.com/spring-projects/spring-integration-aws). Is there anything specifically missing from there you need assistance with? – Not a JD Mar 28 '19 at 19:39
-
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 Mar 28 '19 at 19:59
-
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 Mar 28 '19 at 21:02
1 Answers
4
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

Artem Bilan
- 113,505
- 11
- 91
- 118
-
Don't I have to define default poller also ? If I don't add this bean I can an error 'No poller has been defined for Annotation-based endpoint, ...' Is PollerMetadata with new PeriodicTrigger(200) good configuration for this queue ? – Sebastian Dusza Apr 01 '19 at 11:49