生产者
java
private final RabbitTemplate rabbitTemplate;
@GetMapping("/putRecord") //插入记录
public Result userMessage(){
Map<String ,String> map =new HashMap<>();
map.put("name","生产队的驴");
map.put("qq","147258");
rabbitTemplate.convertAndSend("csdn.fanout","a",map);
return Result.success("操作成功",null);
}
生产者正常发送消息,而到了队列就变成了这样,自动转换成字节导致体积变大。
rO0ABXNyABFqYXZhLnV0aWwuSGFzaE1hcAUH2sHDFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAx3CAAAABAAAAACdAACcXF0AAYx
NDcyNTh0AARuYW1ldAAP55Sf5Lqn6Zif55qE6am0eA==
消息转换器
导入JSON依赖进行序列化
xml
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
声明依赖
在springboot的启动类上声明
java
@SpringBootApplication
public class Demo1Application {
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
}
@Bean
public MessageConverter jackonMessageConverter(){
return new Jackson2JsonMessageConverter();
}
}