问题
I would like to know the exactly meaning of "concurrency" when using spring.cloud.stream.default.consumer.concurrency property.
Documentation (https://docs.spring.io/spring-cloud-stream/docs/Chelsea.RELEASE/reference/html/_configuration_options.html) says "The concurrency of the inbound consumer" and this can be interpreted in several ways.
What kind of thread executor is created behind the scenes?
Thanks!
回答1:
The semantics of concurrency is dependent on the actual binder implementation. For example in the case of the Kafka binder, when you set concurrency, that value will be passed on to the underlying MessageListenerContainer
. Lets say that your consumer application is consuming from a topic that has 3 partitions and you set the value of concurrency
to 3. This will create 3 threads by the container in which each of them is handling a single partition from the topic (In fact, in the case of Kafka binder, 3 listener containers will be created behind the scenes). If there are more partitions on the topic than there are concurrent threads, then the partitions will be distributed across the various threads. The same semantics apply for the Rabbit binder as well although the actual implementation of it may vary slightly internally.
来源:https://stackoverflow.com/questions/54260536/spring-cloud-stream-spring-cloud-stream-default-consumer-concurrency-property-e