1 Reply Latest reply on Mar 23, 2012 9:28 AM by Justin Bertram

    Topic Subscriber Listener HornetQ 2.1.2 Final

    Sergiu Pienar Expert

      I'm trying to subscribe to a Topic using a TopicSubscriber. To that TopicSubscriber I'm trying to assign a MessageListener. I added the code below inside the init() method of a Servlet that loads on server start-up:

      String destName = "topic/userManagementTopic";
      TopicConnectionFactory connectionFactory = null;
      TopicConnection connection = null;
      TopicSession session = null;
      Topic topic = null;
      InitialContext jndiContext = BlaBla.magicallyBuildTheCorrectInitialContext("userManagementTopic");
      = (TopicConnectionFactory)jndiContext.lookup("java:/JmsXA");

      = (javax.jms.Topic)jndiContext.lookup(destName);

      = (TopicConnection)connectionFactory.createConnection("topicUser", "topicPwd");
      = (TopicSession)connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      TopicSubscriber recv = session.createSubscriber(topic);
      .setMessageListener(new UserManagementTopicListener());

      Problem is I never get past the last line, because I get

      javax.jms.IllegalStateException: This method is not applicable inside the application server. See the J2EE spec

      I've tried to apply the recommended fix I found on the internet, adding <config-property name="Strict" type="java.lang.Boolean">false</config-property> to my jms-ds.xml, but that won't fix it.

      So, how else could I subscribe to the Topic and indicate my desired MessageListener?

      I'm using jboss-5.1.0.GA and my app is based on Struts.

      Thank you for reading this.

        • 1. Re: Topic Subscriber Listener HornetQ 2.1.2 Final
          Justin Bertram Master

          The "Strict" configuration parameter was used by the JBoss generic JMS JCA RA which was used for JBossMQ and JBoss Messaging.  However, the HornetQ JCA RA does not support this feature.  In other words, there's no way to make HornetQ semantics here less strict.  It enforces the Java EE spec, period.  The preferred way to implement a MessageListener in combination with JCA is by using an MDB.  If you don't wish to use an MDB then don't use a JCA connection factory, use a connection factory directly from the remote server.