[rabbitmq-discuss] How to persist message when mq server restarts?

cheepu shammi at arosys.com
Fri Mar 16 10:18:00 GMT 2012

I am using RabbitMQ2.7 and having following code for the Publisher 

public void producer(String message,int noOfMessage) {
         try {
            String exchangeType = "direct";
            boolean durable = true;
            channel = mqConnection.createChannel();         
            channel.exchangeDeclare(exchangeName, exchangeType, durable);
            channel.queueDeclare(queueName, durable, false, false, null);
            channel.queueBind(queueName, exchangeName, routekeyName);
            QueueingConsumer consumer = new QueueingConsumer(channel);
            channel.basicConsume(queueName, false, consumer); //false

            AMQP.BasicProperties props = new AMQP.BasicProperties();
            int counter = 0;
            while (counter++<noOfMessage) {                
                 byte[] messageBodyBytes=message.getBytes();
                 channel.basicPublish(exchangeName, routekeyName, props,
                 logger.info("Message Published: "+counter+" "+message);
        }  // end of While

        } catch (Exception e) {
            logger.error("Exception "+e);

Messages are persistent when the server is running but when I restart the
server all the published messages are lost. For now there are no consumer
As I know that for persistence of message queue should be durable and
deliveryMode should be 2 and I have configured that. What additional setting
needs to be done for the persistence of message even after the server goes

View this message in context: http://old.nabble.com/How-to-persist-message-when-mq-server-restarts--tp33516102p33516102.html
Sent from the RabbitMQ mailing list archive at Nabble.com.

More information about the rabbitmq-discuss mailing list