2

I'm migrating to the new spring cloud stream version. Spring Cloud Stream 3.1.0

And I have the following consumer configuration:

someChannel-in-0:
  destination: Response1
  group: response-channel
  consumer:
    concurrency: 4

 someChannel-out-0:
   destination: response2

I have connected this channel to the new function binders

// just sample dummy code
@Bean
    public Function<Flux<String>, Flux<String>> aggregate() {
        return inbound -> inbound.
                .map(w -> w.toLowerCase());
    }

And when I'm starting the app I'm getting the following error:

Concurrency > 1 is not supported by reactive consumer, given that project reactor maintains its own concurrency mechanism.

My question is what is the equivalent of concurrency: 4 in project reactor and how do I implement this ?

orirab
  • 2,915
  • 1
  • 24
  • 48
Rami Loiferman
  • 853
  • 1
  • 6
  • 22
  • 1
    Your question is really related to project reactor and the various different ways you can control concurrency (e.g., `.subscribeOn(Schedulers.parallel())`), so consider asking in rector forum for more details. That said, if you are migrating to functional programming model from StreamListener I would suggest a non-reactive function first (`Function`). This way you could still benefit from all the existing properties for regular message handlers that you had before moving to more advanced world of reactive approach. – Oleg Zhurakousky Feb 01 '21 at 17:48
  • @OlegZhurakousky how would the integrations between the reactor concurrency and the rabbit concurrency go? does spring "translate" this automatically, or do I need to define some thing explicitly? – orirab Feb 03 '21 at 05:49

1 Answers1

0

Basically, Spring cloud stream manage consumers through MessageListenerContainer and it provides a hook which allow users create a bean and inject some advanced configurations. And so here comes to the solution if you are using RabbitMQ as messaging middleware.

@Bean
public ListenerContainerCustomizer<AbstractMessageListenerContainer> listenerContainerCustomizer() {
    return (container, destinationName, group) -> {
        if (container instanceof SimpleMessageListenerContainer) {
            ((SimpleMessageListenerContainer) container).setConcurrency("3");
        }
    };
}