Service Broker simple example

Source: Internet
Author: User

-- Select name, database_id, service_broker_guid, is_broker_enabled from sys. databases;

-- 1 one process messages table for storing sending message action
-- Create table imessages (Id uniqueidentifier not null, messagebody nvarchar (200), service_name nvarchar (200 ));

-- 2 create one message type that can be used by any conversation particle ant
-- Create message type iMessage validation = none;

-- 3. create a contract in which the imessage message type can be sent by any participant
-- Create contract iContract (iMessage sent by any );

-- 4 create a target queue targetQueue for target service

-- Create queue targetQueue with status = on, retention = on [default];

-- 5. create a source queue sourcequeue for source service

-- Create queue sourcequeue with status = on, retention = on [default];

-- 6. create an initiator serivce for sending messages
-- Create service sendingmessage on queue sourcequeue (iContract );

-- 7. create a target service for processing ing message

-- Create service receivingmessage on queue targetqueue (iContract );

-- 8 sending message
Declare @ dialog_handle uniqueidentifier;
Begin dialog conversation @ dialog_handle
From service sendingmessage
To service 'receivingmessage'
On contract iContract
With encryption = off;


Send on conversation @ dialog_handle message type iMessage ('Hello world! ');
End conversation @ dialog_handle;

Go

Select * from targetqueue;
Go
Select * from sourcequeue;
Go
Declare @ ch uniqueidentifier, @ service_name nvarchar (200 );
Receive top (1) @ ch = conversation_handle, @ service_name = service_name from targetqueue;
Print 'conversation handle: '+ cast (@ ch as nvarchar (max ));
Print 'service Name: '+ cast (@ service_name as nvarchar (max ));
End conversation @ ch
Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.