msgsend  msgsubscribe and msgunsubscribe

Chapter 5: Real Time Data Functions

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 

Parameters

end_point

A basic_character_expression whose runtime value is a service_provider_uri. The destination of a message.

option_string

The general format of the option_string is specified in option_string—general format. The options for msgrecv are described in Table 5-3.

filter_clause

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

message_filter

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.

basic_character_expression

A SQL query expression whose datatype is char, varchar, or java.lang.String.

returns_clause

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:

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. msgrecv option values are shown in Table 5-3.

Table 5-3: msgrecv option values

Option

Values

Default

Comment

timeout

-1, 0 - (231- 1)

-1

By default, msgrecv is a blocking command, which blocks the message until it reads the next message from the message bus. If timeout is not -1, msgrecv returns null when the timeout interval lapses without reading a message. The values are in numbers of milliseconds.

requeue

String

None

The name of a destination, queue, or topic on which to requeue messages that Adaptive Server cannot process. If requeue is not specified, and the message cannot be processed, an error message appears.The endpoint specified must be on the same messaging provider as msgconsume and msgrecv.

Examples

Example 1

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 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_jms_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_jms_provider?queue=queue.sample’),
     ’another_jms_provider?queue=queue2’)

Example 4

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

Example 6

This example reads a message and returns it as a varbinary.

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

Usage





Copyright © 2004. Sybase Inc. All rights reserved. msgsubscribe and msgunsubscribe

View this book as PDF