smallarv
smallarv

Reputation: 57

How MQ Client like Java Client listen messages from MQ Server running ServerConn Channel

I am looking for detailed description on how IBM MQ Client or listener get the messages from MQ Server when new messages are placed on MQ Queue or Topic.

  1. How the connection between MQ Client and MQ Server are created?
  2. Does MQ Client initiates the connection with Server or does server initiates the connection to its consumer?
  3. In case we have connection pool defined on MQ Client, how client knows that it has to create more connections with Server as the messages are increasing on Server? How Client know about the messages on Server?
  4. Is there a communication from Server to Client which tells client that new messages have arrived?

I am looking for these details not the details on how this is setup or how to setup MQ Channels or Listeners. I am looking for how it works behind the scene.

If someone can point me to the right direction or documentation, it would be great.

Upvotes: 0

Views: 1508

Answers (2)

Roger
Roger

Reputation: 7456

The first thing you should do is take a course on JMS/IBM MQ or go to the new IBM conference called: Integration Technical Conference

Ok, now to your questions:

  1. How the connection between MQ Client and MQ Server are created?

You simply issue the createQueueConnection method of QueueConnectionFactory class and specify the credentials.

QueueConnection conn = cf.createQueueConnection("myUserId", "myPwd");
  1. Does MQ Client initiates the connection with Server or does server initiates the connection to its consumer?

MQ client application starts the connection - always.

  1. In case we have connection pool defined on MQ Client, how client knows that it has to create more connections with Server as the messages are increasing on Server? How Client know about the messages on Server?

It is up to the team's architect or lead developer to understand message flow and message patterns. Hence, they will know what to set the pool count at. Also, lots and lots of testing too. Some client applications will only require a pool count of 10 whereas other applications may need a pool count of 50 because it is a heavy flow.

  1. Is there a communication from Server to Client which tells client that new messages have arrived?

You use the createReceiver method of the QueueSession class to retrieve a message. Set a timeout value for the createReceiver method rather than continuously polling the queue manager.

Again, some training on the use of JMS/IBM MQ is strongly recommended.

Upvotes: 0

Justin Bertram
Justin Bertram

Reputation: 34973

It's hard to speak definitively about how the IBM WebSphereMQ client & server work since they're closed source, but based on my experience with other messaging implementations I can provide a general explanation.

A JMS connection is initiated by a client to a server. A JMS client uses a javax.jms.ConnectionFactory to create a javax.jms.Connection which is the connection between the client and server.

Typically when a client uses a pool the pool is either filled "eagerly" (which means a certain number of connections are created when the pool is initialized to fill it to a certain level) or "lazily" (which means the pool is filled with connections one-by-one as clients request them from the pool). If a client requests a connection from the pool and if all the connections in the pool are being used and the maximum size of connections allowed by the pool hasn't been reached then another connection will be created. If the pool has reached its maximum allowed size (i.e no more connections can be created) then the client requesting a connection will have to wait for another client to return their connection to the pool at which point the pool will then give it to the waiting client.

A JMS client can find out about messages on the server in a few different ways.

If the JMS client wants to ask the server occasionally about the messages it has on a particular queue it can create a javax.jms.Consumer and use the receive() method. This method can wait forever for a message to arrive on the queue or it can take a timeout parameter so that if a message doesn't arrive in the specified timeout the call to receive() will return.

If the JMS client wants to receive a message from a particular queue as soon as the message arrives on the queue then it can create a javax.jms.MessageListener implementation and register it on the queue. When such a listener is registered on a queue then when a message arrives on the queue the server will send the message to the listener. This is sometimes referred to as a "callback" since the server is "calling back" to the client.

Upvotes: 1

Related Questions