Runtime components : Service components : Communication services : MQ Connector : Tasks : Using an MQ Connector from an application
  
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();
Go up to
Tasks