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;
|
2025-08-27 16:42:13 +08:00
|
|
|
|
import org.springframework.amqp.core.ExchangeBuilder;
|
|
|
|
|
|
import org.springframework.amqp.core.HeadersExchange;
|
2025-06-12 19:44:47 +08:00
|
|
|
|
import org.springframework.amqp.core.Queue;
|
2025-08-27 16:42:13 +08:00
|
|
|
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
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 {
|
2025-08-27 16:42:13 +08:00
|
|
|
|
|
2025-06-12 19:44:47 +08:00
|
|
|
|
private static final String QUEUE = "HOST_INFO_QUEUE";
|
2025-08-27 16:42:13 +08:00
|
|
|
|
|
|
|
|
|
|
public static final String EXCHANGE_NAME = "user.headers.exchange";
|
|
|
|
|
|
|
2025-11-10 20:43:43 +08:00
|
|
|
|
public static final String AI_CHAT_EXCHANGE_NAME = "ai.chat.headers.exchange";
|
|
|
|
|
|
public static final String BIG_BROTHER_EXCHANGE_NAME = "big.brother.headers.exchange";
|
2025-12-05 13:57:34 +08:00
|
|
|
|
public static final String WEB_AI_EXCHANGE_NAME = "web.ai.headers.exchange";
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-10 20:43:43 +08:00
|
|
|
|
|
2025-06-12 19:44:47 +08:00
|
|
|
|
//创建队列
|
|
|
|
|
|
//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-08-27 16:42:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
public HeadersExchange userHeadersExchange() {
|
|
|
|
|
|
return ExchangeBuilder.headersExchange(EXCHANGE_NAME)
|
|
|
|
|
|
.durable(true)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-10 20:43:43 +08:00
|
|
|
|
@Bean
|
|
|
|
|
|
public HeadersExchange aiChatHeadersExchange() {
|
|
|
|
|
|
return ExchangeBuilder.headersExchange(AI_CHAT_EXCHANGE_NAME)
|
|
|
|
|
|
.durable(true)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
public HeadersExchange bigBrotherHeadersExchange() {
|
|
|
|
|
|
return ExchangeBuilder.headersExchange(BIG_BROTHER_EXCHANGE_NAME)
|
|
|
|
|
|
.durable(true)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-05 13:57:34 +08:00
|
|
|
|
@Bean
|
|
|
|
|
|
public HeadersExchange webAiHeadersExchange() {
|
|
|
|
|
|
return ExchangeBuilder.headersExchange(WEB_AI_EXCHANGE_NAME)
|
|
|
|
|
|
.durable(true)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-10 20:43:43 +08:00
|
|
|
|
|
2025-08-27 16:42:13 +08:00
|
|
|
|
@Bean
|
|
|
|
|
|
public RabbitAdmin rabbitAdmin(ConnectionFactory cf) {
|
|
|
|
|
|
return new RabbitAdmin(cf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|