2 Replies Latest reply on Aug 28, 2002 11:08 AM by Mauro Ramon

    Problem with Log4j and JMSAppender

    Mauro Ramon Newbie

      hi all, we got a problem when trying to use Log4J with JMSAppender. We are using Jboss 3.0+Jetty.
      We defined a Topic in jbossmq-destinations-service.xml
      <mbean code="org.jboss.mq.server.jmx.Topic"name="jboss.mq.destination:service=Topic,name=topicLogTest">
      <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager


      We configured Log4J of the following form:
      log4j.category.com.sancorseguros.nova =INFO, JMS

      log4j.appender.JMS=org.apache.log4j.net.JMSAppender
      log4j.appender.JMS.TopicBindingName=topic/topicLogTest
      log4j.appender.JMS.TopicConnectionFactoryBindingName=ConnectionFactory

      Everything seem to work fine for logging. We have create an stand-alone class to subscribe to topic. A fragment of code:
      try {
      InitialContext ctx = new InitialContext();
      TopicConnectionFactory tcf = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
      topicCon = tcf.createTopicConnection();
      TopicSession topicSess = topicCon.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
      Topic topic = (Topic) ctx.lookup("topic/topicLogTest");
      TopicSubscriber topicSubscriber = topicSess.createSubscriber(topic);
      TextListener listener = new TextListener();
      topicSubscriber.setMessageListener(listener);
      topicCon.start();
      while (this.start) {
      / /nada
      }
      } catch(Exception e) {
      e.printStackTrace(System.out);
      } finally {
      if (topicCon != null) {
      try {
      topicCon.close();
      } catch(Exception e) {
      e.printStackTrace(System.out);
      }
      }
      }

      TextListener to implement MessageListener.
      public void onMessage(Message message) {
      TextMessage msg = null;
      try {
      if (message instanceof TextMessage) {
      msg = (TextMessage) message;
      System.out.println("Reading message: " +msg.getText());
      } else {
      System.out.println("Message of wrong type: " + message.getClass().getName());
      }
      } catch (JMSException e) {
      System.out.println("JMSException in onMessage(): " +e.toString());
      } catch (Throwable t) {
      System.out.println("Exception in onMessage():" + t.getMessage());
      }
      }

      The problem occur when TextListener try to evaluate message instanceof TextMessage. The class type for Message parameter is org.jboss.mq.SpyObjectMessage and we don't to see the text message.

      We have forgot to configure something???
      Please, any tip are welcome.
      Thanks in advance.
      PD:Sorry for my english please