msgpublish  msgsend

Chapter 4: SQL Reference

msgrecv

Description

Provides a SQL interface to receive messages from different service endpoints, which must be queues.

msgrecv receives a message from the specified service_provider and service_destination, and returns that message. The value returned is the message body returned by the service provider, converted to the specified return type.

Syntax

msgrecv_call ::=
	msgrecv (end_point options_filter_and_returns)
options_filters_and_return ::= 
	[option_clause] [filter_clause] [returns_clause]
option_clause ::=   [,] option option_string
filter_clause ::=  [,] message selector message_filter
message_filter ::=basic_character_expression
returns_clause ::=  [,] returns sql_type
end_point ::= basic_character_expression
sql_type ::=  
	varchar(integer) | java.lang.String | text
	| varbinary(integer ) |  image 
 message_filter ::= basic_character_expression

Parameters

basic_character_expression

is a SQL query expression with a datatype is char, varchar, or java.lang.String.

end_point

is a basic_character_expression where the runtime value is a service_provider_uri. The destination of a message.

filter_clause

passes a message_filter directly to a specified message provider, which determines its use.

message_filter

is a filter parameter and basic_character_expression. The filter value is passed directly to the message provider. Its use depends on the message provider. See the Usage section below for a discussion of message filters.

Any message_filter specified to msgrecv is ignored if the provider class is “ibm_mq.”

msgrecv

receives a message from the specified service_provider and service_destination, and returns that message. The value returned is the message body returned by the service provider, converted to the specified return type.

option

is a value shown in Table 4-8 for MQSeries, and Table 4-9 for TIBCO JMS.

NoteUnrecognized option names result in an error.

option_string

is the general format of the option_string is specified in option_string. The options for msgrecv are described in Table 4-8 for MQSeries and Table 4-9 for JMS.

returns_clause

is the datatype that you want returned.

If you do not specify a returns_clause, the default is varchar(16384).

If you specify a returns_clause of type varbinary or image, the data is returned in the byte ordering of the message.

sql_type

The SQL datatype. The legal SQL datatypes are:

Examples

Example 1

MQSeries – a message is read from the queue Q1 with a specified timeout. If no messages are available on Q1 before the timeout of 3 seconds, a null value is returned:

select msgrecv(
'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
option 'timeout=3ss')

Example 2

MQSeries – a correlationId is specified without a timeout. The call returns when a message matching the correlationId is available on the queue:

select msgrecv(
'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
option 'correlationId=x67a12z99')

Example 3

MQSeries – a groupId is specified, as well as allMsgsInGroup, but a timeout is not specified. This call blocks until all the messages for the groupId specified are available on the queue:

select msgrecv(
'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
option 'groupId=g7853b77,allMsgsInGroup=yes')

Example 4

MQSeries – these messages already exist on the queue:

AA BB CC DD EE FF GG HH

The first three messages are read in browse mode (AA-CC), and CC is removed. The browse cursor is then set back to the beginning, and three messages are read in browse mode (AA-DD), and DD is removed. The read that removes CC causes CC to not be included when the browse is repositioned at the beginning. Finally, a read is performed with position set to next, which reads and removes AA. When this example completes, the messages AA, CC, and DD will no longer remain on the queue.

-- Browse cursor at the beginning, this will return 'AA'
select msgrecv(
    'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
    option 'inputMode=browse+Qdefault,browse=first')

-- Browse the next message, this will return 'BB'
select msgrecv(
    'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
    option 'inputMode=browse+Qdefault,browse=next')

-- Browse the next message, this will return 'CC'
select msgrecv(
    'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
    option 'inputMode=browse+Qdefault,browse=next')

-- Remove the message under the browse cursor, this will return 'CC'
select msgrecv(
    'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
    option 'inputMode=browse+Qdefault,position=cursor')

-- Reposition browse cursor at the beginning, this will return 'AA'
select msgrecv(
    'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
    option 'inputMode=browse+Qdefault,browse=first')

-- Browse the next message, this will return 'BB'
select msgrecv(
    'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
    option 'inputMode=browse+Qdefault,browse=next')

-- Browse the next message, this will return 'DD'
select msgrecv(
    'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
    option 'inputMode=browse+Qdefault,browse=next')

-- Read the message under the cursor, this will return 'DD'
select msgrecv(
    'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
    option 'inputMode=browse+Qdefault,position=cursor')

-- Read the next message in queue order, this will return 'AA'
select msgrecv(
    'ibm_mq:chnl1/TCP/host1(5678)?qmgr=QM,queue=Q1',
    option 'inputMode=browse+Qdefault,position=next')

Example 5

TIBCO JMS – Receives a message from the specified end_point:

select msgrecv
     ('tibco_jms:tcp://my_jms_host:7222?queue=queue.sample,'
     +'user=jms_user1,password=jms_user1_password')

Example 6

TIBCO JMS – receives a message from the specified end_point, using the timeout option and specifying a message selector:

declare @mymsg varchar (16384)
select @mymsg = msgrecv('my_jms_provider?queue=queue.sample', 
     option 'timeout=1000' 
     MESSAGE SELECTOR 'correlationID = ''MSG_001''')

Example 7

TIBCO JMS – forwards a message to the specified endpoint:

select msgsend(msgrecv('my_jms_provider?queue=queue.sample'),
     'another_jms_provider?queue=queue2')

Example 8

TIBCO JMS – this msgrecv call only consumes messages from queue.sample when the message property “Name” is equal to “John Smith”:

select msgrecv('my_jms_provider?queue=queue.sample',
     MESSAGE SELECTOR 'Name=''John Smith''')

Example 9

TIBCO JMS – illustrates how to insert a text message into a table:

create table T1(c1 numeric(5,0)identity, m text)
insert into T1 
select msgrecv('my_jms_provider?queue=queue.sample',
     RETURNS text)

Example 10

TIBCO JMS – this example reads a message and returns it as a varbinary.

select msgrecv('my_jms_provider?queue=queue.sample'
     returns varbinary(500))

Usage


MQSeries

These are valid only if the provider class is “ibm_mq”:


Quoting property or option values


Message filters

Permissions

You must have messaging_role to run msgrecv.





Copyright © 2005. Sybase Inc. All rights reserved. msgsend

View this book as PDF