@JMSListener 和@Consume 注释之间的区别?
Difference between @JMSListener and @Consume annotations?
我正在尝试使用带@Consume 注释的 bean 使用通过 spring JmsTemplate 发送的 JMS 消息。消费者在使用 JmsTemplate 发送时收不到消息。
然而,当使用 Camel 的 ProducerTemplate 发送时,消息被接收。
@org.springframework.jms.annotation.JmsListener和@org.apache.camel.Consume有什么区别?
生产者逻辑
jmsTemplate.convertAndSend("jms:mailbox", message);
消费者逻辑
@Consume(uri="jms:mailbox")
public void onRequest(String name) {
System.out.println("Received message > "+name);
}
Apache Camel @Consume
annotation can consume from any endpoint, which supports consuming. This annotation takes uri
as parameter. URI consists of scheme, path and optional params. In case of JMS component the scheme is jms
, path is Destination
(在您的情况下 mailbox
)和参数是自定义 Consumer
.
行为的附加选项
Spring @JmsListener
can consume from JMS and takes Destination
作为参数。
您的代码不起作用,因为 Destination
是 mailbox
,而不是 jms:mailbox
。 Spring JmsTemplate
不知道 jms
方案,它是 Camel 特有的。因此,在 Spring 侧使用 jmsTemplate.convertAndSend("mailbox", message)
,在 Camel 侧使用 @Consume(uri="jms:mailbox")
。
我正在尝试使用带@Consume 注释的 bean 使用通过 spring JmsTemplate 发送的 JMS 消息。消费者在使用 JmsTemplate 发送时收不到消息。
然而,当使用 Camel 的 ProducerTemplate 发送时,消息被接收。
@org.springframework.jms.annotation.JmsListener和@org.apache.camel.Consume有什么区别?
生产者逻辑
jmsTemplate.convertAndSend("jms:mailbox", message);
消费者逻辑
@Consume(uri="jms:mailbox")
public void onRequest(String name) {
System.out.println("Received message > "+name);
}
Apache Camel @Consume
annotation can consume from any endpoint, which supports consuming. This annotation takes uri
as parameter. URI consists of scheme, path and optional params. In case of JMS component the scheme is jms
, path is Destination
(在您的情况下 mailbox
)和参数是自定义 Consumer
.
Spring @JmsListener
can consume from JMS and takes Destination
作为参数。
您的代码不起作用,因为 Destination
是 mailbox
,而不是 jms:mailbox
。 Spring JmsTemplate
不知道 jms
方案,它是 Camel 特有的。因此,在 Spring 侧使用 jmsTemplate.convertAndSend("mailbox", message)
,在 Camel 侧使用 @Consume(uri="jms:mailbox")
。