[英]Use @SentTo to send a message with Spring Boot and RabbitMq
Is it possible to send a return value of any method to a queue using an annotation, like 是否可以使用注释将任何方法的返回值发送到队列,例如
@SentTo("my.queue.name")
String send() {
return myString;
}
Do I definitely need a @RabbitListener to use @SendTo? 我肯定需要@RabbitListener来使用@SendTo吗? Maybe another way out? 也许是另一种出路?
I'm trying to simplify my code. 我正在尝试简化我的代码。
@SendTo
is only currently for replies from a @RabbitListener
where the sender didn't set a replyTo
header. @SendTo
当前仅用于来自@RabbitListener
答复,其中发件人未设置replyTo
标头。
You could do what you want with a Spring Integration @Publisher
annotation with its channel wired to a rabbitmq outbound channel adapter... 您可以使用Spring Integration @Publisher
注释将其通道连接到rabbitmq出站通道适配器来做您想要的...
@Publisher(channel = "amqpOutboundChannel")
public String send() {
return myString;
}
@Bean
@ServiceActivator(inputChannel = "amqpOutboundChannel")
public AmqpOutboundEndpoint amqpOutbound(AmqpTemplate amqpTemplate) {
AmqpOutboundEndpoint outbound = new AmqpOutboundEndpoint(amqpTemplate);
outbound.setRoutingKey("my.queue.name"); // default exchange - route to queue 'my.queue.name'
return outbound;
}
The method has to be public and invoked from outside the bean itself. 该方法必须是公共的,并且必须从bean本身外部调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.