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

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

Hi,  

thanks for the reply. However, our problem persists. For each MessageListener object, 
a single TopicSession instance is created. While receiving and processing messages, 
Listener performs proper operations on the session object (commits session with 
commit() or rolls back with rollback()). In case of any critical exception, it is 
logged and TopicSubscriber is closed. In spite of catching all exceptions- nothing is 
written to the logs. Below are the skeleton of clients:



MessageListeners

------------------

public class UMPMessageListener implements MessageListener {

    private transient TopicSubscriber topicSubscriber;

    private transient TopicSession topicSession;



    public void onMessage(Message message) {

        try {

            String messageID = message.getJMSMessageID();

            logger.info("[TRANSFER MESSAGE " + messageID + "]");

            // ...............

            // process message

            // e.g. RMIInvocation

            // ...............

            logger.info("[TRANSFERED " + messageID + "]");



            // confirm delivery

            topicSession.commit();



        } catch (UMPMessageRedelivery umpMessageRedelivery) {

            logger.info("Message must redelivery.");

            messageRollback(message);

        } catch (ConnectException e) {

            logger.error("ConnectionException !", e);

            messageRollback(message);

            unsubscribe();

        } catch (RemoteException e) {

            logger.error("RemoteException !", e);

            messageRollback(message);

            unsubscribe();

        } catch (JMSException e) {

            logger.error("Unknown state ?!?!?!", e);

            messageRollback(message);

        } catch (Exception e) {

            logger.error("Unknown state ?!?!?!", e);

            messageRollback(message);

        }





    }





    private void messageRollback(Message message) {

        try {

            topicSession.rollback();

            logger.debug("Rollback transaction for Message: " + 
message.getJMSMessageID());

        } catch (JMSException e) {

            logger.error("Error !", e);

        }

    }



    private void unsubscribe() {

        try {

            topicSession.close();

            topicSubscriber.close();

        } catch (JMSException e) {

            logger.error("Error !", e);

        }

    }

}









Create Subscriber and Register Listeners(in System as Singleton):

------------------------------------------------------------------

public class RegisterImpl {

    private transient TopicConnectionFactory topicConnectionFactory;

    private transient TopicConnection topicConnection;



    public RegisterImpl() {

        try {

            topicConnectionFactory = (TopicConnectionFactory) 
EJBHomeFactory.getFactoryClient().getInitialContext().lookup("ConnectionFactory");

            topicConnection = topicConnectionFactory.createTopicConnection();

            topicConnection.setClientID("ProviderRegister");

        } catch (Exception e) {

            logger.fatal("FatalError !", e);

            throw new IllegalStateException();

        }

    }





    public void register(...) {

        String providerId = ... // unique for UMPMessageListener



        TopicSession topicSession = null;

        try {

            topicSession = topicConnection.createTopicSession(true, 0);

        } catch (JMSException e) {

            logger.error("Error !", e);

        }



                UMPMessageListener messageListener = new UMPMessageListener();



                Topic topic = null;



                try {

                    topicConnection.stop();



                    try {

                        topic = (Topic) 
EJBHomeFactory.getFactory().getInitialContext().lookup(/* lookup for Topic */);

                    } catch (Exception e) {

                        logger.fatal("FatalError while geting the Topic !", e);

                        throw new IllegalStateException();

                    }



                    TopicSubscriber topicSubscriber = 
topicSession.createDurableSubscriber(

                            topic,

                            topic.getTopicName() + "." + providerId,

                            selector,

                            false

                    );



                    messageListener.setTopicSession(topicSession);

                    messageListener.setTopicSubscriber(topicSubscriber);

                    topicSubscriber.setMessageListener(messageListener);



                    topicConnection.start();

                } catch (JMSException e) {

                    logger.error("Error !", e);

                }

    }

}







Message Publisher:

-----------------

    public void publishMessage(Object aMessage) {

        TopicSession topicSession = null;

        TopicPublisher topicPublisher = null;

        ObjectMessage message = null;

        try {

            topicSession = topicConnection.createTopicSession(false, 
Session.AUTO_ACKNOWLEDGE);

            topicPublisher = topicSession.createPublisher(topic);



            message = topicSession.createObjectMessage();

            // ......

            // ...... additional properties for message

            // ......

            message.setObject(aMessage);



            topicPublisher.publish(topic, message, DeliveryMode.PERSISTENT, 4, 0);

        } catch (JMSException e) {

            logger.fatal("FatalError !", e);

            throw new IllegalStateException();

        } finally {

            if(topicSession != null) {

                try {

                    topicPublisher.close();

                    topicSession.close();

                } catch (JMSException e) {

                    logger.error("Error !", e);

                }

            }

        }

        logger.debug("Message Published: " + aMessage.toString());

    }





Best regards:

Wojciech Koszut






-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to