DB2 Version 9.7 for Linux, UNIX, and Windows

RECEIVE_MESSAGE function - Get a message from a specified pipe

The RECEIVE_MESSAGE function gets a message from a specified pipe.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-DBMS_PIPE.RECEIVE_MESSAGE--(--pipename -+------------+--)---><
                                           '-,--timeout-'      

Return value

The RECEIVE_MESSAGE function returns one of the following status codes of type INTEGER.
Table 1. RECEIVE_MESSAGE status codes
Status code Description
0 Success
1 Time out

Function parameters

pipename
An input argument of type VARCHAR(128) that specifies the name of the pipe. If the specified pipe does not exist, the pipe is created implicitly. For more information about pipes, see DBMS_PIPE module.
timeout
An optional input argument of type INTEGER that specifies the wait time in seconds. The default is 86400000 (1000 days).

Authorization

EXECUTE privilege on the DBMS_PIPE module.

Example

In proc1, send a message. In proc2, receive and unpack the message. Timeout if the message is not received within 1 second.

SET SERVEROUTPUT ON@ 

CREATE PROCEDURE proc1()
BEGIN
  DECLARE status INTEGER;
  SET status = DBMS_PIPE.CREATE_PIPE( 'pipe1' );
  SET status = DBMS_PIPE.PACK_MESSAGE('message1');
  SET status = DBMS_PIPE.SEND_MESSAGE( 'pipe1' );
END@

CREATE PROCEDURE proc2()
BEGIN
  DECLARE    v_item          VARCHAR(80);
  DECLARE    v_status        INTEGER;
  SET v_status = DBMS_PIPE.RECEIVE_MESSAGE('pipe1',1);
  CALL DBMS_OUTPUT.PUT_LINE('RECEIVE_MESSAGE status: ' || v_status);
  CALL DBMS_PIPE.UNPACK_MESSAGE(v_item);
  CALL DBMS_OUTPUT.PUT_LINE('Item: ' || v_item);
END@

CALL proc1@
CALL proc2@

This example results in the following output:

RECEIVE_MESSAGE status: 0
Item: message1