Thursday, October 4, 2018

Message Queue in Liberty Profile ​

I didn't know that Liberty Profile has come with an internal embedded messaging server? This sound interesting to me, I should to give it a try now. For this to work, it required the full profile version of Liberty Profile. When I first start, I didn’t realize the one I'm using now is a web profile version, end up I'm not able to configure the messaging features in the server. I got the Liberty full profile from here. According to the tutorial found on the web, the configuration on the server.xml is pretty straightforward. Here is the work done in PTP configuration:

The <jmsactivationspec> tag is the very crucial part of connecting the embedded messaging engine to the MDB deployed in the server. The documentation mentions here has detail explanation on how the things should work. Without this tag or miss configure the id will give a friendly error reminding you that there are some problem with the tag. Below is the sample error in my case, notice the name of the id has mentioned in the error:
[WARNING ] CNTR4015W: The message endpoint for the MessageBean message-driven bean cannot be activated because the jms2-0.0.1-SNAPSHOT/MessageBean activation specification is not available. The message endpoint will not receive messages until the activation specification becomes available.
Code snippet below is a simple MDB app for the sake of this testing purpose:


Connect to MDB without using JNDI 

Now the server is ready to accept the incoming messages. The sample below is a standalone Java program that will establish a connection to Liberty Profile, it doesn’t use the JNDI to send the message to MDB. This is the hardest part as not much information available on the web. Eventually, I have identified 3 libraries which are needed in order to build this program, there are available in the WAS installation path located at AppServer/runtimes​. Here are the 3 libraries:
  1. com.ibm.ws.ejb.thinclient_8.5.0.jar
  2. com.ibm.ws.sib.client.thin.jms_8.5.0.jar
  3. com.ibm.ws.orb_8.5.0.jar
Looking at the code above, I have no idea what the setBusName() on line 16 trying to do? It will just throw an error as seen below if I remove that line:
Caused by: com.ibm.websphere.sib.exception.SIIncorrectCallException: CWSIT0003E: No busName property was found in the connection properties.
  at com.ibm.ws.sib.trm.client.ClientAttachProperties.< init>(ClientAttachProperties.java:109)
  at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.createConnection(TrmSICoreConnectionFactoryImpl.java:295)
  at com.ibm.ws.sib.trm.client.TrmSICoreConnectionFactoryImpl.createConnection(TrmSICoreConnectionFactoryImpl.java:222)
  at com.ibm.ws.sib.api.jmsra.impl.JmsJcaConnectionFactoryImpl.createCoreConnection(JmsJcaConnectionFactoryImpl.java:711)
  at com.ibm.ws.sib.api.jmsra.impl.JmsJcaConnectionFactoryImpl.createCoreConnection(JmsJcaConnectionFactoryImpl.java:647)
  at com.ibm.ws.sib.api.jmsra.impl.JmsJcaConnectionFactoryImpl.createConnection(JmsJcaConnectionFactoryImpl.java:376)
  at com.ibm.ws.sib.api.jms.impl.JmsManagedConnectionFactoryImpl.createConnection(JmsManagedConnectionFactoryImpl.java:162)
  ... 3 more

Connect to MDB with JNDI

This is much easier to implement as compare to the previous client app just because it uses JNDI. It doesn’t require any additional library from WAS server. Long story short, here is the code:

No comments: