MQReceive() function

The MQReceive() function returns a message from the WMQ queue and removes the message from the queue.

Syntax


1  MQRECEIVE (?  service_name?  , policy_name?  , correl_id  )
service_name
Optional parameter. Refers to the value in the servicename column of the "informix".mqiservice table. If service_name is not specified, IDS.DEFAULT.SERVICE is used as the service. The maximum size of service_name is 48 bytes.
policy_name
Optional parameter. Refers to the value in the policyname column of the "informix".mqipolicy table. If policy_name is not specified, IDS.DEFAULT.POLICY is used as the policy. The maximum size of policy_name is 48 bytes.
correl_id
Optional parameter. A string containing a correlation identifier to be associated with this message. The correl_id is often specified in request and reply scenarios to associate requests with replies. The maximum size of correl_id is 24 bytes. If not specified, no correlation ID is added to the message.

Usage

The MQReceive() function returns a message from the WMQ location specified by service_name, using the quality of service policy policy_name. This function removes the message from the queue associated with service_name. If correl_id is specified, then the first message with a matching correlation identifier is returned. If correl_id is not specified, then the message at the head of the queue is returned. The result of the function is a string LVARCHAR type. If no messages are available to be returned, the function returns NULL.

The following table describes how the arguments for the MQReceive() function are interpreted.
Table 1. MQReceive() argument interpretation
Usage Argument interpretation
MQReceive() No arguments
MQReceive(arg1) arg1 = service_name
MQReceive(arg1, arg2) arg1 = service_name

arg2 = policy_name

MQReceive(arg1, arg2, arg3) arg1 = service_name

arg2 = policy_name

arg3 = correl_id

Return codes

A string of LVARCHAR type
The operation was successful.
NULL
No messages are available.
Error
The operation was unsuccessful.

Examples

Example 1
begin;
EXECUTE FUNCTION MQReceive();
commit;
Alternatively, the following syntax can be used:
insert into my_order_table VALUES(MQReceive());
This example receives the message at the head of the queue with the following parameters:
  • service_name: default service name
  • policy_name: default policy name
  • correl_id: none
Example 2
begin;
EXECUTE FUNCTION MQReceive('MYSERVICE');
rollback;
Alternatively, the following syntax can be used:
insert into my_order_table VALUES(MQReceive('MYSERVICE'));
This example receives the message at the head of the queue with the following parameters:
  • service_name: "MYSERVICE"
  • policy_name: default policy name
  • correl_id: none
Example 3
begin;
EXECUTE FUNCTION MQReceive('MYSERVICE','MYPOLICY');
commit;
Alternatively, the following syntax can be used:
insert into my_order_table VALUES(MQReceive('MYSERVICE', 'MYPOLICY'));
This example receives the message at the head of the queue with the following parameters:
  • service_name: "MYSERVICE"
  • policy_name: "MYPOLICY"
  • correl_id: none
Example 4
begin;
EXECUTE FUNCTION MQReceive('MYSERVICE','MYPOLICY','1234');
commit;
Alternatively, the following syntax can be used:
insert into my_order_table VALUES(MQReceive('MYSERVICE', 'MYPOLICY', '1234'));
This example receives the message at the head of the queue with the following parameters:
  • service_name: "MYSERVICE"
  • policy_name: "MYPOLICY"
  • correl_id: "1234"