The MQPUBLISH function publishes the data contained in msg-data to
the MQSeries publisher
specified in publisher-service, and using
the quality of service policy defined by service-policy.
An optional topic for the message can be specified, and an optional
user-defined message correlation identifier can also be specified.
The data type of the result is VARCHAR(1). The result
of the function is '1' if successful or '0' if unsuccessful.
Syntax
>>-MQPUBLISH--(------------------------------------------------->
>--+---------------------------------------------+--msg-data---->
'-publisher-service--,--+-------------------+-'
'-service-policy--,-'
>--+--------------------------------+--)-----------------------><
'-,--topic--+------------------+-'
| (1) |
'-,--correl-id-----'
Notes:
- The correl-id cannot be specified
unless a service and a policy are
also specified.
The schema is DB2MQ for non-transactional message
queuing functions, and DB2MQ1C for one-phase commit transactional
MQ functions.
Function parameters
- publisher-service
- A string containing the logical MQSeries destination
where the message is to be sent. If specified, the publisher-service
must refer to a publisher Service Point defined in the DB2MQ.MQPUBSUB
table that has a type value of 'P' for publisher service. If publisher-service
is not specified, the DB2.DEFAULT.PUBLISHER
will be used. The maximum size of publisher-service is
48 bytes.
- service-policy
- A string containing the MQSeries
Service Policy to be used in handling of this message. If specified,
the service-policy must refer to a Policy
defined in the DB2MQ.MQPOLICY table. A Service Policy defines a set
of quality of service options that should be applied to this messaging
operation. These options include message priority and message persistence.
If service-policy is not specified, the
default DB2.DEFAULT.POLICY
will be used. The maximum size of service-policy is
48 bytes.
- msg-data
- A string expression containing the data to be sent via MQSeries. The maximum size
for a VARCHAR string expression is 32 000 bytes and the maximum size
for a CLOB string expression is 1M bytes.
- topic
- A string expression containing the topic for the message publication.
If no topic is specified, none will be associated with the message.
The maximum size of 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".
- correl-id
- An optional string expression 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. If not specified, no correlation ID will be added to
the message. The maximum size of correl-id is
24 bytes.
Authorization
One of the following authorities
is required to execute the function:
- EXECUTE privilege on the function
- DATAACCESS authority
- DBADM authority
- SQLADM authority
Default PUBLIC privilege
In a non-restrictive
database, EXECUTE privilege is granted to PUBLIC when the function
is automatically created.
Examples
Example 1: This example publishes
the string "Testing 123" to the default publisher service (DB2.DEFAULT.PUBLISHER)
using the default policy (DB2.DEFAULT.POLICY). No correlation identifier
or topic is specified for the message.
VALUES MQPUBLISH('Testing 123')
Example
2: This example publishes the string "Testing 345" to the publisher
service "MYPUBLISHER" under the topic "TESTS". The default policy
is used and no correlation identifier is specified.
VALUES MQPUBLISH('MYPUBLISHER','Testing 345', 'TESTS')
Example
3: This example publishes the string "Testing 678" to the publisher
service "MYPUBLISHER" using the policy "MYPOLICY" with a correlation
identifier of "TEST1". The message is published with topic "TESTS".
VALUES MQPUBLISH('MYPUBLISHER','MYPOLICY','Testing 678','TESTS','TEST1')
Example
4: This example publishes the string "Testing 901" to the publisher
service "MYPUBLISHER" under the topic "TESTS" using the default policy
(DB2.DEFAULT.POLICY)
and no correlation identifier.
VALUES MQPUBLISH('Testing 901','TESTS')