rabbitMq发送、接受对象消息

//jar包
     
            com.fasterxml.jackson.core
            jackson-core
            2.13.3
        
        
            com.fasterxml.jackson.core
            jackson-annotations
            2.13.3
        

        
            com.fasterxml.jackson.core
            jackson-databind
            2.13.3
        


		
2//发送对象消息		
        UserDto userDto=new UserDto();
        userDto.setId("1233");
        userDto.setName("中国人民");

        ObjectMapper objectMapper=new ObjectMapper();
        String string = objectMapper.writeValueAsString(userDto);
        sendMessage(string);
		

3//接收消息		
@Component
@RabbitListener(queues = "监听队列名")
public class Receiver {
    
  
    @RabbitHandler
    public void handle(String str) throws IOException {
        System.out.println("========================================");
        ObjectMapper objectMapper=new ObjectMapper();


        UserDto userDto = objectMapper.readValue(str, UserDto.class);
        System.out.println(userDto.toString());


        LOGGER.info("receive message str:{}",userDto);
       
    }
}

你可能感兴趣的:(java-rabbitmq,rabbitmq,java)