Search This Blog

2009-05-16

How to integrate GlassfishV2.1 and Websphere MQV6

For my latest project I had to create a web application which integrates an existing Websphere Message Broker application.According to what is so important at developing software, i am talking about "keep it simple",  i chose to stick to the components described in the javaEE specification.
JSF for the front end development, local stateless session beans for the business logic, oracle's toplink as JPA Provider to provide access to an Oracle database. WebApp and EJBs deployed into one EAR to the application server glassfish V2.1, using my favorite IDE Netbeans 6.5.1. 
The only tricky thing was: How do i integrate this Broker Application? 
The customer decided to have a request reply message broker flow for the web application. So i created a facade for the web application to handle the messages between the web app and the broker application. This facade has the TransactionAttribute 'Not supported' and delegates to 2 stateless session beans with TransactionAttribute 'Requires New'. One bean is responsible for sending messages, the other for receiving. 

But back to topic of this post. I chose the jms ressource adapter 'generic ra', which is part of the glassfish v2.1 download. I followed installation steps described in this document. This is a amazing document. Everything is very well described and all the commands i had to execute were successfull. However there is one sentence which confused me:
If you have the MQ broker running on a different machine and need to access it remotly, please refere the WebSphere MQ documentation for configuration details.
Yes, i have MQ broker running on a different machine. So what do i have to do now? I just had to change localhost with the ip adress of the machine where mq is running to the following line
def qcf(QCF) hostname(localhost) port(1414) channel(SYSTEM.DEF.SVRCONN) transport(CLIENT) qmanager(QM1)
That's all. BUT there was one thing i had to struggle for 2 days. While trying to send messages i always received the following error message:
MQError in allocating a connection. Cause: null
With the help and awesome support of Ramesh Parthasarathy,  thank you again Ramesh, we finally found the problem. The ressource adapter is configured to look up the MQ configuration in a .binding file. I placed this file into /tmp and configured the ressource adapter like this:
java.naming.provider.url=file://tmp
This configuration did not work for me. I had to add another slash like this, and finally i got it working
java.naming.provider.url=file:///tmp
it was really tough to find out what the problem was. After I was able to send a message to MQ with a local jms client (java program) on a windows xp machine, I thought there must be something wrong with the file system configuration. I'll post the java code of this very useful client in the next blog message. Another hint: If you don't use XA transaction support, configure your connection pool with the settings
--transactionsupport . NoTransaction
If you just skip this line, you will get the following error while trying to send a message.
MQError in allocating a connection. Cause: SupportsXA is configured as false. Dont use the resource adapter in XA mode
Last but not least. Never forget to start and close the connection in your java code. Otherwise you won't be able to send or read/consume messages from a Queue, even though the connection is working :)

No comments:

Post a Comment