You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by JohnRodey <ti...@yahoo.com> on 2011/09/19 22:55:14 UTC

JMS Message Listener

So I'm just trying to create a JMS message listener in my pivot app that will
listen for messages and populate a table with those messages.  My code looks
similar to the code below, does anyone know why this wouldn't work?  On my
console for activemq I see the new connection and consumer created when I
launch my application, however when I send messages I never see my println
written.

Pivot 2.0, on Windows.  Running in Tomcat with ActiveMQ.

Thanks!


  public void startup(Display display, Map&lt;String, String&gt; map) throws
Exception {
    System.out.println("Starting...");
    ...
    startMessageListener();
  }

  public void startMessageListener() {
    try {
      ActiveMQConnectionFactory factory = new
ActiveMQConnectionFactory("tcp://1.2.3.4:61616");
      connection = factory.createConnection();
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      topic = session.createTopic("myTopic");
      MessageConsumer consumer = session.createConsumer(topic);
      consumer.setMessageListener(new MessageListener {
        public void onMessage(Message msg) {
          System.out.println("I got a message!!!");
        }
      });
      connection.start();
    } catch (Exception e) {
      e.printStackTrace();
    }

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/JMS-Message-Listener-tp3350099p3350099.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: JMS Message Listener

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
good to know ... and interesting application to show/dump JMS messages.

>I needed to sign my jar to get it to open a connection to the messaging
broker, however I didnt update my classpath to use the signed pivot jars. I
replaced the pivot jars with the signed versions and presto! 
Are you running your Pivot application as Applet or with Web Start ?
Opening connections from Applets/Web Start require code inside signed jars
(the JVM needs it), while standalone applications not (by default without a
security manager).

If you have some screenshot and/or a (more verbose) description of this
application, post here, could be an interesting thing to see ...

Bye


--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/JMS-Message-Listener-tp3350099p3351500.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: JMS Message Listener

Posted by JohnRodey <ti...@yahoo.com>.
For those who follow....

I needed to sign my jar to get it to open a connection to the messaging
broker, however I didnt update my classpath to use the signed pivot jars.

I replaced the pivot jars with the signed versions and presto!

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/JMS-Message-Listener-tp3350099p3350394.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: JMS Message Listener

Posted by JohnRodey <ti...@yahoo.com>.
It's really weird cause if I run this logic in a simple java class it works
fine.

Even if I change it to not use the message listener but just receive a
message I still never receive anything.  Anyone have any ideas why this
would be?

 public void startMessageListener() { 
    try { 
      ActiveMQConnectionFactory factory = new
ActiveMQConnectionFactory("tcp://1.2.3.4:61616"); 
      connection = factory.createConnection(); 
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 
      topic = session.createTopic("myTopic"); 
      MessageConsumer consumer = session.createConsumer(topic); 
      connection.start(); 
      *System.out.println("Waiting to receive.");
      Message m = consumer.receive(100000);
      System.out.println("Done!");*    } catch (Exception e) { 
      e.printStackTrace(); 
    } 


--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/JMS-Message-Listener-tp3350099p3350358.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.