| By Jerry Dixon | Article Rating: |
|
| November 17, 2006 02:00 PM EST | Reads: |
28,962 |
The second procedure accepts a message from the request queue and halts processing for the indicated amount of time. First, the message is retrieved from the request queue. The RECEIVE statement is used for this. (Note that the semi-colon before the RETRIEVE is required unless the RECEIVE statement is the first statement in the batch.) The conversation handle, message body, and message type are retrieved from the queue and stored in variables for later processing. (Note that the message body is stored in an XML variable. This will be useful in a moment.) If a message was retrieved (@@ROWCOUNT > 0) then the delay parameter is obtained from the message document via a call to the VALUE method of the message body variable. The procedure then executes a WAITFOR statement using the provided delay parameter value. Next, the procedure sends a message to the response queue. In this example, the message data is identical to that received above. In practice, this would probably be different. Finally, because the request side of the conversation has completed its work, the END CONVERSATION statement is used. This statement informs Service Broker that this side of the conversation will send no more messages for this request.
The last stored procedure is very similar to the second. It obtains a message from the response queue and retrieves a delay value from this message. The WAITFOR statement is then used to execute a pause for the desired length. Finally, the END CONVERSATION statement is used to inform Service Broker that this side of the conversation is complete. Since both sides are now complete, the conversation ends.
Service Program Activation
At this point, the
system would work perfectly well, but each stored procedure would have
to be executed manually. This is usually not desirable. Instead,
Service Broker provides a method for automatic procedure activation.
Refer to listing 5. (Insert Listing 5) Here we see statements similar
to those used to create our queues earlier. This time, however, the
statements include an ACTIVATION clause. This clause specifies the name
of a Service Program (a stored procedure) which should be executed
whenever a message arrives at the queue. The MAX_QUEUE_READERS clause
indicates the maximum number of separate instances of the stored
procedure that can be executed simultaneously. Similarly, the
MIN_QUEUE_READERS clause indicates the minimum number that can be used.
(Use this setting with caution, as too large a value can hinder
performance.) The EXECUTE AS clause specifies the user account under
which the stored procedure should be run.
Summary
This small example demonstrates how Server
Broker can be used to implement an asynchronous database process. It
shows how messages can be sent back and forth between different queues,
and how stored procedures can automatically be executed on an as-needed
basis. Keep in mind that Service Broker is designed to be highly
scalable, and can handle systems with many more queues, messages, and
stored procedures than used here. In addition, X.509 certificates can
be used to secure message data and to authenticate participating
servers. Service Broker is a serious tool, and it deserves your
consideration when you are designing your next system.
Published November 17, 2006 Reads 28,962
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Jerry Dixon
Jerry Dixon is a senior developer and architect for ACH Food Companies in Memphis, Tennessee. Over the past 16 years he has led development projects for a number of enterprise, mid-level, and small business organizations. While he has fulfilled multiple roles as an infrastructure designer, database administrator, and software developer, he specializes in XML, SQL and ASP.NET. He is a co-leader and frequent presenter at the Memphis .NET User Group. Jerry holds the following Microsoft certifications: MCSD (VB 6.0 and .NET), MCDBA (SQL 2000), MCSA (Windows 2000 and 2003), MCSE (Windows 2000), MCAD (.NET), MCT. He resides in Olive Branch, MS with his wife and son.
![]() |
.NET News Desk 11/17/06 02:39:12 PM EST | |||
In today's complex and demanding environments, it is quite common for users to be able to submit requests faster than those requests can be processed. In some situations, this is because the system has an enormous number of users. In other situations, it is because the requests take a long time to process. In both cases, the system needs to be designed so that it can accept the requests immediately, and process those requests later on. Such a system is said to be asynchronous. |
||||
- Kindle 2 vs Nook
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Windows 7 – Microsoft’s First Step to the Cloud
- Cloud Expo and the End of Tech Recession
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Reality Check at the Cloud Computing Expo
- Visual Studio 2010 Is Cloud Friendly
- Fired SCO CEO Fires Back
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- Wave on Ulitzer: Confessions of a Google Wave Fanboy
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Best Practices
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Eval JavaScript in a Global Context
- Windows 7 – Microsoft’s First Step to the Cloud
- Google Maps and ASP.NET
- Crystal Reports XI & How It Has Changed
- Converting VB6 to VB.NET, Part I
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- How to Write High-Performance C# Code
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Implementing Tab Navigation with ASP.NET 2.0
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Viewpoint: "SOA Sucks"
- Programmatically Posting Data to ASP .NET Web Applications


























