Hi all; i'm using JBoss 3.2.5.
I have this scenario: i have a sender that sends a message to a MDB; then the 
MDB send on a topic a Collection and my subscritors should be able to recover 
them; well i have this exception:

anonymous wrote : javax.jms.JMSException: A message listener is already 
registered

My Sender ( it sends on a queue where the MDB is listening ) is:


  | package it.eng.nikko.infobean.mdb.sender;
  | 
  | //Java import
  | import java.io.Serializable;
  | import java.util.Hashtable;
  | 
  | //JMS import
  | import javax.jms.DeliveryMode;
  | import javax.jms.JMSException;
  | import javax.jms.Message;
  | import javax.jms.ObjectMessage;
  | import javax.jms.Queue;
  | import javax.jms.QueueConnection;
  | import javax.jms.QueueConnectionFactory;
  | import javax.jms.QueueSender;
  | import javax.jms.QueueSession;
  | import javax.naming.InitialContext;
  | import javax.naming.Context;
  | import javax.naming.NamingException;
  | 
  | //Nikko
  | import it.eng.nikko.defs.Definitions;
  | 
  | import org.apache.log4j.Logger;
  | /**
  |  * <p>Title: </p>
  |  *
  |  * <p>Description: </p>
  |  *
  |  * <p>Copyright: Copyright (c) 2004</p>
  |  *
  |  * <p>Company: </p>
  |  *
  |  * @author not attributable
  |  * @version 1.0
  |  */
  | public class NikkoCollectionSender {
  |     
  |     private static final Logger log = Logger.getLogger( 
NikkoCollectionSender.class.getName() );
  |     public NikkoCollectionSender() {
  |     }
  | 
  |     private Context getContext() throws NamingException {
  | 
  |         Hashtable props = new Hashtable();
  |         props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
  |                   Definitions.JNDI_INITIAL_CONTEXT_FACTORY);
  |         props.put(InitialContext.PROVIDER_URL,
  |                   Definitions.JNDI_CONTEXT_PROVIDER_URL);
  |         return new InitialContext(props);
  |     }
  | 
  |     public void createAndSendMsg(Serializable theCollection) throws
  |             NamingException, JMSException {
  |         
  |         log.info( "Send message" );
  |         Context cont = getContext();
  |         QueueConnectionFactory factory = (QueueConnectionFactory) (cont.
  |                 lookup(Definitions.JNDI_CONNECTION_FACTORY_NAME));
  |         Queue coda = (Queue) cont.lookup(Definitions.JNDI_MDB_QUEUE);
  |         QueueConnection connessione = factory.createQueueConnection();
  |         QueueSession sessione = connessione.createQueueSession(true,
  |                 QueueSession.AUTO_ACKNOWLEDGE);
  |         QueueSender sender = sessione.createSender(coda);
  |         ObjectMessage msg = sessione.createObjectMessage();
  |         msg.setObject(theCollection);
  |         sender.send(msg, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY,
  |                     Message.DEFAULT_TIME_TO_LIVE);
  |         sessione.commit();
  |         sessione.close();
  |         connessione.close();
  |         log.info( "Done send message" );
  |     }
  | }

This is my MDB code:

package it.eng.nikko.infobean.mdb;
  | 
  | import javax.ejb.MessageDrivenBean;
  | import javax.jms.MessageListener;
  | import javax.ejb.MessageDrivenContext;
  | import javax.jms.Message;
  | import javax.jms.ObjectMessage;
  | 
  | //Nikko Imports
  | import it.eng.nikko.infobean.mdb.util.SerializableService;
  | import it.eng.nikko.infobean.mdb.util.CollectionDispatcher;
  | 
  | //Log4j import
  | import org.apache.log4j.Logger;
  | import javax.jms.JMSException;
  | 
  | //java import
  | import java.io.Serializable;
  | 
  | public class IBRetrieverBean implements MessageDrivenBean, MessageListener {
  | 
  |     private static final String MODULE = IBRetrieverBean.class.getName();
  |     private static final Logger log = Logger.getLogger( MODULE );
  |     MessageDrivenContext messageDrivenContext;
  |     public void ejbCreate(){
  | 
  |         if( log.isDebugEnabled() ){
  | 
  |             log.debug( "Creating instance of MDB" );
  |         }
  |     }
  | 
  |     public void ejbRemove() {
  | 
  |         if( log.isDebugEnabled() ){
  | 
  |             log.debug( "Removing instance of MDB" );
  |         }
  |     }
  | 
  |     public void onMessage(Message message) {
  | 
  |         ObjectMessage objMsg = ( ( ObjectMessage )( message ) );
  |         try {
  |             
  |             if( log.isDebugEnabled() ){
  |                 
  |                 log.debug( "Sending message to all subscriptors" );
  |             }
  |             sendCollectionToConsumers( ( (SerializableService) (objMsg.
  |                     getObject()) ) );
  |         } catch (JMSException ex) {
  |             
  |             log.error( ex );
  |             throw new IllegalArgumentException( "In class: "+MODULE+". 
There has been a JMSException: "+ ex.getMessage() );
  |         } catch (Exception ex) {
  |             
  |             log.error( ex );
  |             throw new IllegalArgumentException( "In class: "+MODULE+". 
Error in sendCollectionToConsumers method" );
  |         }
  |     }
  | 
  |     public void setMessageDrivenContext(MessageDrivenContext
  |                                         messageDrivenContext) {
  |         if( log.isDebugEnabled() ){
  | 
  |             log.debug( "Setting messageDrivenContext" );
  |         }
  |         this.messageDrivenContext = messageDrivenContext;
  |     }
  |     
  |     private void sendCollectionToConsumers( Serializable theMsg ) throws
  |             JMSException, Exception {
  |         
  |         CollectionDispatcher theDispatcher = new CollectionDispatcher();
  |         theDispatcher.publishObject( theMsg );
  |     }
  | }

This is my receiver ( listening on a topic ):

package it.eng.nikko.infobean.mdb.receiver;
  | 
  | //JMS
  | import javax.jms.TopicConnectionFactory;
  | import javax.jms.TopicConnection;
  | import javax.jms.TopicSession;
  | import javax.jms.TopicPublisher;
  | import javax.jms.TopicSubscriber;
  | import javax.jms.Topic;
  | import javax.jms.MessageListener;
  | import javax.jms.Message;
  | 
  | //JNDI
  | import javax.naming.NamingException;
  | import javax.naming.InitialContext;
  | import javax.naming.Context;
  | 
  | //JAVA
  | import java.util.Hashtable;
  | import java.io.Serializable;
  | 
  | //Log4j
  | import org.apache.log4j.Logger;
  | 
  | //Nikko
  | import it.eng.nikko.defs.Definitions;
  | import javax.jms.JMSException;
  | 
  | 
  | /**
  |  * <p>Title: </p>
  |  *
  |  * <p>Description: </p>
  |  *
  |  * <p>Copyright: Copyright (c) 2004</p>
  |  *
  |  * <p>Company: </p>
  |  *
  |  * @author not attributable
  |  * @version 1.0
  |  */
  | public class NikkoCollectionReceiver implements MessageListener {
  | 
  |     private static final String MODULE = 
NikkoCollectionReceiver.class.getName();
  |     private static final Logger log = Logger.getLogger( MODULE );
  |     private static Context context;
  |     private boolean transacted = false;
  |     private int acknowledgementMode = javax.jms.Session.AUTO_ACKNOWLEDGE;
  |     private TopicConnectionFactory topicConnectionFactory;
  |     private TopicConnection topicConnection;
  |     private TopicSession topicSession;
  |     private TopicPublisher topicPublisher;
  |     private TopicSubscriber topicSubscriber;
  |     private Topic topic;
  |     private String topicConnectionFactoryName = 
Definitions.JNDI_CONNECTION_FACTORY_NAME;
  |     private String subscribeTopicName = Definitions.JNDI_MDB_TOPIC;
  |     //private String clientId = "1";
  |     private String durableName = Definitions.JNDI_MDB_TOPIC;
  |     private boolean durable = true;
  |     public NikkoCollectionReceiver() {
  |     }
  | 
  |     private void setTransacted(boolean transacted) {
  |         this.transacted = transacted;
  |     }
  | 
  |     public TopicSubscriber getTopicSubscriber() throws Exception {
  |         log.info( "getTopicSubscriber()" + isDurable() );
  |         if (topicSubscriber == null) {
  |             if (isDurable()) {
  |                 topicSubscriber = 
getTopicSession(true).createDurableSubscriber(
  |                         getSubscribeTopic(), getDurableName());
  |             } else {
  |                 topicSubscriber = getTopicSession(true).createSubscriber(
  |                         getSubscribeTopic());
  |             }
  | 
  |             topicSubscriber.setMessageListener(this);
  | 
  |             log.info( "getTopicSubscriber() setMessageListener "+ 
topicSubscriber.getMessageListener() );
  |             getTopicConnection(true).start();
  |         }
  |         return topicSubscriber;
  |     }
  |     public TopicSession getTopicSession(boolean consumer) throws Exception {
  |         if (topicSession == null) {
  |             topicSession = getTopicConnection(consumer).createTopicSession(
  |                     isTransacted(), getAcknowledgementMode());
  |         }
  |         return topicSession;
  |     }
  | 
  |     public TopicConnection getTopicConnection(boolean consumer) throws
  |             Exception {
  |         if (topicConnection == null) {
  |             topicConnection = 
getTopicConnectionFactory().createTopicConnection();
  |             topicConnection.start();
  |             /*if (isDurable() && consumer) {
  |                 topicConnection.setClientID(clientId);
  |             }*/
  |         }
  |         return topicConnection;
  |     }
  | 
  |     public TopicConnectionFactory getTopicConnectionFactory() throws 
Exception {
  |         if (topicConnectionFactory == null) {
  |             Object obj = getContext().lookup(topicConnectionFactoryName);
  |             topicConnectionFactory = (TopicConnectionFactory) obj;
  |         }
  |         return topicConnectionFactory;
  |     }
  | 
  |     private void setDurable(boolean durable) {
  |         this.durable = durable;
  |     }
  | 
  |     private boolean isDurable() {
  |         return durable;
  |     }
  | 
  |     private void setDurableName(String durableName) {
  |         this.durableName = durableName;
  |     }
  | 
  |     private String getDurableName() {
  |         return durableName;
  |     }
  | /*
  |     private void setClientId(String clientId) {
  |         this.clientId = clientId;
  |     }
  | 
  |     private String getClientId() {
  |         return clientId;
  |     }
  | */
  |     private void setSubscribeTopicName(String subscribeTopicName) {
  |         this.subscribeTopicName = subscribeTopicName;
  |     }
  | 
  |     private String getSubscribeTopicName() {
  |         return subscribeTopicName;
  |     }
  |     private void setTopicConnectionFactoryName(String 
topicConnectionFactoryName) {
  |         this.topicConnectionFactoryName = topicConnectionFactoryName;
  |     }
  | 
  |     private String getTopicConnectionFactoryName() {
  |         return topicConnectionFactoryName;
  |     }
  | 
  |     private void setAcknowledgementMode(int acknowledgementMode) {
  |         this.acknowledgementMode = acknowledgementMode;
  |     }
  | 
  |     private int getAcknowledgementMode() {
  |         return acknowledgementMode;
  |     }
  | 
  |     private boolean isTransacted() {
  |         return transacted;
  |     }
  | 
  |     private Context getInitialContext() throws NamingException {
  |         Hashtable environment = new Hashtable();
  | 
  |         environment.put(Context.INITIAL_CONTEXT_FACTORY,
  |                         Definitions.JNDI_INITIAL_CONTEXT_FACTORY);
  |         environment.put(Context.URL_PKG_PREFIXES,
  |                         "org.jboss.naming:org.jnp.interfaces");
  |         environment.put(Context.PROVIDER_URL, 
Definitions.JNDI_CONTEXT_PROVIDER_URL_MESAGEGES);
  | 
  |         return new InitialContext(environment);
  |     }
  | 
  |     private Context getContext() throws Exception {
  |         if (context == null) {
  |             try {
  |                 context = getInitialContext();
  |             } catch (Exception ex) {
  |                 ex.printStackTrace();
  |                 throw ex;
  |             }
  |         }
  |         return context;
  |     }
  | 
  |     public Topic getSubscribeTopic() throws Exception {
  |         if (topic == null) {
  |             log.info( "I'm looking for: "+ subscribeTopicName );
  |             Object obj = getContext().lookup(subscribeTopicName);
  |             topic = (Topic) obj;
  |         }
  |         return topic;
  |     }
  |     public void onMessage(Message message) {
  | 
  |         System.out.println( "Gotten: "+ message );
  |         try {
  |             close();
  |         } catch (JMSException ex) {
  | 
  |             log.error( ex );
  |             throw new IllegalArgumentException( "In the onMessage method. 
JMSException: "+ ex.fillInStackTrace() );
  |         }
  |     }
  |     private void close() throws JMSException {
  |         if (topicPublisher != null) {
  |             topicPublisher.close();
  |         }
  |         if (topicSubscriber != null) {
  |             topicSubscriber.close();
  |         }
  |         if (topicSession != null) {
  |             topicSession.close();
  |         }
  |         if (topicConnection != null) {
  |             topicConnection.close();
  |         }
  |     }
  | }

This is my Definitions class:
package it.eng.nikko.defs;
  | 
  | 
  | import it.eng.nikko.config.model.Configuration;
  | /**
  |  * <p>Title: </p>
  |  *
  |  * <p>Description: </p>
  |  *
  |  * <p>Copyright: Copyright (c) 2004</p>
  |  *
  |  * <p>Company: </p>
  |  *
  |  * @author not attributable
  |  * @version 1.0
  |  */
  | public class Definitions {
  |     public static final String PROFILE_MANAGER_ID = "PM";
  |     public static final String CONTENT_ADMIN_ID = "CA";
  |     public static final String CONTENT_EDITOR_ID = "CE";
  | 
  |     public static final String JNDI_CONTEXT_PROVIDER_URL = 
"jnp://127.0.0.1:1099";
  |     //public static final String JNDI_CONTEXT_PROVIDER_URL_MESAGEGES = 
"jnp://"+Configuration.getIpAddress( "CA" )+":1099";
  |     public static final String JNDI_CONTEXT_PROVIDER_URL_MESAGEGES = 
"jnp://127.0.0.1:1099";
  |     public static final String JNDI_INITIAL_CONTEXT_FACTORY = 
"org.jnp.interfaces.NamingContextFactory";
  | 
  |     public static final String JNDI_MDB_QUEUE = 
"queue/it.eng.nikko.IBDispatcher";
  |     public static final String JNDI_MDB_TOPIC = 
"topic/it.eng.nikko.ibTunneling";
  |     public static final String 
JNDI_CONNECTION_FACTORY_NAME="ConnectionFactory";
  |     public Definitions() {
  |     }
  | }

This is mi CollectionDispatcher class:
package it.eng.nikko.infobean.mdb.util;
  | 
  | //Java
  | import java.io.Serializable;
  | import java.util.Hashtable;
  | 
  | //Naming
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | import javax.naming.Context;
  | 
  | //JMS
  | import javax.jms.TopicConnectionFactory;
  | import javax.jms.TopicConnection;
  | import javax.jms.TopicSession;
  | import javax.jms.TopicPublisher;
  | import javax.jms.Topic;
  | 
  | //Nikko
  | import it.eng.nikko.defs.Definitions;
  | import javax.jms.JMSException;
  | 
  | //Log4J
  | import org.apache.log4j.Logger;
  | 
  | /**
  |  * <p>Title: </p>
  |  *
  |  * <p>Description: </p>
  |  *
  |  * <p>Copyright: Copyright (c) 2004</p>
  |  *
  |  * <p>Company: </p>
  |  *
  |  * @author not attributable
  |  * @version 1.0
  |  */
  | public class CollectionDispatcher {
  | 
  |     private static Context context;
  |     private boolean transacted = false;
  |     private int acknowledgementMode = javax.jms.Session.AUTO_ACKNOWLEDGE;
  |     private TopicConnectionFactory topicConnectionFactory;
  |     private TopicConnection topicConnection;
  |     private TopicSession topicSession;
  |     private TopicPublisher topicPublisher;
  |     private Topic topic;
  |     private String topicConnectionFactoryName = 
Definitions.JNDI_CONNECTION_FACTORY_NAME;
  |     private String publishTopicName = Definitions.JNDI_MDB_TOPIC;
  | 
  |     private String clientId = "1";
  |     private String durableName = Definitions.JNDI_MDB_TOPIC;
  |     private boolean durable = true;
  | 
  |     private static final Logger log = Logger.getLogger( 
CollectionDispatcher.class.getName() );
  | 
  |     public CollectionDispatcher() {
  |     }
  | 
  |     public void setTransacted(boolean transacted) {
  | 
  |         this.transacted = transacted;
  |     }
  | 
  |     private TopicSession getTopicSession(boolean consumer) throws Exception 
{
  |         if (topicSession == null) {
  |             topicSession = getTopicConnection(consumer).createTopicSession(
  |                     isTransacted(), getAcknowledgementMode());
  |         }
  |         return topicSession;
  |     }
  | 
  |     private TopicConnection getTopicConnection(boolean consumer) throws
  |             Exception {
  |         if (topicConnection == null) {
  |             topicConnection = 
getTopicConnectionFactory().createTopicConnection();
  |             topicConnection.start();
  |             if (isDurable() && consumer) {
  |                 topicConnection.setClientID(clientId);
  |             }
  |         }
  |         return topicConnection;
  |     }
  | 
  |     private TopicConnectionFactory getTopicConnectionFactory() throws 
Exception {
  |         if (topicConnectionFactory == null) {
  |             Object obj = getContext().lookup(topicConnectionFactoryName);
  |             topicConnectionFactory = (TopicConnectionFactory) obj;
  |         }
  |         return topicConnectionFactory;
  |     }
  | 
  |     public void setDurable(boolean durable) {
  |         this.durable = durable;
  |     }
  | 
  |     public boolean isDurable() {
  |         return durable;
  |     }
  | 
  |     public void setDurableName(String durableName) {
  |         this.durableName = durableName;
  |     }
  | 
  |     public String getDurableName() {
  |         return durableName;
  |     }
  |     private String getTopicConnectionFactoryName() {
  |         return topicConnectionFactoryName;
  |     }
  | 
  |     public void setAcknowledgementMode(int acknowledgementMode) {
  |         this.acknowledgementMode = acknowledgementMode;
  |     }
  | 
  |     public int getAcknowledgementMode() {
  |         return acknowledgementMode;
  |     }
  | 
  |     public boolean isTransacted() {
  |         return transacted;
  |     }
  | 
  |     private Context getInitialContext() throws NamingException {
  |         Hashtable environment = new Hashtable();
  | 
  |         environment.put(Context.INITIAL_CONTEXT_FACTORY,
  |                         Definitions.JNDI_INITIAL_CONTEXT_FACTORY);
  |         environment.put(Context.URL_PKG_PREFIXES,
  |                         "org.jboss.naming:org.jnp.interfaces");
  |         environment.put(Context.PROVIDER_URL,
  |                         Definitions.JNDI_CONTEXT_PROVIDER_URL);
  | 
  |         return new InitialContext(environment);
  |     }
  | 
  |     private Context getContext() throws Exception {
  |         if (context == null) {
  |             try {
  |                 context = getInitialContext();
  |             } catch (Exception ex) {
  |                 ex.printStackTrace();
  |                 throw ex;
  |             }
  |         }
  |         return context;
  |     }
  | 
  |     private Topic getPublishTopic() throws NamingException, Exception {
  |         if (topic == null) {
  |             Object obj = getContext().lookup(publishTopicName);
  |             topic = (Topic) obj;
  |         }
  |         return topic;
  |     }
  | 
  |     private TopicPublisher getTopicPublisher() throws JMSException, 
Exception {
  |         if (topicPublisher == null) {
  |             topicPublisher = getTopicSession(false).createPublisher(
  |                     getPublishTopic());
  | 
  |         }
  |         return topicPublisher;
  |     }
  | 
  |     public void publishObject(Serializable message) throws JMSException,
  |             Exception {
  | 
  |         log.info( "Publishing: " + message.toString() );
  |         javax.jms.ObjectMessage objectMessage = getTopicSession(false).
  |                                                 createObjectMessage();
  |         objectMessage.clearBody();
  |         objectMessage.setObject(message);
  |         getTopicPublisher().publish(objectMessage);
  |         if (isTransacted()) {
  |             getTopicSession(false).commit();
  |         }
  |         close();
  |     }
  | 
  |     private void close() throws Exception {
  |         if (topicPublisher != null) {
  |             topicPublisher.close();
  |         }
  |         if (topicSession != null) {
  |             topicSession.close();
  |         }
  |         if (topicConnection != null) {
  |             topicConnection.close();
  |         }
  |     }
  | }

This is my jboss-service.xml:

anonymous wrote : <?xml version="1.0" encoding="UTF-8"?>
  | <!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 3.2//EN" 
"http://www.jboss.org/j2ee/dtd/jboss-service_3_2.dtd";>
  | 
  |   
  |     <depends 
optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager
  |     <depends 
optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager
  |   
  |   
  |     <depends 
optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager
  |     <depends 
optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager
  |   
  | 

These are my ejb-jar.xml and jboss.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 
2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd";>
anonymous wrote : <ejb-jar>
  |   <display-name>it.eng.nikko.messages</display-name>
  |   <enterprise-beans>
  |     <message-driven>
  |       <ejb-name>IBRetrieverBean</ejb-name>
  |       <ejb-class>it.eng.nikko.infobean.mdb.IBRetrieverBean</ejb-class>
  |       <transaction-type>Container</transaction-type>
  |       <message-driven-destination>
  |         <destination-type>javax.jms.Queue</destination-type>
  |       </message-driven-destination>
  |     </message-driven>
  |   </enterprise-beans>
  |   <assembly-descriptor>
  |     <container-transaction>
  |       
  |         <ejb-name>IBRetrieverBean</ejb-name>
  |         <method-name>*</method-name>
  |       
  |       <trans-attribute>Required</trans-attribute>
  |     </container-transaction>
  |   </assembly-descriptor>
  | </ejb-jar>

anonymous wrote : <?xml version="1.0" encoding="UTF-8"?>
  | <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" 
"http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd";>
  | 
  |   <enterprise-beans>
  |     <message-driven>
  |       <ejb-name>IBRetrieverBean</ejb-name>
  |       
<destination-jndi-name>queue/it.eng.nikko.IBDispatcher</destination-jndi-name>
  |     </message-driven>
  |   </enterprise-beans>
  | 

Can anybody tell me why i have that error?

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3856898#3856898

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3856898


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to