Integrating IBM MQ

You can use Product Master with IBM® MQ to connect Product Master with enterprise applications to send and receive messages.

Before you begin

For IBM Product Master functions that have dependencies on IBM MQ to work, you need to update the env_settings.ini file. For more information, see Configuring IBM MQ parameters.

About this task

The main benefit of integrating with IBM MQ is the enterprise-wide connectivity. Any enterprise application can create the messages for Product Master, and IBM MQ can route these messages.

In some scenarios, an external business process must receive or update the Product Master data. Different organizations within the enterprise can take business decisions that are based on this data. Therefore, integrating Product Master with a competent message-oriented middleware product such as IBM MQ is a good communication option.

A message is defined as input in CSV, XML, or UDF format that is provided by an external source. These messages can be parsed before they are sent or after you receive the messages by using the Script API or Java™ API of Product Master that is provided for interacting with IBM MQ.

Product Master supports two ways of sending messages by using IBM MQ:
IBM MQ native message format
These messages can be produced by any IBM MQ support languages.
IBM MQ JMS
These messages can be produced by only JMS message aware API provided by IBM MQ. These APIs can be JMS or XMS clients for IBM MQ.

IBM IBM MQ is bundled with Product Master.

Procedure

  1. Create the wanted IBM MQ topology, including queue managers, queues, and channels.
    If your IBM MQ topology requires the IBM MQ Server to be installed on a remote computer, (not on the same computer as Product Master), or if you are using the Script APIs to integrate with IBM MQ, then you must correctly configure the IBM MQ for client connectivity and define the relevant server connection (SVRCONN) channel and listeners.
    Note: When you use IBM MQ with the Script API, IBM MQ client connectivity is used. The Script API provides a reduced set of capabilities and does not support transactions.
  2. When you connect to IBM MQ through the Script API, default configuration information must be provided.
    1. Configure the following properties in the common.properties file for connecting and controlling the way messages are directed to IBM MQ.
      mq_port=1414
      mq_channel=WPC.SVRCONN
      mq_hostname=wpc.ibm.com
      mq_queuemanager=WPC_QMGR
      mq_username=
      mq_password=
      mq_inbound_queue=WPC.IN.QUEUE
      mq_outbound_queue=WPC.OUT.QUEUE
      mq_queue_put_open_options=
      mq_message_put_options=
      mq_queue_get_open_options=
      mq_message_get_options=
      mq_use_utf=false
      mq_charset=819
      
    2. Set the JMS-specific default settings:
      jms_provider=IBM MQ
      jms_receive_timeout=1000
      jms_inbound_queue=WPC.IN.QUEUE
      jms_outbound_queue=WPC.OUT.QUEUE
      
  3. If you are developing the Product Master solution with the Java API, then direct access to the IBM MQ APIs must be used.
    Both client mode and bindings mode connectivity can be used. However, the design of the IBM MQ deployment topology is the deciding factor.

Example

Perform the following steps to configure IBM MQ where IBM MQ server is installed:
  1. Create and start IBM MQ queue manager WPC_QMGR
    crtmqm WPC_QMGR
    strmqm WPC_QMGR
    
  2. Create IBM MQ SVRCONN CHANNEL WPC.SVRCONN
    runmqsc WPC.SVRCONN //define the channel in the command prompt that displays
    DEF CHL(WPC.SVRCONN) CHLTYPE(SVRCONN)
    
  3. Create IBM MQ local queues. You must create the queue in runmqsc command prompt.
    DEF QL(WPC.IN.QUEUE)
    DEF QL(WPC.OUT.QUEUE)
    DEF QL(MY.QUEUE)
    
  4. Exit from runmqsc by running the end command.
  5. Start the listener on queue manager WPC_QMGR to accept TCP/IP connections.
    runmqlsr –m WPC_QMGR –ttcp –p1415 & //The & symbol at the end makes 
                                        //the listener run in the background 
The script that is provided is an example of WebSphere® MQ native message format that can be used as basis to develop solution-specific integration scripts. As in this example, you can override the default values specific to the Product Master configuration files.
//setup properties for MQ
var properties = [];
properties["mqHost"] = "test.ibm.com"; //assign the host name of the machine
                                       // where queue manager is running
properties["mqPort"] = "1415";	//The port number of the listener through
                               // which we can connect to queue manager
properties["mqChannel"] = "WPC.SVRCONN";	//CHANNEL name through which
																		  // we connect to queue manager
properties["mqManager"] = "WPC_QMGR";	    //Queue manager name
properties["mqInqueue"] = "WPC.INPUT.QUEUE";
properties["mqOutqueue"] = "WPC.OUTPUT.QUEUE";
properties["myQueue"] = "MY.QUEUE";
   
MY_MQ_HOST = properties["mqHost"];
MY_MQ_PORT = properties["mqPort"];
MY_MQ_CHANNEL = properties["mqChannel"];
MY_MQ_MGR = properties["mqManager"];
MY_MQ_INBOUND_QUEUE = properties["mqInqueue"];
MY_MQ_OUTBOUND_QUEUE = properties["mqOutqueue"];


function sendMessage(Item)
{
	//First get the Queue manager
	qMgr = mqGetQueueMgr(MY_MQ_HOST, MY_MQ_PORT, MY_MQ_CHANNEL, MY_MQ_MGR);
	
	
	//Doing a send message 
	
	mqSentMsg = qMgr.mqSendTextMsg(Item, MY_MQ_QUEUE, MQ_OPEN_OPTIONS, MQ_PUT_OPTIONS);

	textMsg = mqGetTextFromMsg(mqSentMsg);
	
	out.writeln("Sent Message :"+textMsg +"\n\n"); 
}

function createXMLMsg()
{
    var text = ""
        +  "<msg>"
        +    "<item"
        +       "<sku>123456</sku>"
        +       "<quantity>1</quantity>"
        +       "<Price>99.99</Price>"
        +    "</item>"
        +  "</msg>";
    return text;
}


function receiveMsg()
{

	qMgr = mqGetQueueMgr(MY_MQ_HOST, MY_MQ_PORT, MY_MQ_CHANNEL, MY_MQ_MGR);
	
	//Receive message from MY.QUEUE
	mqMsg = qMgr.mqGetReceivedMsg(MY_MQ_QUEUE, MQ_OPEN_OPTIONS, MQ_GET_OPTIONS); 
	
	
	textMsg = mqGetTextFromMsg(mqMsg);
	out.writeln("\n\nReceived Message : "+textMsg +"\n\n");

}

Msg = createXMLMsg();
sendMessage (Msg);
receiveMsg();