简体   繁体   English

如何在Spring Boot Messaging上添加MessageConverter

[英]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.

相关问题 spring boot rabbitmq MappingJackson2MessageConverter 自定义对象转换 - spring boot rabbitmq MappingJackson2MessageConverter custom object conversion 运行Spring Boot应用程序时RabbitMQ MessageConverter提供错误 - RabbitMQ MessageConverter giving error when running Spring Boot app 用于Spring Boot REST应用程序的MessageConverter的自定义实现不起作用 - Custom implementation for MessageConverter for Spring boot REST application not working Spring 启动 kafka 消息传递。 如何简化处理程序的 dto 映射? - Spring boot kafka messaging. How to simplify dto mapping for handlers? Spring Boot JMS MappingJackson2MessageConverter即使存在_type字段也找不到 - Spring Boot JMS MappingJackson2MessageConverter cannot find `_type` field even though it exists Spring RestTemplate - 选择 MessageConverter 使用 - Spring RestTemplate - selecting MessageConverter to Use Spring MessageConverter HTTP 415响应? - Spring MessageConverter HTTP 415 response? 如何在Spring Boot 2和Activiti 7中添加Activiti Spring Boot Starter Basic? - How to add activiti spring boot starter basic in spring boot 2 and activiti 7? 将org.springframework.amqp.support.converter.MessageConverter转换为org.springframework.messaging.converter.MessageConverter - Convert a org.springframework.amqp.support.converter.MessageConverter to a org.springframework.messaging.converter.MessageConverter 如何在Spring Boot中使用Vaadin附加组件? - How to use Vaadin add-on with Spring Boot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM