We have a scenario where we need to send a synchronous message over our an in memory activemq broker. Our synchronous client side code looks like this:
Session responseSession = connection.createSession(false, Session.A开发者_如何学CUTO_ACKNOWLEDGE);
TemporaryQueue responseQ = responseSession.createTemporaryQueue();
msg.setJMSReplyTo(responseQ);
QueueReceiver qReceiver = ((QueueSession) responseSession).createReceiver(responseQ);
sendMessage(msg, false, timeout);
Message response = qReceiver.receive(timeout);
Most of the time our server response code works fine but occasionally we get a stacktrace like:
javax.jms.InvalidDestinationException: Cannot publish to a deleted Destination: temp-queue://ID:<removed>
at org.apache.activemq.ActiveMQSession.send(ActiveMQSession.java:1632)
at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:231)
at org.apache.activemq.ActiveMQMessageProducerSupport.send(ActiveMQMessageProducerSupport.java:269)
I'm suspecting that the root problem is that the temporary queue isn't fully setup or that it hasn't been published or whatever it is that it does by the time the service attempts to publish a message to it. In my server code I've wrapped the send call in a loop catching the InvalidDestinationException, sleeping for a second and trying again until it succeeds. Since I've added this, whenever I see the exception on the second try it works.
Am I doing something wrong? Should I be doing something on the client to sync or flush or otherwise ensure that the temporary queue is up before sending the message to the server? Is there something else I should be doing on the server side to ensure the queue is up? Can I otherwise safely attempt to create the temporary queue on the server side if it thinks it isn't already there?
Note: We were using ActiveMQ 5.3.0 but today I tried 5.5.0 with the same results.
That's rather strange and I don't think it should be happening as the temp destination is created locally and should be in the Connections map of temp destinations. If you could create a simple JUnit test case the demonstrates the issue you should open a new Jira and attach it for review.
精彩评论