Note that there are some explanatory texts on larger screens.

plurals
  1. POI'm getting a deadlock when calling consumer.setMessageListener(MessageListener)
    text
    copied!<p>In activemq I'm doing something that might be wrong. I'm creating a consumer and setting a messageListener (consumer.setMessageListener(MessageListener)) while consuming a message. This causes activeMQ to deadlock.</p> <p>Here is a code sample of what I am doing:</p> <pre><code>class DriverClass extends MessageListener { Destination destination = session.createTopic("Some.Topic"); MessageListener msgSub = new MyClass(destination); Session session = passedInSession; MessageConsumer consumer; try { consumer = session.createConsumer(destination); msgSub.setConsumer( consumer ); if(msgSub.getMessageListener() != null) { consumer.setMessageListener( msgSub ); } } catch (Exception ex) { LOGGER.error( "Error subscribing to "+msgSub.getTopic() +" Error message: ", ex ); } } class MyClass extends MessageListener { Destination dest; public MyClass(Destination destToUse) { dest = destToUse; } @Override public void onMessage( final Message message ) { //note here we are using the same topic MessageListener msgSub = new MyMessageListener("Some.Topic"); MessageConsumer consumer; try { //note here we are using the same dest as above consumer = session.createConsumer(dest); msgSub.setConsumer( consumer ); if(msgSub.getMessageListener() != null) { //this is where it deadlocks subscribing while consuming a message //on the same topic/destination consumer.setMessageListener( msgSub ); } } catch (Exception ex) { LOGGER.error( "Error subscribing to "+msgSub.getTopic() +" Error message: ", ex ); } } } </code></pre> <p>Basically, I'm subscribing within a consumer within the ActiveMQ thread. The only reference to this problem can be found here: <a href="https://issues.apache.org/jira/browse/AMQ-336" rel="nofollow">https://issues.apache.org/jira/browse/AMQ-336</a> but I can't tell what the workaround is. For now I'm just going to put the subscription call on a worker thread and return control back to ActiveMQ but it seems like there is a better solution. Is the issue that I'm subscribing to a topic/destination while handling a message of the same topic/destination?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload