How to use RMQ and spring cloud stream for creating partition based producer?

无人久伴 提交于 2020-01-15 04:55:15

问题


I am trying to find example of spring cloud stream where it creates parition based producer for RMQ. I want to see how it will create binding for those queues as RMQ not natively support paritions for topic but it will create number of queues equivalent to number of partitions (I read this,I may be wrong). First I want to understand how to create producer using spring cloud stream on RMQ for partition based producer.


回答1:


@SpringBootApplication
@EnableBinding(Source.class)
public class So43614477Application implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(So43614477Application.class, args);
    }

    @Autowired
    private MessageChannel output;

    @Override
    public void run(String... args) throws Exception {
        output.send(MessageBuilder.withPayload("fiz").setHeader("whichPart", 0).build());
        output.send(MessageBuilder.withPayload("buz").setHeader("whichPart", 1).build());
    }

}

with properties...

spring.cloud.stream.bindings.output.destination=foo
spring.cloud.stream.bindings.output.producer.partition-key-expression=headers['whichPart']
spring.cloud.stream.bindings.output.producer.partition-count=2

spring.cloud.stream.bindings.output.producer.required-groups=bar

I added the required-groups so you can see how the consumer queues are bound.

foo exhange bindings:

The expression can be any valid expression evaluated against the message (e.g. payload.hashCode()); it is then modded % against the partition count to determine the final partition.



来源:https://stackoverflow.com/questions/43614477/how-to-use-rmq-and-spring-cloud-stream-for-creating-partition-based-producer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!