Runtime components : Service components : Communication services : MQ Connector : Tasks
  
Tasks
See also
Customizing event management
Using an MQ Connector from an application
Creating and closing a dynamic queue
Configuring an MQ Connector
MQ Connector
Customizing event management
To customize MQ Connector event management, extend the ConnectionHandler class and override the following methods:
message(MQConnectionService). MQ Connection signals this event when it receives a message from the WebSphere MQ reply queue. The event contains the MQMessage received. The default behavior is to read the message.
error(MQConnectionService). The default behavior is to do nothing.
closed(MQConnectionService). The default behavior is to do nothing.
opened(MQConnectionService). The default behavior is to do nothing.
See Event notification for the list of events triggered by this service.
See also
Tasks
Using an MQ Connector from an application
This example describes the process that could be followed for an operation on the server side that sends a message to a partner MQManager and waits for the response.
Note This is only an example of using an MQ Connector from an application, and only some of the methods of the MQ Connector public API are represented.
1 If the operation runs with a local MQ server, use the mq package:
import com.ibm.mq.*;
2 Instantiate an MQMessage for the received message:
MQMessage retrievedMessage = new MQMessage();
3 Get the service from the context:
MQConnectionService service = (MQConnectionService) getService("conversation");
4 Establish the connection with MQManager. Open the queues:
service.establishConnection();
5 Format the message to be sent to the partner:
String messageToSend = ((FormatElement) getHostSendFormat()).format(getContext());
6 Send the message to the partner, and store the correlationId to identify the response:
byte [] id = service.send(messageToSend);
7 Wait for the response:
retrievedMessage=(MQMessage)service.receive(id,30000);
8 Read the response:
String msgText = retrievedMessage.readUTF();
9 Close the connection:
service.closeConnection();
See also
Tasks
Creating and closing a dynamic queue
To create a dynamic queue instead of a static queue, set the following in the external definition for the MQConnection instance that you want to use:
For dynamic queues used to send MQ messages:
Specify the model queue for the send queue in the sendModelQ tag attribute.
Note The model queue name must be defined using WebSphere MQ.
Set the sendToQType tag attribute to "model"
For dynamic queues used to receive MQ messages:
Specify the model queue for the reply queue in the replyModelQ tag attribute.
Note The model queue name must be defined using WebSphere MQ.
Set the replyToQType tag attribute to "model"
By default, the name of the dynamic send queue is the name of the MQConnection instance appended with sendQ. For example, if the MQConnection is called MQC, the name of the send queue is MQCsendQ. To specify a different name for the send queue, use the sendDynamicQTemplate tag attribute. The name of the reply queue follows the same rules as the send queue name except that its default name ends with replyQ instead of sendQ and you use the replyDynamicQTemplate attribute to set a different name for the reply queue.
To close a dynamic queue, send it the closeConnection message. If the queue is temporary, WebSphere MQ deletes it.
See also
Tasks
Configuring an MQ Connector
This is an example of how you might configure an MQ Connector, based on the configuration described in MQ Connector example. To configure MQ Connector as in the example, you would complete the following steps:
Configure an MQ server
Configure an MQ host (This step is to simulate a partner, and is unnecessary if you are working with a real host.)
Start the MQ runtime environment
See also
Configuring an MQ server
Configuring an MQ host
Starting the MQ runtime environment
Tasks
Configuring an MQ server
Complete the following steps on the server:
1 Create a queue manager by typing the following at the command prompt:
crtmqm -q -d SERVER.TO.HOST -u SYSTEM.DEAD.LETTER.QUEUE QMS
where SERVER.TO.HOST is the default transmission queue, and QMS is the name of the queue manager (which must be the same as the QMgrName parameter in the service definition).
2 Start the queue manager by typing the following at the command prompt:
strmqm QMS
3 Determine if commands must be sent to the host. If yes, you will have to start the command server. The default system queue used to process commands is SYSTEM.ADMIN.COMMAND.QUEUE. To start the command server, type the following at the command prompt:
strmqcsv QMS
4 Create the required MQ objects for QMS by typing the following at the command prompt:
Runmqsc< c:\mqm\setup\server.tst >c:\mqm\setup\server.out
The file c:\mqm\setup\server.tst must contain the information shown as follows.
To send messages to the host:
DEFINE QREMOTE('QS1') REPLACE +
RNAME('QH1') +
RQMNAME(QMH) +
XMITQ(SERVER.TO.HOST) +
DESCR('Messages for host')
DEFINE QLOCAL(SERVER.TO.HOST) REPLACE +
USAGE(xmitq) +
DESCR('Xmit queue to host')
DEFINE CHANNEL(SERVER.TO.HOST) +
CHLTYPE(sdr) REPLACE +
TRPTYPE(tcp) CONNAME(your IP address) +
XMITQ(SERVER.TO.HOST) +
DESCR('Sender channel from server to host')
To receive messages from the host:
DEFINE QLOCAL('QS2') REPLACE +
DESCR('Messages from host')
DEFINE CHANNEL(HOST.TO.SERVER) +
CHLTYPE(rqstr) REPLACE +
CONNAME(your IP address) +
TRPTYPE(tcp) +
DESCR('Receiver channel from host to server')
where QS1 is the service definition parameter sendToQ, and QS2 is the service definition parameter replyToQ.
If commands such as channel inquiries are to be sent to the host, then an additional queue to hold replies from the host is required. To receive replies from the host:
DEFINE QLOCAL('CHANNELQ') REPLACE +
DESCR('Replies from host')
where CHANNELQ is the queue added to receive replies from the host that are related to channel queries.
The definition includes a channel to manage clients when working as an WebSphere MQ client. The definition is set on the server side. To define the server-to-client connection:
DEFINE CHANNEL(CLIENT.TO.SERVER.CH) +
CHLTYPE(svrconn) REPLACE +
TRPTYPE(tcp) +
DESCR('Server connection to client')
See also
Configuring an MQ Connector
Configuring an MQ host
To simulate a partner, if you are not working with an existing host, complete the following steps on the host:
1 Create the queue manager by typing the following at the command prompt:
Crtmqm -q -d HOST.TO.SERVER -u SYSTEM.DEAD.LETTER.QUEUE QMH
2 Start the queue manager by typing the following at the command prompt:
strmqm QMH
3 Create all required MQ objects for QMH:
Runmqsc<host.tst>host.out
The file host.tst must contain the following information:
To receive messages from the server:
DEFINE QLOCAL('QH1') REPLACE +
DESCR('Messages from the server')
DEFINE CHANNEL(SERVER.TO.HOST) +
CHLTYPE(rcvr) REPLACE +
TRPTYPE(tcp) +
DESCR('Receiver channel from server to host')
To send messages to the server:
DEFINE QREMOTE('QH2') REPLACE +
RNAME('QS2') +
RQMNAME(QMS) +
XMITQ(HOST.TO.SERVER) +
DESCR('Messages for the server')
DEFINE QLOCAL(HOST.TO.SERVER) REPLACE +
USAGE(xmitq) +
DESCR('Xmit queue to server')
DEFINE CHANNEL(HOST.TO.SERVER) +
CHLTYPE(svr) REPLACE +
TRPTYPE(tcp) +
XMITQ(HOST.TO.SERVER) +
DESCR('Sender channel from host to server')
See also
Configuring an MQ Connector
Starting the MQ runtime environment
To start the runtime environment, complete the following steps on the host machine:
1 Start the listener by typing the following at the command prompt:
runmqlsr -t tcp -m QMH
When also working as a client, start the listener at server(QMS) by entering the following at the command prompt:
runmqlsr -t tcp -p 1415 -m QMS
Note A port must be specified, because the default port (1414) is used by QMH.
2 Start the MQ program.
3 Start the channels by typing the following at the command prompt:
runmqsc QMS
start channel(SERVER.TO.HOST)
start channel(HOST.TO.SERVER)
When also working as a client, start the client connection channel by typing the following at the command prompt:
start channel(CLIENT.TO.SERVER)
See also
Configuring an MQ Connector