msgpublish  msgpropvalue

Chapter 5: Real Time Data Functions

msgconsume

Description

Provides a SQL interface to consume messages that are published to different topics.

Syntax

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

Parameters

subscription_name

Name of the subscription from which you are consuming messages.

option_string

The general format of the option_string is specified in option_string—general format. The special options to use when consuming a message are described in Table 5-7.

returns

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

basic_character_expression

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

option_string

is one of the following:

Table 5-7: msgconsume option values

Option

Values

Default

Values

timeout

-1, 0 – (231– 1)

-1

By default, msgconsume is a blocking command, which blocks the message until it reads the next message from the message bus. If timeout is not -1, msgconsume returns null when the timeout interval lapses without reading a message.The values are in number 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 provideras msgconsume and msgrecv.

SQL_type

The datatypes used in SQL statements.

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’

Example 2

Before consuming messages from a subscription, a client must first subscribe to the subscription:

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

Example 3

Declares variables and receives a message from the specified subscription:

declare @mymsg varchar (16384)	
select @mymsg = msgconsume(’subscription_1’, 
     OPTION ’timeout=0’)

Example 4

Forwards a message:

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

Example 5

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

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

Usage





Copyright © 2004. Sybase Inc. All rights reserved. msgpropvalue

View this book as PDF