Commit 4f710b24 authored by dwentzel's avatar dwentzel

added code for [DEFAULT] contracts

parent cc0b3da4
......@@ -8,7 +8,7 @@ This folder contains the source code for my [Service Broker Demystified blog ser
`contracts_and_message_types.sql` covers why contracts and message types are optional, yet really important.
`default_contract.sql` covers why [DEFAULT] contract is not the default contract for a service
`default_contract.sql` and `default_contract2.sql` covers why [DEFAULT] contract is not the default contract for a service
`encryption_errors.sql` and `encryption_errors2.sql` cover goofiness with encryption and how to work around it.
......
/*
This is the source code for http://www.davewentzel.com/content/service-broker-demystified-default-not-default.
This demonstrates that by default the [DEFAULT] SB objects are not used.
*/
--first, note that there are actual SSB objects named DEFAULT that ship by MS
--available in every db
--SELECT * FROM sys.service_message_types
--SELECT * FROM sys.service_contracts
--basic setup
CREATE DATABASE SBTest
GO
ALTER DATABASE SBTest SET NEW_BROKER
GO
USE SBTest
GO
/*
Let's build an EmployeeSvc and AccountingSvc. The goal is for the EmployeeSvc to submit an
ExpenseReport to the AccountingSvc.
Here is the most basic configuration
*/
CREATE QUEUE AccountingQ;
CREATE SERVICE AccountingSvc ON QUEUE AccountingQ;
CREATE QUEUE EmployeeQ;
CREATE SERVICE EmployeeSvc ON QUEUE EmployeeQ;
--submit a rudimentary expense report
BEGIN TRANSACTION
DECLARE @h UNIQUEIDENTIFIER;
BEGIN DIALOG @h
FROM SERVICE [EmployeeSvc]
TO SERVICE 'AccountingSvc', 'CURRENT DATABASE'
WITH ENCRYPTION = OFF
;
SEND ON CONVERSATION @h;
COMMIT;
select message_type_name, convert(xml,message_body), service_contract_name, validation from EmployeeQ
select message_type_name, convert(xml,message_body), service_contract_name, validation from AccountingQ
select message_type_name, to_service_name, from_service_name,
service_contract_name, transmission_status from sys.transmission_queue
--note that our message is stuck in the sending Q because we have not specified a contract.
--hence AccountingSvc is a "send only) service.
--basic cleanup
USE master;
GO
DROP DATABASE SBTest;
GO
/*
This is the source code for http://www.davewentzel.com/content/service-broker-demystified-default-not-default.
This demonstrates what is required to create a receive Service/Queue with validation = NONE
*/
--basic setup
CREATE DATABASE SBTest
GO
ALTER DATABASE SBTest SET NEW_BROKER
GO
USE SBTest
GO
/*
Let's build an EmployeeSvc and AccountingSvc. The goal is for the EmployeeSvc to submit an
ExpenseReport to the AccountingSvc.
Here is the most basic configuration...that works.
*/
CREATE QUEUE AccountingQ;
--here we add the DEFAULT contract to AccountingSvc which allows it to receive messages.
CREATE SERVICE AccountingSvc ON QUEUE AccountingQ ([DEFAULT]);
CREATE QUEUE EmployeeQ;
CREATE SERVICE EmployeeSvc ON QUEUE EmployeeQ;
--submit a rudimentary expense report
BEGIN TRANSACTION
DECLARE @h UNIQUEIDENTIFIER;
BEGIN DIALOG @h
FROM SERVICE [EmployeeSvc]
TO SERVICE 'AccountingSvc', 'CURRENT DATABASE'
WITH ENCRYPTION = OFF
;
SEND ON CONVERSATION @h; --no payload
COMMIT;
select * from AccountingQ
select message_type_name, to_service_name, from_service_name,
service_contract_name, transmission_status from sys.transmission_queue
--note that although this works the [DEFAULT] contract provides NO VALIDATION.
--so we can send just about anything to AccountingSvc
BEGIN TRANSACTION
DECLARE @h1 UNIQUEIDENTIFIER;
BEGIN DIALOG @h1
FROM SERVICE [EmployeeSvc]
TO SERVICE 'AccountingSvc', 'CURRENT DATABASE'
WITH ENCRYPTION = OFF
;
SEND ON CONVERSATION @h1 ('This is my expense report'); --a random payload
COMMIT;
select convert(xml,message_body) AS message_body from AccountingQ
select message_type_name, to_service_name, from_service_name,
service_contract_name, transmission_status from sys.transmission_queue
--basic cleanup
USE master;
GO
DROP DATABASE SBTest;
GO
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment