0 Replies Latest reply on Mar 8, 2002 8:06 AM by jurosa

    Any tips ?  -  log4j:ERROR No appenders could be found for c

    jurosa

      Please, could You tell me also the possible reason of this partial problems with simple examples of MDB ?

      this:
      log4j:ERROR No appenders could be found for category (org.jboss.mq.referenceable.SpyConnectionFactoryObjectFactory).
      log4j:ERROR Please initialize the log4j system properly.




      --------------------------------- client console:
      Microsoft(R) Windows NT(TM)
      (C) Copyright 1985-1996 Microsoft Corp.

      D:\projects\j2ee\WP-09 - MDB tests\QueueMDBean\ConsoleApp>run

      D:\projects\j2ee\WP-09 - MDB tests\QueueMDBean\ConsoleApp>java -cp ./deploy/QueueMDBean-client.jar;D:\projects\JBoss\jboss/lib/jnpserver.
      jar;D:\projects\JBoss\jboss/lib/jboss.jar;D:\projects\JBoss\jboss/lib/jboss-j2ee.jar;D:\projects\JBoss\jboss/lib/jbossmq.jar;D:\projects\
      JBoss\jboss/lib/jboss-common.jar;D:\projects\JBoss\jboss/lib/log4j.jar;D:\projects\JBoss\jboss/lib/concurrent.jar client.SendRecvClient
      Begin sendRecvAsync
      log4j:ERROR No appenders could be found for category (org.jboss.mq.referenceable.SpyConnectionFactoryObjectFactory).
      log4j:ERROR Please initialize the log4j system properly.
      sendRecvAsync, sent text=A text msg#0
      sendRecvAsync, sent text=A text msg#1
      sendRecvAsync, sent text=A text msg#2
      sendRecvAsync, sent text=A text msg#3
      sendRecvAsync, sent text=A text msg#4
      sendRecvAsync, sent text=A text msg#5
      sendRecvAsync, sent text=A text msg#6
      onMessage, recv text=A text msg#0processed by: -23273254
      sendRecvAsync, sent text=A text msg#7
      sendRecvAsync, sent text=A text msg#8
      onMessage, recv text=A text msg#1processed by: -22804418
      sendRecvAsync, sent text=A text msg#9
      End sendRecvAsync
      onMessage, recv text=A text msg#2processed by: -22800792
      onMessage, recv text=A text msg#3processed by: -22796087
      onMessage, recv text=A text msg#4processed by: -22796087
      onMessage, recv text=A text msg#5processed by: -22796087
      onMessage, recv text=A text msg#7processed by: -22800792
      onMessage, recv text=A text msg#8processed by: -23272172
      onMessage, recv text=A text msg#6processed by: -22796087
      onMessage, recv text=A text msg#9processed by: -22804418

      D:\projects\j2ee\WP-09 - MDB tests\QueueMDBean\ConsoleApp>













      ----- for sure here is some partial code of MDB --------

      ------------------ example source of sendReceive client:
      package client;

      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueReceiver;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.jms.TextMessage;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import EDU.oswego.cs.dl.util.concurrent.CountDown;


      /** A complete JMS client example program that sends N
      * TextMessages to a Queue B and asynchronously receives the
      * messages as modified by TestMDB from QueueB.
      *
      * @author Scott.Stark@jboss.org
      * @version $Revision:$
      */
      public class SendRecvClient {
      static final int N = 10;
      static CountDown done = new CountDown(N);
      QueueConnection conn;
      QueueSession session;
      Queue queA;
      Queue queB;

      public static class ExListener implements MessageListener {
      public void onMessage(Message msg) {
      done.release();
      TextMessage tm = (TextMessage) msg;
      try {
      System.out.println("onMessage, recv text="+tm.getText());
      }
      catch(Throwable t) {
      t.printStackTrace();
      }
      }
      }

      public void setupPTP()
      throws JMSException, NamingException {
      InitialContext iniCtx = new InitialContext();
      Object tmp = iniCtx.lookup("ConnectionFactory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
      conn = qcf.createQueueConnection();
      queA = (Queue) iniCtx.lookup("queue/A");
      queB = (Queue) iniCtx.lookup("queue/B");
      session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      conn.start();
      }

      public void sendRecvAsync(String textBase)
      throws JMSException, NamingException, InterruptedException {
      System.out.println("Begin sendRecvAsync");
      // Setup the PTP connection, session
      setupPTP();
      // Set the async listener for queA
      QueueReceiver recv = session.createReceiver(queA);
      recv.setMessageListener(new ExListener());
      // Send a few text msgs to queB
      QueueSender send = session.createSender(queB);
      for(int m = 0; m < 10; m ++) {
      TextMessage tm = session.createTextMessage(textBase+"#"+m);
      tm.setJMSReplyTo(queA);
      send.send(tm);
      System.out.println("sendRecvAsync, sent text="+tm.getText());
      }
      System.out.println("End sendRecvAsync");
      }

      public void stop() throws JMSException {
      conn.stop();
      }

      public static void main(String args[]) throws Exception {
      SendRecvClient client = new SendRecvClient();
      client.sendRecvAsync("A text msg");
      client.done.acquire();
      client.stop();
      System.exit(0);
      }

      }

      ----------------------------------- ejb:
      package ejb;

      import javax.ejb.*;
      import javax.jms.*;
      import javax.ejb.MessageDrivenBean;
      import javax.ejb.MessageDrivenContext;
      import javax.ejb.EJBException;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.jms.TextMessage;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      // subscription-durability="NonDurable"
      // ejb-class="ejb.TextMDBean"
      /*
      * @ejb: -------- probably also neccessary tags ---------
      name = "jms/QCF"
      type = "javax.jms.QueueConnectionFactory"
      --------------------------------------------------------
      */


      /**
      * Sample Message-Driven Bean
      *
      * @ejb:bean
      name = "TextMDBean"
      transaction-type = "Bean"
      message-selector = ""
      acknowledge-mode = "Auto-acknowledge"
      destination-type = "javax.jms.Queue"
      subscription-durability = "NonDurable"

      * @ejb:resource-ref
      res-name = "jms/QCF"
      res-type = "javax.jms.QueueConnectionFactory"
      res-auth = "Container"

      * @jboss:destination-jndi-name
      name = "queue/B"

      * @jboss:resource-ref
      res-ref-name = "jms/QCF"
      jndi-name = "ConnectionFactory"
      *
      */

      public class TextMDBean implements MessageDrivenBean, MessageListener
      {
      private MessageDrivenContext ctx = null;
      private QueueConnection conn;
      private QueueSession session;

      public TextMDBean()
      {
      System.out.println("TextMDB.ctor, this="+hashCode());
      }

      public void setMessageDrivenContext(MessageDrivenContext ctx)
      {
      this.ctx = ctx;
      System.out.println("TextMDB.setMessageDrivenContext, this="+hashCode());
      }

      public void ejbCreate()
      throws EJBException
      {
      System.out.println("TextMDB.ejbCreate, this="+hashCode());
      try
      {
      setupPTP();
      }
      catch(Exception e)
      {
      throw new EJBException("Failed to init TextMDB", e);
      }
      }
      public void ejbRemove()
      {
      System.out.println("TextMDB.ejbRemove, this="+hashCode());
      ctx = null;
      try
      {
      if( session != null )
      session.close();
      if( conn != null )
      conn.close();
      }
      catch(JMSException e)
      {
      e.printStackTrace();
      }
      }

      public void onMessage(Message msg)
      {
      System.out.println("TextMDB.onMessage, this="+hashCode());
      try
      {
      TextMessage tm = (TextMessage) msg;
      String text = tm.getText() + "processed by: "+hashCode();
      Queue dest = (Queue) msg.getJMSReplyTo();
      sendReply(text, dest);
      }
      catch(Throwable t)
      {
      t.printStackTrace();
      }
      }

      private void setupPTP()
      throws JMSException, NamingException
      {
      InitialContext iniCtx = new InitialContext();
      Object tmp = iniCtx.lookup("java:comp/env/jms/QCF");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
      conn = qcf.createQueueConnection();
      session = conn.createQueueSession(false,
      QueueSession.AUTO_ACKNOWLEDGE);
      conn.start();
      }

      private void sendReply(String text, Queue dest)
      throws JMSException
      {
      System.out.println("TextMDB.sendReply, this="+hashCode()
      +", dest="+dest);
      QueueSender sender = session.createSender(dest);
      TextMessage tm = session.createTextMessage(text);
      sender.send(tm);
      sender.close();
      }

      }