MQPublish() function
The MQPublish() function publishes a message on one or more topics to a queue managed by WMQ.
Syntax
- publisher_name
- Optional parameter. Refers to the value in the pubsubname column
of the "informix".mqipubsub table. If publisher_name is
not specified, IDS.DEFAULT.PUBLISHER is used as the publisher. The
maximum length of publisher_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.PUB.SUB.POLICY is used as the policy. The maximum size of policy_name is 48 bytes.
- msg_data
- Required parameter. A string containing the data to be sent by WMQ. The maximum size of the string is defined by the LVARCHAR data type. If msg_data is NULL, it sends a zero-length message to the queue.
- topic
- Optional parameter. A string containing the topic for the message publication. The maximum size of a topic is 40 bytes. Multiple topics can be specified in one string (up to 40 characters long). Each topic must be separated by a colon. For example, "t1:t2:the third topic" indicates that the message is associated with all three topics: t1, t2, and the third topic. If no topic is specified, none are associated with the message.
- 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 MQPublish() function publishes data to WMQ. It requires the installation of the WMQ Publish/Subscribe component of WMQ, and that the Message Broker is running.
The MQPublish() function publishes the data contained in msg_data to the WMQ publisher specified in publisher_name, using the quality of service policy defined by policy_name.
The following table describes
how the arguments for the MQPublish() function
are interpreted.
Usage | Argument interpretation |
---|---|
MQPublish(arg1) | arg1 = msg_data |
MQPublish(arg1, arg2) | arg1 = msg_data arg2 = topic |
MQPublish(arg1, arg2, arg3) | arg1 = publisher_name arg2 = msg_data arg3 = topic |
MQPublish(arg1, arg2, arg3, arg4) | arg1 = publisher_name arg2 = policy_name arg3 = msg_data arg4 = topic |
MQPublish(arg1, arg2, arg3, arg4, arg5) | arg1 = publisher_name arg2 = policy_name arg3 = msg_data arg4 = topic arg5 = correl_id |
Return codes
- 1
- The operation was successful.
- Error
- The operation was unsuccessful.
Examples
- Example 1
begin; EXECUTE FUNCTION MQPublish('Testing 123'); commit:
This example publishes the message with the following parameters:- publisher_name: default publisher
- policy_name: default policy
- msg_data: "Testing 123"
- topic: None
- correl_id: None
- Example 2
begin; EXECUTE FUNCTION MQPublish ('MYPUBLISHER','Testing 345','TESTTOPIC'); commit;
This example publishes the message with the following parameters:- publisher_name: "MYPUBLISHER"
- policy_name: default policy
- msg_data: "Testing 345"
- topic: "TESTTOPIC"
- correl_id: None
- Example 3
begin; EXECUTE FUNCTION MQPublish('MYPUBLISHER', 'MYPOLICY','Testing 678','TESTTOPIC','TEST1'); commit;
This example publishes the message with the following parameters:- publisher_name: "MYPUBLISHER"
- policy_name: "MYPOLICY"
- msg_data: "Testing 678"
- topic: "TESTTOPIC"
- correl_id: "TEST1"
- Example 4
begin; EXECUTE FUNCTION MQPublish('Testing 901','TESTS'); commit;
This example publishes the message with the following parameters:- publisher_name: default publisher
- policy_name: default policy
- msg_data: "Testing 901"
- topic: "TESTS"
- correl_id: None
- Example 5
begin; EXECUTE FUNCTION MQPublish('SEND.MESSAGE', 'emergency', 'CODE BLUE', 'expedite'); commit;
This example publishes the message with the following parameters:- publisher_name: "SEND.MESSAGE"
- policy_name: "emergency"
- msg_data: "CODE BLUE"
- topic: "expedite"
- correl_id: None
- Example 6
- The following table contains sample rows and columns in the "informix".mqipubsub table.
Sample row pubsubname column receiver column pubsubtype column Sample row 1 'IDS.DEFAULT.
PUBLISHER'' ' 'Publisher' Sample row 2 'IDS.DEFAULT.
SUBSCRIBER''IDS.DEFAULT.
SUBSCRIBER.RECEIVER''Subscriber' begin; EXECUTE FUNCTION MQSubscribe('IDS.DEFAULT.SUBSCRIBER', 'IDS.DEFAULT.PUB.SUB.POLICY', 'Weather'); commit;
This statement demonstrates a subscriber registering an interest in messages containing the topicWeather,
with the following parameters:- subscriber_name: "IDS.DEFAULT.SUBSCRIBER"
- policy_name: "IDS.DEFAULT.PUB.SUB.POLICY"
- topic: "Weather"
begin; EXECUTE FUNCTION MQPublish ('IDS.DEFAULT.PUBLISHER', 'IDS.DEFAULT.PUB.SUB.POLICY', 'Rain', 'Weather'); commit;
This statement publishes the message with the following parameters:- publisher_name: "IDS.DEFAULT.PUBLISHER"
- policy_name: "IDS.DEFAULT.PUB.SUB.POLICY"
- msg_data: "Rain"
- topic: "Weather"
- correl_id: None
begin; EXECUTE FUNCTION MQReceive ('IDS.DEFAULT.SUBSCRIBER.RECEIVER', 'IDS.DEFAULT.PUB.SUB.POLICY'); commit;
This statement receives the message with the following parameters (it returns "Rain"):- service_name: "IDS.DEFAULT.SUBSCRIBER.RECEIVER"
- policy_name: "IDS.DEFAULT.PUB.SUB.POLICY"