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.

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-7.

option_string

is the general format of the option_string is specified in option_string. The options for msgrecv are described in Table 4-7.

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

Receives a message from the specified end_point:

select msgrecv
     ('tibco_jms:tcp://my_ems_host:7222?queue=queue.sample,'
     +'user=ems_user1,password=ems_user1_password')

Example 2

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_ems_provider?queue=queue.sample', 
     option 'timeout=1000' 
     MESSAGE SELECTOR 'correlationID = ''MSG_001''')

Example 3

Forwards a message to the specified endpoint:

select msgsend(msgrecv('my_ems_provider?queue=queue.sample'),
     'another_ems_provider?queue=queue2')

Example 4

Calls only consumes messages from queue.sample when the message property “Name” is equal to “John Smith”:

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

Example 5

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_ems_provider?queue=queue.sample',
     RETURNS text)

Example 6

Reads a message and returns it as a varbinary.

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

Usage


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