2

永続化機能があるため、HornetQ をキュー プロバイダーとして使用しています。ただし、アプリケーションを再起動すると、キュー内のすべてのメッセージが失われます。もしかして設定の問題?

コードは次のとおりです。

// 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();

ジャーナル ファイルも印刷しようとしましたが、メッセージ数は常に 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
4

2 に答える 2

1

HornetQ User Forumの Andy Taylor氏の回答に感謝します。問題は、次のような永続的でないメッセージの作成にありました。

ClientMessage cMessage = session.createMessage(false);

に変更しただけでtrue、現在はうまく機能しています。

于 2013-01-15T09:22:19.687 に答える