activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slyfox <>
Subject inject MessageListener instance to allow for onMessage to reside anywhere in the application
Date Thu, 21 Jan 2010 22:08:13 GMT

I would like to create a topic consumer module that I can re-use in my code. 
I am publishing stock quotes to a topic that I can consume no problem if I
put my consumer logic all in once class.  I would like to some how
instantiate my ActiveMQConsumer class with a MessageListener so that the
onMessage method is called where ever I want it (I hope that was clear?) 
For example

public class ActiveMQConsumer implements MessageListener {

    public void onMessage(Message m) { /* Works just fine */ }


what I would like to do (and tried) is the following

public class AnotherClass implements MessageListener {
    private static MessageListener ml;
    ActiveMQConsumer consumer = new ActiveMQConsumer(ml);
    public void OnMessage(Message msg) { };

And i take the ml that I give to my ActiveMQConsumer class and when i set my
message listener I use:
    c.setMessageListener(ml); // ml is give to class through constructor
instead of 

Everything compiles just fine and no exceptions are thrown, just nothing
happens, I am thinking that it is a threading issue.  

Please help.

View this message in context:
Sent from the ActiveMQ - User mailing list archive at

View raw message