1

I have to listen a queue using spring integration flow and intgeration sqs. Once message is received from queue it should trigger a integration flow. Below is the things which I am trying but everythings fine in but afater receiving test it is not triggering any Integration flow. Please let me know where I am doing wrong:

UPDATED as per comment from Artem

Adapter for SQS.

@Bean
  public MessageProducerSupport sqsMessageDrivenChannelAdapter() {
    SqsMessageDrivenChannelAdapter adapter = new SqsMessageDrivenChannelAdapter(amazonSQSAsync, "Main");
    adapter.setOutputChannel(inputChannel());
    adapter.setAutoStartup(true);
    adapter.setMessageDeletionPolicy(SqsMessageDeletionPolicy.NEVER);
    adapter.setMaxNumberOfMessages(10);
    adapter.setVisibilityTimeout(5);
    return adapter;
  }

Queue configured:

@Bean
  public MessageChannel inputChannel() {
    return new DirectChannel();
  }

Now the main integration flow trigger point:

@Bean
  public IntegrationFlow inbound() {
    return IntegrationFlows.from("inputChannel").transform(i -> "TEST_FLOW").get();
  }
  }

Appreciate any type of help.

1 Answers1

1
  1. The sqsMessageDrivenChannelAdapter() must be declared as a @Bean
  2. The inbound() must be declared as a @Bean
  3. This one fully does not make sense IntegrationFlows.from(MessageChannels.queue()). What is the point to start the flow from anonymous channel? Who and how is going to produce messages to that channel?

Make yourself familiar with different channels: https://docs.spring.io/spring-integration/docs/current/reference/html/core.html#channel-implementations

Pay attention that QueueChannel must be consumed via polling endpoint. Right, there is a default poller auto-configured by Spring Boot, but it is based on a single thread in the TaskScheduler and has a polling period as 10 millis.

I wouldn't recommend to hand off SQS messages to the QueueChannel: when consumer fails, you lose the data. It is better to process those messages in the consumer thread.

Otherwise your intention is not clear in the provided code.

Can you, please, share with us what error you get or anything else?

You also can turn on DEBUG logging level for org.springframework.integration to see how your messages are processed.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Hi Artem, I have updated the code as per the suggestions. I think I am doing wrong something in IntegratonFlow. Any way to correct this? My use case is to get the message from SQS and pass that message to IntegrationFlow. – Vipul Tiwari Dec 07 '22 at 19:30
  • Just do `return new DirectChannel();`. Then just use `from("inputChannel")`. Otherwise you are confusing the framework what exactly bean to use. The `inputChannel` is that bean method name and that's enough to use it as a reference everywhere. You can, of course, `from("tempChannel")`, but then you have to do `adapter.setOutputChannelName("tempChannel");` – Artem Bilan Dec 07 '22 at 19:36
  • Sorry Artem for giving you trouble but after the changes it is giving below error. Dispatcher has no subscribers for channel 'unknown.channel.name'.; – Vipul Tiwari Dec 07 '22 at 19:52
  • Do you have `@EnableIntegration` on one of your `@Configuration` ? – Artem Bilan Dec 07 '22 at 20:03
  • Yes I have `@EnableIntegration` on test class – Vipul Tiwari Dec 07 '22 at 20:15
  • What is "test class"? The code you show right now in the question is OK, so, you probably just don't show us enough. Your exception might only mean that your `inbound` is not parsed properly. This can happen if there is no `@EnableIntegration`. Otherwise consider to share with us a simple project to reproduce and play with. – Artem Bilan Dec 07 '22 at 20:37