FileDocCategorySizeDatePackage
JMSUtil.javaAPI DocJBoss 4.2.12034Fri Jul 13 20:56:00 BST 2007xpetstore.util

JMSUtil

public class JMSUtil extends Object
author
Herve Tchepannou

Fields Summary
Constructors Summary
Methods Summary
public static voidsendToJMSQueue(java.lang.String queueName, java.io.Serializable obj, boolean transacted)

        Debug.print( "sendToJMSQueue(" + queueName + "," + obj + "," + transacted + ")" );

        InitialContext  ic = null;
        QueueConnection cnn = null;
        QueueSender     sender = null;
        QueueSession    session = null;

        try
        {
            ic = new InitialContext(  );

            Queue                  queue = ( Queue ) ic.lookup( queueName );

            QueueConnectionFactory factory = ( QueueConnectionFactory ) ic.lookup( JNDINames.QUEUE_CONNECTION_FACTORY );
            cnn     = factory.createQueueConnection(  );
            session = cnn.createQueueSession( transacted, QueueSession.AUTO_ACKNOWLEDGE );

            ObjectMessage msg = session.createObjectMessage( obj );

            sender = session.createSender( queue );
            sender.send( msg );
        }
        finally
        {
            if ( sender != null )
            {
                sender.close(  );
            }

            if ( session != null )
            {
                session.close(  );
            }

            if ( cnn != null )
            {
                cnn.close(  );
            }

            if ( ic != null )
            {
                ic.close(  );
            }
        }