msgconsume

Description

EAServer JMS only – provides a SQL interface to consume messages that are published to different topics.

Syntax

msgconsume_call ::=
	msgconsume (subscription_name, option_and_returns)
		subscription_name:= basic_character_expression
		option_and_returns ::= [option_clause] [returns_clause]
			option_clause::= [,] option option_string
			returns_clause ::= [,] returns sql_type
				subscriber_name ::= basic_character_expression
				sql_type ::= 
					varchar(integer) | java.lang.String | text)
					| varbinary(integer) | image

Parameters

basic_character_expression

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

option_string

is the general format of option_string as specified in option_string. The special options to use when consuming a message are described in Table 3-6:

Table 3-6: option and option_string values for msgconsume

option values

option_string values

Default

Description

timeout

timespec between -1, 0 – (231– 1)

-1

By default, msgconsume blocks the message until it reads the next message from the message bus. If timeout is not -1, msgconsume returns a null value when the timeout interval lapses without reading a message.Values are in number of milliseconds.

timeout uses the timespec option. See timespec.

requeue

string

None

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

subscription_name

is the name of the subscription from which you are consuming messages.

returns

specifies the clause that you want returned.

SQL_type

is the datatype used in SQL statements.

If you do not specify a datatype to be returned, the default is varchar(16384). The legal SQL datatypes are:

  • varchar(n)

  • text

  • java.lang.String

  • varbinary(n)

  • image

  • univarchar(n)

Examples

Example 1

Defines a subscription on the client server, before consuming a message:

sp_msgadmin 'register', 'subscription', 'subscription_1',
     'my_jms_provider?topic=topic.sample,user=user1,password=pwd',
     'Supplier=12345',null,'durable1', 'client1'

Before consuming messages from a subscription, Sybase recommends that the subscription be subscribed:

select msgsubscribe('subscription_1')
declare @mymsg varchar(16384)
select @mymsg = msgconsume('subscription_1')

Example 2

Declares variables and receives a message from the specified subscription:

declare @mymsg varchar (16384)	
select @mymsg = msgconsume('subscription_1', 
     option 'timeout=0')

Forwards a message:

select msgsend
     (msgconsume('subscription_1'), 'my_jms_provider?queue=queue.sample')

Reads a message and returns it as a varbinary:

select msgconsume('subscription_1' returns varbinary(500))

Usage

Permissions

You must have messaging_role to run msgconsume.