今天测试rabbitmq消息持久化,一直没成功,不知道问题出在哪,大家帮忙看看,先谢谢了!!!测试代码:
rabbitmq消息public class ClientSend1{
    public static final String queue_name="my_queue";
    public static final boolean durable=true; //消息队列持久化
    public static void main(String[] args)
    throws java.io.IOException{
        ConnectionFactory factory=new ConnectionFactory(); //创建连接工厂
        factory.setHost("localhost");
        Connection connection=factory.newConnection(); //创建连接
        Channel channel=connection.createChannel();//创建信道
        channel.queueDeclare(queue_name, durable, false, false, null); //声明消息队列,且为可持久化的
        String message="Hello world"+Math.random();
        //将队列设置为持久化之后,还需要将消息也设为可持久化的,MessageProperties.PERSISTENT_TEXT_PLAIN
        channel.basicPublish("", queue_name, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes());
        System.out.println("Send message:"+message);
        channel.close();
        connection.close();
    }
}步骤:
1,启动rabbitmq server
2,运行以上java代码
3,使用rabbitmqctl查看消息
D:\sbin>rabbitmqctl list_queues name messages_ready messages_unacknowledged
Listing queues ...
my_queue        1       0
4,关闭rabbitmq server,再启动
5,使用rabbitmqctl查看消息
D:\sbin>rabbitmqctl list_queues name messages_ready messages_unacknowledged
Listing queues ...
my_queue        0       0对比rabbitmq server重启前后消息查看结果,消息并没有持久化,但是队列是持久化了的。请高人指点,问题出在哪里(如果方便,请给出正确的源码)