Commit 04f022f0 authored by dwentzel's avatar dwentzel

added SBDemystifiedSeries folder and entries

parent c254431b
Service Broker Demystified Series
====================================
This folder contains the source code for my [Service Broker Demystified blog series](http://www.davewentzel.com/taxonomy/term/343).
`contracts.sql` covers why contracts are not alterable
/*
This is the source code for http://www.davewentzel.com/content/service-broker-demystified-why-there-no-alter-contract-statement.
You can't alter a contract in Service Broker. Instead you need some sort of versioning mechanism for your contracts,
or you need to DROP/CREATE them whenever changes are needed.
*/
--basic setup
CREATE DATABASE SBTest
GO
ALTER DATABASE SBTest SET NEW_BROKER
GO
USE SBTest
GO
/*
You can't have a contract without a message type, but a contract may have multiple message types.
Let's build 4 message types to model a rudimentary asynchronous inventory system. Hopefully the object
names will be sufficient to understand the workflow.
Initially the workflow's intention was to have either the inventory requestor or the inventory manager
be able to cancel an inventory request. But let's say you decide later that only the sender can cancel
an inventory request...the inventory manager can never cancel a request, rather it can only delay it. In
this case you must drop and recreate the CONTRACT...you can't alter it.
Since there may be a lot of moving parts and different systems with different release schedules you really
should never alter a CONTRACT anyway. Instead you should consider versioning your contracts and then the
disparate systems in the design can call the new versions of the CONTRACTs (and probably services too) when
they finally release their modified code.
*/
CREATE MESSAGE TYPE RequestInventoryItem VALIDATION = WELL_FORMED_XML;
CREATE MESSAGE TYPE AvailabilityOfInventoryItemRequested VALIDATION = WELL_FORMED_XML;
CREATE MESSAGE TYPE InventoryItemFulfilled VALIDATION = WELL_FORMED_XML;
CREATE MESSAGE TYPE CancelInventoryItemRequest VALIDATION = WELL_FORMED_XML;
CREATE CONTRACT InventoryRequestWorkflow
(
RequestInventoryItem SENT BY INITIATOR,
AvailabilityOfInventoryItemRequested SENT BY TARGET,
InventoryItemFulfilled SENT BY TARGET,
CancelInventoryItemRequest SENT BY ANY
);
--this would fail
--ALTER CONTRACT InventoryRequestWorkflow
--instead, minimally we need to DROP CONTRACT and recreate it with the new requirements
--it would be better to version the names of the objects to aid in future feature changes
DROP CONTRACT InventoryRequestWorkflow;
CREATE CONTRACT InventoryRequestWorkflow
(
RequestInventoryItem SENT BY INITIATOR,
AvailabilityOfInventoryItemRequested SENT BY TARGET,
InventoryItemFulfilled SENT BY TARGET,
CancelInventoryItemRequest SENT BY INITIATOR
);
--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