2 Replies Latest reply: Jan 15, 2013 4:05 AM by eng.fouad RSS

HornetQ does not persist messages after restart

eng.fouad Newbie

I am using HornetQ as a queue provider as it has persistence capabilities. However, after I restart the application, all the messages in the queue are lost. Maybe configuration issues?

Here is the code:

 

// Step 1. Create the Configuration, and set the properties accordingly
Configuration configuration = new ConfigurationImpl();
configuration
.setPersistenceEnabled(true);
configuration
.setPersistIDCache(true);
configuration
.setJMXManagementEnabled(true);
configuration
.setMessageCounterEnabled(true);
configuration
.setPersistDeliveryCountBeforeDelivery(true);
configuration
.setSecurityEnabled(false);
configuration
.setJournalSyncTransactional(true);
configuration
.setJournalSyncNonTransactional(true);
configuration
.setJournalType(JournalType.NIO);

HashSet<TransportConfiguration> transports = new HashSet<TransportConfiguration>();

transports
.add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
transports
.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
    configuration
.setAcceptorConfigurations(transports);

// Step 2. Create and start the server
eServer
= new EmbeddedHornetQ();
eServer
.setConfiguration(configuration);
eServer
.start();

// Step 3. As we are not using a JNDI environment we instantiate the objects irectly
ServerLocator serverLocator = HornetQClient.createServerLocatorWithHA(new TransportConfiguration(NettyConnectorFactory.class.getName()), new TransportConfiguration(InVMConnectorFactory.class.getName()));
sessionFactory
= serverLocator.createSessionFactory();

// Step 4. Create a core queue
coreSession
= sessionFactory.createSession(true, true, true);
QueueQuery qq = coreSession.queueQuery(SimpleString.toSimpleString(QUEUE_NAME));
if(!qq.isExists()) coreSession.createQueue(QUEUE_NAME, QUEUE_NAME, true);
coreSession
.close();

// Step 5. Create the session, and the producer
session
= sessionFactory.createSession();
producer
= session.createProducer(QUEUE_NAME);

// Step 6. Create the message consumer and set a listener
ClientConsumer messageConsumer = session.createConsumer(QUEUE_NAME);
messageConsumer
.setMessageHandler(new QueueListener(session, producer));

// Step 7. Start the connection.
session
.start();

// ...

// put 50,000 messages into the queue

// ...

session
.close();
sessionFactory
.close();
eServer
.stop();

I have also tried to print the journal files, but the message count is always 0:

 

JournalStorageManager.describeMessagesJournal(journalDirectory);


#JournalFileImpl: (hornetq-data-1.hq id = 209, recordID = 209)
#JournalFileImpl: (hornetq-data-2.hq id = 210, recordID = 210)
#JournalFileImpl: (hornetq-data-3.hq id = 211, recordID = 211)
#JournalFileImpl: (hornetq-data-4.hq id = 212, recordID = 212)
#JournalFileImpl: (hornetq-data-9.hq id = 213, recordID = 213)
#JournalFileImpl: (hornetq-data-10.hq id = 214, recordID = 214)
#JournalFileImpl: (hornetq-data-17.hq id = 215, recordID = 215)
#JournalFileImpl: (hornetq-data-18.hq id = 216, recordID = 216)
#JournalFileImpl: (hornetq-data-35.hq id = 217, recordID = 217)
#JournalFileImpl: (hornetq-data-36.hq id = 218, recordID = 218)
#JournalFileImpl: (hornetq-data-57.hq id = 219, recordID = 219)
#JournalFileImpl: (hornetq-data-58.hq id = 220, recordID = 220)
#JournalFileImpl: (hornetq-data-71.hq id = 221, recordID = 221)
#JournalFileImpl: (hornetq-data-72.hq id = 222, recordID = 222)
#JournalFileImpl: (hornetq-data-73.hq id = 223, recordID = 223)
#JournalFileImpl: (hornetq-data-74.hq id = 224, recordID = 224)
#JournalFileImpl: (hornetq-data-187.hq id = 225, recordID = 225)
#JournalFileImpl: (hornetq-data-188.hq id = 226, recordID = 226)
#JournalFileImpl: (hornetq-data-207.hq id = 227, recordID = 227)
#JournalFileImpl: (hornetq-data-208.hq id = 228, recordID = 228)

### Surviving Records Summary ###

### Prepared TX ###

### Message Counts ###
message count
=0
message reference count
prepared message count
=0

 

Here is the link of the same question on SO: http://stackoverflow.com/q/14332916/597657