0

In my Code, SqsMessageDrivenChannelAdapter channel adapter configured to read message from AWS queue and push to a pollable channel(Queue). To the pollable channel,a service activator is pointing to poll message and process.

My Exact question: How to make work service activator as multithreaded to poll message from pollable channel and do some parallel task by specified thread size.

Channel Adapter:

@Bean
  public MessageProducer sqsMessageDrivenChannelAdapterForFlights() {
    log.info("**** start listening to: " + ttFlightsXMLSqsName + " **** ");
    SqsMessageDrivenChannelAdapter adapter =
        new SqsMessageDrivenChannelAdapter(amazonSqs, ttFlightsXMLSqsName);
    adapter.setOutputChannelName(MessageChannelConstants.get_tt_flights);
    adapter.setMaxNumberOfMessages(5);
    return adapter;
  }

Pollable Channel:

@Bean(name = MessageChannelConstants.get_tt_flights)
  public PollableChannel sqsInputChannelFlights() {
    return new QueueChannel();
  }

Service activator:

  @ServiceActivator(inputChannel = MessageChannelConstants.get_tt_flights,
      poller = @Poller(fixedRate = "5000"))
  public void processFlightData(Message<?> receive) throws PacPlusException {
    .................
   long startTime = System.currentTimeMillis();
}

Final question: If I make two service activator pointing to the same pollable channel will it work perfectly and is it good to use kind of parallel message process?

1 Answers1

1

See an task-executor option for the poller configuration. Exactly this one makes the same service activator to be called in parallel. See more in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/endpoint.html#endpoint-namespace

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Hi Artem Bilan, thanks for your answer. I tried task-executor as below. But on seeing logs seems it does not execute parallely. If it is running multithread way then I suppose to see log should be in non sequence. How to ensure it is working multithread way. – user2393260 Dec 05 '21 at 14:18
  • See `maxMessagesPerPoll`. It is unlimited by default for service activator . So, all messages in the queue are polled by a single thread – Artem Bilan Dec 05 '21 at 15:07