release- RabbitMQConfig

release-2024-08-08
pikaqiudeshujia 5 months ago
parent ed43cc3bb7
commit 6ad9a547c6

@ -1,12 +1,12 @@
package com.luoo.music.config; package com.luoo.music.config;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.InitializingBean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
/** /**
* @Author: yawei.huang * @Author: yawei.huang
* @Package: com.macro.mall.config * @Package: com.macro.mall.config
@ -16,20 +16,20 @@ import javax.annotation.Resource;
* @Describe: * @Describe:
*/ */
@Configuration @Configuration
public class RabbitMQConfig implements InitializingBean { public class RabbitMQConfig {
/** @Bean
* RabbitTemplate public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
*/ RabbitTemplate template = new RabbitTemplate(connectionFactory);
@Resource template.setMessageConverter(new Jackson2JsonMessageConverter());
private RabbitTemplate rabbitTemplate; return template;
}
/** @Bean
* JSON public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
*/ SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
@Override factory.setConnectionFactory(connectionFactory);
public void afterPropertiesSet() { factory.setMessageConverter(new Jackson2JsonMessageConverter());
//使用JSON序列化 return factory;
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
} }
} }

Loading…
Cancel
Save