月光代碼園

記錄、分享、交流

导航

RabbitMQ #2 持久化

return new Queue("testQueue",true,false,false,map);

return new DirectExchange("testExchange",true,false);

 MessagePostProcessor messagePostProcessor = message -> {
            message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
            return message;
        };
        rabbitTemplate.convertAndSend("testExchange","testRoutingKey", msg, messagePostProcessor);

  

 

 消息似乎默认是持久化的

public static int toInt(MessageDeliveryMode mode) {
        switch(mode) {
        case NON_PERSISTENT:
            return 1;
        case PERSISTENT:
            return 2;
        default:
            return -1;
        }
    }

  

posted on 2022-07-15 10:47  bangdikka  阅读(47)  评论(0编辑  收藏  举报