Here's a little HOWTO that I wrote for the project I'm currently working
on.

Using JBoss with MQSeries JMS
=============================

This information is up to date for JBoss 3.0.1.

You'll need the MQSeries classes for Java.

To put MQSeries JMS queues into the JBoss JNDI namespace, you need to
use the MQSeries JMS Administration Tool (JMSAdmin), described in
Chapter 5 of IBM's MQSeries manual, _Using Java_.

Setting up JMSAdmin to talk to JBoss
------------------------------------

Make sure you've set the environment variable MQ_JAVA_INSTALL_PATH, and
put the MQSeries JARs in your CLASSPATH, as described in _Using Java_.

Find the following JARs in your JBoss installation, and put them in your
CLASSPATH:

    * jnpserver.jar
    * jnet.jar
    * log4j.jar
    * jboss-common.jar

Edit the file %MQ_JAVA_INSTALL_PATH%\bin\JMSAdmin.config so that it
contains the following lines:

INITIAL_CONTEXT_FACTORY=org.jnp.interfaces.NamingContextFactory
PROVIDER_URL=jnp://localhost:1099

Start JBoss. Then open a command prompt, cd to the
%MQ_JAVA_INSTALL_PATH%\bin directory, and test the setup by typing:

IVTSetup
IVTRun -url jnp://localhost:1099 -icf
org.jnp.interfaces.NamingContextFactory
IVTTidy

As with all JBoss JNDI bindings, these changes are only as persistent as
the JBoss JNDI setup, which currently is not very, so you will have to
run this every time you restart JBoss.

If that works, you can then use JMSAdmin to bind your queues to the
JBoss JNDI namespace.

Using MQSeries JMS from within JBoss
------------------------------------

Drop all the MQSeries JAR files into your JBoss server's lib directory.

After you start JBoss, but before your application does anything with
JMS, you need to use JMSAdmin to set up JNDI names.

The JBoss JNDI implementation is not persistent, so your JMS queues will
be lost if you restart JBoss. To get around this, have your JMSAdmin
commands put into a script file, such as jbossjmssetup.scp. Then, when
you restart JBoss, simply rerun the script by typing
%MQ_JAVA_INSTALL_PATH%\bin\JMSAdmin < myscript.scr.

Enlisting MQSeries in XA Transactions
-------------------------------------

Using JMSAdmin, define an XAQueueConnectionFactory rather than a
QueueConnectionFactory, e.g.:

def xaqcf(myXAQueueConnectionFactory)

In jms-service.xml, put the JNDI name of your XAQueueConnectionFactory
in the QueueFactoryRef attribute, e.g.:

<attribute name="QueueFactoryRef">myXAQueueConnectionFactory</attribute>

Comment out the SecurityDomainJndiName attribute at the bottom of the
file; this doesn't seem to work. (TODO: look into this.)

In Java, get a QueueConnectionFactory and a QueueConnection like this:

QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)
    ctx.lookup("java:/JmsXA"); // Note that this is defined in
jms-service.xml
QueueConnection queueConnection =
    queueConnectionFactory.createQueueConnection();

Don't attempt to call start() on the QueueConnection; it will throw an
exception saying that this method isn't applicable when using JCA. JBoss
starts the connection for you.

Look up your queue in JNDI, under the name that you bound it to with
JMSAdmin.

Important:

For each transaction, you must:

   1. Begin a UserTransaction.
   2. Create a new, transacted QueueSession (e.g.
queueConnection.createQueueSession(true, AUTO_ACKNOWLEDGE)).
   3. Do some work with the QueueSession.
   4. Commit the transaction.
   5. Close the QueueSession.

If you don't create a new QueueSession after beginning each transaction,
the session won't be enlisted in the transaction. If you don't close the
session after committing the transaction, it won't be returned to the
JCA connection pool.

It looks as if it's OK for multiple threads (and transactions) to share
the same QueueConnection.
 


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to