完善rabbitmq配置

This commit is contained in:
2024-03-29 22:42:32 +08:00
parent de70b7bbcb
commit 6830b43c18

View File

@@ -1,8 +1,13 @@
package cn.lihongjie.coal.rabbitmq;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.core.*;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.amqp.RabbitTemplateCustomizer;
import org.springframework.boot.convert.DurationStyle;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -27,6 +32,14 @@ public class RabbitMQConfiguration {
public static final Long[] DELAY_QUEUES_TIME = Arrays.stream(DELAY_QUEUES).map(x -> DurationStyle.detectAndParse(x).toMillis()).toArray(Long[]::new);
@Autowired private ObjectMapper objectMapper;
@Bean
RabbitTemplateCustomizer rabbitTemplateCustomizer() {
return template -> {
template.setMessageConverter(new Jackson2JsonMessageConverter(objectMapper));
};
}
@Bean