Reading from IBM MQ

<< Click to Display Table of Contents >>

Navigation:  Integrating Blaze with Other Systems > Reading Data into s-Server > Reading from Other Sources  >

Reading from IBM MQ

Previous pageReturn to chapter overviewNext page

To read data from IBM MQ queue managers, use the Extensible Common Data Framework. IBM MQ is a publish-subscribe messaging framework that supports stream processing applications created in s-Server.

All adapter or agent implementations involve configuring options. For adapters, you configure and launch the adapter in SQL, using either server or foreign stream/table options. For agents, you configure such options using a properties file and launch the agent at the command line. Many of the options for the ECD adapter and agent are common to all I/O systems. The CREATE FOREIGN STREAM topic in the Streaming SQL Reference Guide has a complete list of options for the ECD adapter.

int_MQseries_read_write

Installing com.ibm.mq.jar and com.ibm.mq.jmqi.jar

Before you can use the ECDA IBM MQ adapter, you need to install the IBM MQ client in your s-Server environment. These are installed with IBM MQ. See IBM MQ classes for Java at the IBM support site for more details.

To install these classes into your s-Server environment, copy both into the $SQLSTREAM_HOME/lib directory.

Note: $SQLSTREAM_HOME refers to the installation directory for s-Server, such as /opt/sqlstream/5.0.XXX/s-Server.

Implementation follows the general framework for writing to files with the ECD Adapter or Agent.

Implementing the IBM MQ ECD Adapter

To define the server, you use code along the following lines:

CREATE OR REPLACE SERVER "IBMMQServer" TYPE 'MQSeries'

FOREIGN DATA WRAPPER ECDA;

 

Note: ECD Adapter server definitions need to reference the ECD foreign data wrapper. You can do so with the syntax FOREIGN DATA WRAPPER ECDA.

Next, you create a foreign stream object. This object contains connection information on the MQSeries queue manager. Streams, like most SQL objects (but unlike data wrappers and servers), should be created within a schema. The following code first creates a schema in which to run the rest of the sample code below, then creates a foreign stream named "IBMMQSourceStream." To read from the MQSeries topic, you SELECT from this stream.

CREATE OR REPLACE SCHEMA "IBMMQSource";

SET SCHEMA '"IBMMQSource"';

 

CREATE OR REPLACE FOREIGN STREAM "IBM_MQ_ReaderStream"

(

SERVER IBMMQServer

OPTIONS

(queue_name 'SYSTEM.DEFAULT.LOCAL.QUEUE',

userid 'IBMMQ_USER',

hostname '127.0.0.1',

queue_manager_name 'TEST2',

CHANNEL_NAME 'SYSTEM.DEF.SVRCONN');

 

Implementing the ECD Agent for IBMMQ

The ECD agent takes similar options, but these options need to be formatted in a properties file along the lines of the following. These properties correspond to those defined for the adapter above.

Note: Before using the ECD agent, you need to create a source stream for it. In the below example, you would need to create the foreign stream "FILEWRITERSTREAM." (Agent properties are not case sensitive.)

SCHEMA=IBMMQSOURCE

--This stream needs to be set up in s-Server

TABLE_NAME=IBM_MQ_ReaderStream

QUEUE_NAME=SYSTEM.DEFAULT.LOCAL.QUEUE

USERID=IBMMQ_USER

HOSTNAME=127.0.0.1

QUEUE_MANAGER_NAME=TEST2

CHANNEL_NAME=SYSTEM.DEF.SVRCONN

 

Special Columns Generated by ECDA for IBM MQ (Input Only)

The Extensible Common Data Adapter generates several special columns when parsing data from IBM MQ. You can declare these columns to make them part of a foreign stream or table.

Special Column

Type

Meaning

APPLICATION_ID_DATA

VARCHAR(256)

The application ID of the application that delivered this row in a message.

PUT_APPLICATION_TYPE

INTEGER

The value set in the application type field of the incoming message containing this row.

PUT_APPLICATION_NAME

VARCHAR(256)

The value set in the application name field of the incoming message containing this row

APPLICATION_ORIGIN_DATA

VARCHAR(256)

The locater of the application where this row's data originated.

PUT_DATA_TIME

TIMESTAMP

The data time on the message containing this row.

USER_ID

VARCHAR(256)

The user id of the sender of the message containing this row.

GROUP_ID

VARCHAR(256)

The group id to which the message containing this row was sent.

MESSAGE_SEQUENCE_NUMBER

INTEGER

The IBM MQ sequence number of the message containing this tuple.

The ECDA Websphere IBM MQ adapter option lets you write messages from s-Server to IBM MQ queue managers. To do so, you first create a foreign stream with a predefined IBM MQ server object as the SERVER option.