Spring Cloud Stream-基于带有RabbitMQ活页夹的有效负载类型的调用处理程序

问题描述 投票:0回答:1

使用Spring AMQP,我可以设置一个包含多个RabbitHandler的RabbitListener,将要调用的RabbitListener取决于https://docs.spring.io/spring-amqp/reference/html/#message-listener-adapter中提到的有效负载类型:

@RabbitListener(id="multi", queues = "someQueue")
@SendTo("my.reply.queue")
public class MultiListenerBean {

    @RabbitHandler
    public String thing2(Thing2 thing2) {
        //gets called when the payload is of type Thing2
    }

    @RabbitHandler
    public String cat(Cat cat) {
        //gets called when the payload is of type Cat
    }

    @RabbitHandler
    public String hat(@Header("amqp_receivedRoutingKey") String rk, @Payload Hat hat) {
        //gets called when the payload is of type Hat
    }

    @RabbitHandler(isDefault = true)
    public String defaultMethod(Object object) {
        //gets called when the payload doesn't match other handlers' types
    }

}

如何使用Spring Cloud Stream实现类似的行为?

spring-boot spring-cloud-stream spring-amqp spring-rabbitmq
1个回答
0
投票

[当您说“相同”时,尚不清楚,因为您提供了几种机制(例如,类型,标头等)的示例。也就是说,s-c-stream确实为routing TO/FROM destinations提供了灵活的机制。

© www.soinside.com 2019 - 2024. All rights reserved.