JMS Queue Already Exists Exception
iandavies May 2, 2011 5:44 PMHi All,
I have an embedded server I am manually creating using JMSServerManagerImpl. I programmatically set this servers queue configuration object with a single queue. In addition to the client code using the embedded server in the same process i have a client in another process which is consuming events of this same single queue.
To reproduce this:
If i start the process hosting the embedded server,
Then start the other client process and wait for it to connect and set up it's message consumer,
Then kill the server process and
Finally restart it i get this error:
HornetQException[errorCode=101 message=Queue jms.queue.myQueue already exists]
at org.hornetq.core.server.impl.HornetQServerImpl.createQueue(HornetQServerImpl.java:1321)
at org.hornetq.core.server.impl.HornetQServerImpl.createQueue(HornetQServerImpl.java:688)
at org.hornetq.core.server.impl.ServerSessionImpl.createQueue(ServerSessionImpl.java:354)
at org.hornetq.core.protocol.core.ServerSessionPacketHandler.handlePacket(ServerSessionPacketHandler.java:251)
at org.hornetq.core.protocol.core.impl.ChannelImpl.handlePacket(ChannelImpl.java:471)
at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.doBufferReceived(RemotingConnectionImpl.java:451)
at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.bufferReceived(RemotingConnectionImpl.java:412)
at org.hornetq.core.remoting.server.impl.RemotingServiceImpl$DelegatingBufferHandler.bufferReceived(RemotingServiceImpl.java:459)
at org.hornetq.core.remoting.impl.netty.HornetQChannelHandler.messageReceived(HornetQChannelHandler.java:67)
at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:100)
at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:362)
at org.jboss.netty.channel.StaticChannelPipeline$StaticChannelHandlerContext.sendUpstream(StaticChannelPipeline.java:514)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:287)
at org.hornetq.core.remoting.impl.netty.HornetQFrameDecoder2.decode(HornetQFrameDecoder2.java:169)
at org.hornetq.core.remoting.impl.netty.HornetQFrameDecoder2.messageReceived(HornetQFrameDecoder2.java:134)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)
at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:362)
at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:357)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261)
at org.jboss.netty.channel.socket.oio.OioWorker.run(OioWorker.java:90)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.IoWorkerRunnable.run(IoWorkerRunnable.java:46)
at org.jboss.netty.util.VirtualExecutorService$ChildExecutorRunnable.run(VirtualExecutorService.java:181)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
This is happening because my client process, when it sees that the server has come back to life wants to redeploy its JMS queues. However, my server code has already deployed this queue as part of it's configuration - hence the error. I've tried using the JMS createQueue method rather than specifying it in the configuration and checking the bindings of the PostOffice of the HornetQServer just before creating it to see if it already exists but this also does not work.
Basically, there seems to be a race condition between my embedded server trying to create the queue and the client process trying to re-create it.
Having looked through the source code there is no equivalent deployQueue for JMS queues (that I can see). Is there any way i can avoid this error? As a result the client also complains about a timeout from the server.
Many thanks!
-ian.