These examples provide a brief preview of the Transact-SQL messaging interface.
Example 1 JMS – sends a message to a queue:
select msgsend('hello world', ('eas_jms:iiop://my_eas:7222?queue=queue.sample' message property 'city=Detroit')
Example 2 JMS – reads a message from a queue, with and without a filter:
select msgrecv('tibco_jms:tcp://my_jms_host:7222?queue=queue.sample') select msgrecv ('eas_jms:iiop://my_eas:7222?queue=queue.sample' message selector 'city=''Detroit''')
Example 3 JMS – publishes a message to a topic:
sp_msgadmin register, subscription,sub1, 'eas_jms:iiop://my_eas:7222?queue=queue.sample' select msgpublish ('hello world', 'sub1' message property 'city=Boston')
Example 4 JMS – consumes a message from a topic:
select msgconsume('sub1')
Example 5 JMS – illustrates working with properties:
select msgconsume('sub1') declare @pcount integer declare @curr integer declare @pname varchar(100) select @curr=1 select @pcount = msgpropcount() while(@curr<=@pcount) begin select @pname=msgpropname(@curr) select msgproptype(@pname) select msgpropvalue(@pname) select @curr=@curr+1 end
Example 6 MQ – sends a message to a queue:
select msgsend('hello world', 'ibm_mq:channel1/tcp/host1(1234)?qmgr=QM,queue=DEFAULT.QUEUE' message header 'priority=2')
Example 7 MQ – reads a message from a queue:
select msgrecv( 'ibm_mq:channel1/tcp/host1(1234)?qmgr=QM,queue=DEFAULT.QUEUE' option 'timeout=30ss')
Example 8 MQ – registers a publisher and publishes a message about “fish”:
select msgsend(NULL, 'ibm_mq:channel1/tcp/host1(1234)?qmgr=QM,queue=SYSTEM.BROKER.CONTROL.QUEUE’' option 'rfhCommand=registerPublisher' message header 'topics=fish' + ',streamName=ANIMALS.STREAM') select msgsend('something about a fish', 'ibm_mq:channel1/tcp/host1(1234)?qmgr=QM,queue=ANIMALS.STREAM' message header 'topics=fish')
Example 9 MQ – registers a subscriber, reads a message, and processes the message properties:
select msgsend(NULL, 'ibm_mq:channel1/tcp/host1(1234)?qmgr=QM,queue=SYSTEM.BROKER.CONTROL.QUEUE' option 'rfhCommand=registerSubscriber' + ',topics=fish' + ',streamName=ANIMALS.STREAM' + ',queueName=MY_ANIMALS.QUEUE') select msgrecv( 'ibm_mq:channel1/tcp/host1(1234)?qmgr=QM,queue=MY_ANIMALS.QUEUE' option 'timeout=30ss') select msgpropvalue('MPQScompcode', @@msgproperties)