How to validate IBM MQ connection for Pool - java-8

I am developing IBM MQ Connection pool using Apache commons pool (2.4.2 ). IBM MQ JAR version 8.
As part of Pool concept , I need to validate the connection before return to program.
Help me on how to validate IBM MQ connection ?
Java 8
IBM MQ 8
Apache commons pool 2.4.2
JMS 2.0

I assume you are using version 2 of Commons pool. To validate instances before delivering them to pool clients, you need to:
Implement valiateObject() in your PooledObjectFactory.
Set the pool's testOnBorrow and / or testOnCreate property to true.
Setting testOnBorrow to true causes instances to be validated each time they are borrowed from the pool. testOnCreate (new in Pool 2) validates only once, when the instance is created.

Related

IBM WAS autoreconnect to IBM MQ

I have a Java EE aplication on IBM WAS 8.5.5.x which connects to IBM MQ 9.0 with Activation specs.
I'm interested in problem of autoreconnecting from WAS to MQ, if for some reason there was a connection loss (MQ server was shut down).
In IBM WAS admin console I have set Resources -> JMS -> Queue connection factories -> Factory -> Advanced properties -> Client reconnect options -> RECONNECT
I set Client reconnect timeout to 120 seconds.
That worked well (there was a reconnection) until queue manager was ended for a long period of time (about 9 hours).
Am I doing something wrong ? Is there a way to make QCF or Activation Spec auto reconnect if there was a connection loss. Is there a limit on number of reconnetion tries ?
This behavior can be controlled by updating the "Reconnection retry count" and "Reconnection retry interval" properties for "WebSphere MQ messaging provider" JMS provider in WAS console.
Path :Resources > JMS Providers > WebSphere MQ messaging provider (select scope) > Resource adapter properties (under Additional properties) .
Reconnection retry count : The maximum number of attempts made by a WebSphere MQ messaging provider activation specification to reconnect to a WebSphere MQ queue manager if a connection fails.
Reconnection retry interval : The time, in milliseconds, that a WebSphere MQ messaging provider activation specification waits before making another attempt to reconnect to a WebSphere MQ queue manager.
Refer : https://www.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/umj_pjmswmq_raprops.html for more details.

Connecting to remote JMS Provider

I am trying to connect to a foreign JMS provider from Websphere Application Server.
Can we connect to a remote JMS provider from Websphere Application Server without using Websphere MQ?
You don't need WebSphere MQ, if your provider supports JMS 1.1 you can configure it as Generic JMS Provider. See the following page as a startnig point: Choosing a messaging provider
Choose a third-party messaging provider. You can use any third-party
messaging provider that supports the JMS Version 1.1 unified
connection factory. You might want to do this, for example, because of
existing investments.
Notes:
To administer a third-party messaging provider, use the resource adaptor or client supplied by the third party. You can still use the
WebSphere Application Server administrative console to administer the
JMS connection factories and destinations that are within WebSphere
Application Server, but you cannot use the administrative console to
administer the JMS provider itself, or any of its resources that are
outside of WebSphere Application Server.
To use message-driven beans (MDBs), third-party messaging providers must include Application Server Facility (ASF), an optional feature that is part of the JMS Version 1.1 specification, or use an inbound resource adapter that conforms to the Java EE Connector Architecture (JCA) Version 1.5 or 1.6 specification.

How to create a TCP/IP Socket connection pool on IBM WebSphere Application Server 8?

I have a situation where every request handled by my web-application that is deployed on IBM WebSphere Application Server 8 has to talk to a remote system via a Socket connection. Is possible to create a connection pool for the Socket connections in IBM WebSphere Application Server 8. If yes, how?
Environment: Java 1.6, JEE5, IBM WAS8
WebSphere Application Server doesn't have builtin support for pooling arbitrary connections. It does support JCA and its connection pooling, so probably the closest you'll get is to write your own resource adapter that opens connections. That's no exactly trivial, and unfortunately, I'm not aware of any libraries that already do this.

How to pool the JMS connection in a standalone Java application?

We are working on an IBM WebSphere MQ application, and we use JMS API to operate the message. But we have a problem that the connection takes too much time, and we want to pool the JMS connection, for it's a standalone application, we have no application container to provide JNDI or pooling service. So is there a solution to resolve this? For JDBC we can use DBCP or c3p0 to archive pooling datasource, in JMS, is there any similar project that can pool JMS connections?
It used to be that the JMS MQConnectionFactory had pooling built in, but it seems that in version 7, it has been removed.
Set the use of ConnectionPooling in earlier versions of the WebSphere
MQ classes for JMS. This method is retained for compatibility with
older MQJMS applications, but, because this Connection Pooling
functionality has been removed from version 7, setting this property
will have no effect.
In the absence of anything else, you can use Apache Commons Pool. Same idea as DBCP (which uses Pool) but for non JDBC objects.
Spring's CachingConnectionFactory works well for this use case.
This answer in https://stackoverflow.com/a/31119435/1765341 explains how to do this in Tomcat, but the code there can easily be adapted for Java standalone applications. This should be much easier (and less error prone) than writing an Apache Commons Pool implementation.

What is Foreign JMS provider? What is the typical role of Weblogic in a JMS application?

Currently I am working on a JMS application. But I use plain JMS API and Property file for configurations. My application is running in Weblogic and connects to MQ series server of my client.
Recently I got to know I can use Weblogic for JMS configurations.
Please explain.
What is "Foreign JMS provider"?
Is Weblogic also a JMS server or Foreign JMS provider or Both?
Weblogic provides the JMS Server features fully compliant with all JMS spec elements such as ConnectionFactory and Destinations. On this JMS Server you can connect and send messages to the client's Messaging Server via a configured Destination.
In addition using Weblogic as the JMS Server gives you lot many features such as Message Retry in case of failure, setting message quotas as well as enhanced monitoring of the JMS Server to track errors. The idea is to have more configuration driven settings for performance, deadlocks, tuning, filestore or database store etc.
A full list of such features is given at http://download.oracle.com/docs/cd/E12840_01/wls/docs103/jms/fund.html#wp1071787
A Foreign JMS Provider in Weblogic is the term used to define JMS implementations other than Weblogic JMS. An example is IBM MQ in your case.
Once the Foreign Provider is configured within Weblogic, for all practical purposes within the code - it can be called as if it was on local JNDI lookup. Weblogic will make the remote calls transparent to your code. This allows you to change your destination via configuration on the Weblogic console.
You will need a Messaging Bridge within Weblogic JMS Server to connect a source destination from which messages are received, and a target destination to which messages are sent.
Some essential reading on this is at: http://download.oracle.com/docs/cd/E12840_01/wls/docs103/jms_admin/advance_config.html#wp1075917
and an example of configuring IBM MQ as a Foreign Provider is at http://www.ibm.com/developerworks/websphere/library/techarticles/0604_kesavan/0604_kesavan.html#N1011D

Resources