Multiple instances of HornetQ Server while enabling persistency
eng.fouad Mar 20, 2013 4:55 AMHi there,
I need to run a core hornetQ server by code (not xml) with enabling persistencty. I want to run multiple instances of the server on the same machine. However, server B always waits for "server.lock" until the server A releases that lock (on shutdown of course). How to achieve that? Maybe something related to the cluster environment? Here is my 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); | ||
configuration.setThreadPoolMaxSize(100); | ||
AddressSettings as = new AddressSettings(); | ||
as.setRedeliveryDelay(10000); // 10 seconds | ||
as.setMaxDeliveryAttempts(Integer.MAX_VALUE); | ||
configuration.getAddressesSettings().put("#", as); | ||
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 2. Create and start the server | ||||||||||||
//iServer = HornetQServers.newHornetQServer(configuration); | ||||||||||||
//iServer.start(); | ||||||||||||
// Step 3. As we are not using a JNDI environment we instantiate the objects directly | ||||||||||||
ServerLocator serverLocator = HornetQClient.createServerLocatorWithHA( | ||||||||||||
new TransportConfiguration(NettyConnectorFactory.class.getName()), | ||||||||||||
new TransportConfiguration(InVMConnectorFactory.class.getName())); | ||||||||||||
serverLocator.setUseGlobalPools(true); | ||||||||||||
serverLocator.setThreadPoolMaxSize(-1); | ||||||||||||
serverLocator.setProducerWindowSize(-1); | ||||||||||||
serverLocator.setProducerMaxRate(-1); | ||||||||||||
serverLocator.setConsumerWindowSize(-1); | ||||||||||||
serverLocator.setConsumerMaxRate(-1); | ||||||||||||
serverLocator.setBlockOnDurableSend(true); | ||||||||||||
sessionFactory = serverLocator.createSessionFactory(); | ||||||||||||
// Step 4. Create a core queue | ||||||||||||
session = sessionFactory.createSession(true, true, 0); | ||||||||||||
QueueQuery qq = session.queueQuery(SimpleString.toSimpleString(QUEUE_NAME)); | ||||||||||||
if(!qq.isExists()) session.createQueue(QUEUE_NAME, QUEUE_NAME, true); | ||||||||||||
else messageCount.set(qq.getMessageCount()); | ||||||||||||
// Step 5. Create the session, and the producer | ||||||||||||
producer = session.createProducer(QUEUE_NAME); | ||||||||||||
// Step 6. Create the message consumer and set a listener | ||||||||||||
ClientConsumer consumer = session.createConsumer(QUEUE_NAME); | ||||||||||||
consumer.setMessageHandler(new QueueListener(session)); | ||||||||||||
// Step 7. Start the connection. | ||||||||||||
session.start(); |