2025-06-12 19:44:47 +08:00
|
|
|
|
package com.yupi.springbootinit.config;
|
|
|
|
|
|
|
2025-06-26 19:12:27 +08:00
|
|
|
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
|
|
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
|
|
|
import com.rabbitmq.client.ConnectionFactory;
|
2025-06-12 19:44:47 +08:00
|
|
|
|
import org.springframework.amqp.core.Queue;
|
2025-06-26 19:12:27 +08:00
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
2025-06-12 19:44:47 +08:00
|
|
|
|
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
|
|
|
|
|
import org.springframework.amqp.support.converter.MessageConverter;
|
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
|
public class RabbitMQConfig {
|
|
|
|
|
|
private static final String QUEUE = "HOST_INFO_QUEUE";
|
|
|
|
|
|
|
|
|
|
|
|
//创建队列
|
|
|
|
|
|
//true:表示持久化
|
|
|
|
|
|
//队列在默认情况下放到内存,rabbitmq重启后就丢失了,如果希望重启后,队列
|
|
|
|
|
|
//数据还能使用,就需要持久化
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
public Queue hostInfoQueue(){
|
|
|
|
|
|
return new Queue(QUEUE,true);
|
|
|
|
|
|
}
|
2025-06-26 19:12:27 +08:00
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
// @Bean
|
|
|
|
|
|
// public MessageConverter messageConverter(){
|
|
|
|
|
|
// return new Jackson2JsonMessageConverter();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
2025-06-12 19:44:47 +08:00
|
|
|
|
@Bean
|
2025-06-26 19:12:27 +08:00
|
|
|
|
public MessageConverter messageConverter() {
|
|
|
|
|
|
ObjectMapper om = new ObjectMapper();
|
|
|
|
|
|
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
|
|
|
|
|
om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
|
|
|
|
|
om.registerModule(new JavaTimeModule());
|
|
|
|
|
|
return new Jackson2JsonMessageConverter(om);
|
2025-06-12 19:44:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|