[英]How to add MessageConverter on Spring boot Messaging
How do I define a MessageConverter for a destination using spring boot? 如何使用Spring Boot为目标定义MessageConverter? I have already defined my message broker and JMS Listener. 我已经定义了消息代理和JMS侦听器。
@JmsListener(destination = "new.clinic.queue")
public void receiveNewClinic(MyCustomDTO message) {
}
and my message broker 和我的消息经纪人
@Bean
public BrokerService broker() throws Exception {
BrokerService broker = new BrokerService();
broker.setBrokerName(brokerName);
broker.addConnector(brokerAddress);
return broker;
}
How do I add my own message converter for MyCustomDTO 如何为MyCustomDTO添加自己的消息转换器
You need to create a JmsMessageContainerFactory
and configure it accordingly. 您需要创建一个JmsMessageContainerFactory
并进行相应的配置。 Spring Boot creates one for you but you can create as much instances as you want with your own customizations and refer them using the containerFactory
of the @JmsListener
annotation. Spring Boot为您创建了一个实例,但是您可以使用自己的自定义项创建任意数量的实例,并使用@JmsListener
批注的containerFactory
引用它们。
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setMessageConverter(yourMessageConverter());
// .. other settings
return factory;
}
Note that the bean name here is the default name so you don't need to specify a connectionFactory
attribute. 请注意,这里的Bean名称是默认名称,因此您无需指定connectionFactory
属性。
Spring Boot 1.4 will auto-detect your MessageConverter
and assign it to the default factory it auto-creates for you. Spring Boot 1.4将自动检测您的MessageConverter
并将其分配给它为您自动创建的默认工厂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.