Sending messages with IBM MQ

When you send messages with IBM MQ, you choose what data to send, where to send it and when to send it. This type of messaging is called send and forget; the sender sends a message and relies on IBM MQ to ensure that the message reaches its destination.

Procedure

To send messages with IBM MQ, use MQSEND.

Message content can be any combination of SQL statements, expressions, functions, and user-specified data. Because this MQSEND function uses two-phase commit, the COMMIT statement ensures that the message is added to the MQ queue.

Examples

If you send more than one column of information, separate the columns with the characters || ' ' ||.

MQSEND (LASTNAME || ' ' || FIRSTNAME)

The following examples use the DB2MQ schema for two-phase commit, with the default service Db2.DEFAULT.SERVICE and the default policy Db2.DEFAULT.POLICY.

The following SQL SELECT statement sends a message that consists of the string "Testing msg":

SELECT DB2MQ.MQSEND ('Testing msg') 
  FROM SYSIBM.SYSDUMMY1;
COMMIT;

The MQSEND function is invoked once because SYSIBM.SYSDUMMY1 has only one row. Because this MQSEND function uses two-phase commit, the COMMIT statement ensures that the message is added to the queue.

When you use single-phase commit, you do not need to use a COMMIT statement. For example:

SELECT DB2MQ.MQSEND ('Testing msg') 
  FROM SYSIBM.SYSDUMMY1;

The MQ operation causes the message to be added to the queue.

Assume that you have an EMPLOYEE table, with VARCHAR columns LASTNAME, FIRSTNAME, and DEPARTMENT. To send a message that contains this information for each employee in DEPARTMENT 5LGA, issue the following SQL SELECT statement:

SELECT DB2MQ.MQSEND (LASTNAME || ' ' || FIRSTNAME || ' ' || DEPARTMENT)
  FROM EMPLOYEE WHERE DEPARTMENT = '5lGA'; 
COMMIT;