Microsoft Queuing Frameworks: SQL Service Broker vs. MSMQ

Microsoft Queuing Frameworks: SQL Service Broker vs. MSMQ

icrosoft offers two queuing frameworks to its ‘brand’ of developers: MSMQ and SQL Service Broker. These two frameworks offer many of the same features, but differ in some important areas that might affect which you choose for your queuing project. MSMQ is a time-tested technology, while SQL Service Broker is new to most developers. This article outlines some of the differences and may help you to make an informed choice when selecting a queuing technology.

Queuing frameworks are still among the most underutilized frameworks for building enterprise applications. Used properly, they can improve user interface interaction by making long-running resource requests asynchronous, distribute workloads across several servers or services, provide disconnected applications with asynchronous connectivity, enable loose coupling between clients and servers?and the list goes on. The real benefit to developers is that the majority of the heavy lifting to provide these services has already been written by Microsoft. You don’t need to author data schemas and stored procedures to manage hand-built queues using SQL Server. There are other queuing services available to Windows developers, such as IBM’s MQ Series and BEA’s MessageQ, but MSMQ and Service Broker are the two most likely candidates for developers who use Microsoft tools. The cost of MSMQ, the ubiquity of SQL Server availability to Microsoft developers, and the wide range of Windows client platforms supported by both make MSMQ and SQL Service Broker easy choices.

Microsoft originally provided MSMQ in the Windows NT4 Option Pack, and has since published multiple revisions. DevX has published several articles detailing MSMQ’s features and programming model?see the Related References section in the left column of this article for links. MSMQ is included free of charge with all versions of Windows Server (after Windows NT 4 with the Option Pack), Windows 2000 Professional, and Windows XP. MSMQ provides API, COM, and .NET interfaces for sending and receiving messages and for managing queues.

With the release of SQL Server 2005, Microsoft also offers Service Broker as an alternative to MSMQ. Because it’s tied closely to the database platform, Service Broker can be more efficient for data-intensive queuing operations; however, unlike MSMQ, you must obtain a license for SQL Server to use Service Broker. Service Broker functionality is available in any language you use to access data from SQL Server. Also, most queuing operations in SQL Service Broker are performed using extensions to T-SQL.

Given the popularity of both MSMQ and Service Broker and the lack of comparisons between the two tools is surprising. This article fills that void.

Viewing the two tools strictly from a high-level perspective, they seem very similar; both provide reliable first-in/first-out prioritized queuing, asynchronous message processing, and are accessible from a wide variety of languages. However, their differences will likely make one or the other a better choice for your development project.

Table 1 provides a brief comparison between SQL Service Broker and MSMQ. The list is not comprehensive, but provides some of the most important differences between the two. The main criterion for inclusion was to identify features or issues that would help in selecting one technology over the other.

Table 1. Feature Comparison: These features and issues help can you decide which technology, MSMQ or SQL Service Broker, is most compatible with your particular project or environment.
Feature/Issue MSMQ SQL Service Broker
Cost Free with all business versions of Windows Requires SQL Server 2005 license
Highest Performance Higher performance possible Lower performance when standard messaging functions are not necessary
Transaction Performance Relatively expensive transactions using the Distributed Transaction Coordinator Efficient transactions using SQL Server’s internal transactions
Code Location Queuing code cannot run in SQL Server Message processing logic can run in SQL Server
Type Enforcement Type enforcement provided via message types and contracts No type enforcement
Disconnected Queuing Support for fully disconnected mode Requires connection to SQL Server (at least SQL Server Express Edition) to send messages
Backup Non-trivial backup Backup via standard SQL Server backup procedures

While the table provides a convenient, if brief, overview, in the rest of this article, I’ll expand on each of the features and issues shown.

Cost
To operate MSMQ, you must be running Windows NT 4 (with the Option Pack installed), any version of Windows 2000, Windows XP, or Windows Server 2003. With such broad support for operating system platforms, MSMQ gives you the best option if you are looking to run on ‘legacy’ platforms. Arguably, SQL Service Broker clients can also run on nearly any of those platforms because a SQL Service Broker client requires only that it can connect to SQL Server 2005. However, many applications will be considerably easier to purchase and deploy without the additional requirement of a SQL Server 2005 instance to host the queuing components.

One common problem observed in small businesses is an overburdened database server. Perhaps the availability of database resources should not be a concern when choosing a queuing platform, but if your database is already overloaded, the only options are to either upgrade or expand the database platform, or use a different queuing technology. In some cases, the cost of adding an additional database platform could prove too costly to consider.

Highest Performance
As a component of the database platform, the reliability of the messaging services provided by SQL Service Broker is unrivaled by MSMQ. Even if you decide to use transactional messaging with MSMQ, you incur the burdensome overhead of using the DTC to manage the transactions. However, if your application is fault tolerant (meaning it is acceptable to lose an occasional message) then MSMQ might provide a better option. It is capable of providing better message throughput by allowing the developer/administrator to turn off security and message loss protection. This is especially true when the sending and receiving applications are not data-driven applications. MSMQ provides finer granularity of control that can be useful when messaging performance is the priority.

Obviously, intentionally removing the security built into any application is not advisable. Further, I can conceive of only a handful of applications where message loss could be tolerated. Nonetheless, MSMQ gives the developer those options for cases where they may be useful.

Transaction Performance
In many instances, queuing applications are inherently data-driven applications. The message processing service could be looking up data from a data warehouse, adding items to an order, etc. In these cases, the queuing application using SQL Service Broker will likely realize a tremendous benefit over the same application built using MSMQ because SQL Service Broker takes advantage of transaction contexts managed internally by SQL Server, while MSMQ must rely on the Distributed Transaction Coordinator (DTC) to coordinate transaction contexts between MSMQ and SQL Server. Especially when MSMQ and the database run on separate servers, the overhead of using the DTC can become prohibitive.

In most cases, when the queuing application supports a database-driven application, SQL Service Broker is the clear choice.

Code Location
Both MSMQ and SQL Service Broker provide a great deal of flexibility in authoring queuing applications. Developers may author queuing applications using any popular language. However, one huge benefit of using SQL Service Broker is that you can write senders and receivers using T-SQL hosted by SQL Server?SQL Service Broker provides the capability of automatically activating stored procedures to process messages. MSMQ would require an external application to receive and process the messages. For data-driven applications, therefore, using SQL Service Broker provides a significant benefit.

Type Enforcement
SQL Service Broker offers a critical advantage over MSMQ by enforcing the content of messages using SQL Service Broker’s Message Types (named data types that optionally can be validated with XML schemas) and Contracts (enforcement of which Message Types are sent by which senders). MSMQ does not provide services to enforce the types of messages being deposited into queues.

Disconnected Queuing
Both MSMQ and SQL Service Broker provide a way to send messages when the receiving queue is not available. MSMQ requires a local instance of MSMQ, and SQL Service Broker requires a connection to (at minimum) SQL Server Express to accept the messages. Because both MSMQ and SQL Server Express are free, the differentiating question for most scenarios is whether the deployment and configuration of SQL Server Express is worth the effort. A massive deployment of SQL Server Express, along with the requisite configuration to enable queuing for your application could be a substantial investment. MSMQ can generally handle disconnected message with no additional local configuration.

If your application requires the senders to send messages during times when the target queue may be unavailable (think about mobile applications), this will be a consideration for your application.

All in all, MSMQ is probably a simpler choice when designing solutions for disconnected applications.

Backup
On average, backing up a SQL Service Broker queue is a more natural process for most development groups than backing up MSMQ message stores. I hope that any company that depends heavily on SQL Server has the SQL Server backup process finely tuned. Because SQL Service Broker queues are database structures, they are backed up during normal database backup processes. Further, they gain all the benefits of incremental and differential backup and restore processes provided by SQL Server.

By contrast, when MSMQ is optimized for the fastest possible messaging, it is possible that messages exist only in memory?they do not even survive restarts of the MSMQ service. Backing up persistent MSMQ messages is easier, but it has been shown to be dangerous to attempt to restore messages to an operating instance of MSMQ. In almost all circumstances, backing up messages from a SQL Service Broker queue is an easier process.

Other Factors
In this article, I have tried to highlight only what I consider to be some of the most likely factors to consider when making the choice between MSMQ and SQL Service Broker. It’s likely that you will consider factors other than those mentioned here. In general, if you have database-driven applications in an environment where a SQL Server 2005 instance is already available, you should seriously consider using SQL Service Broker. But you should consider MSMQ when both the sender and receiver applications are external to the database server and when the required deployment of SQL Server 2005 is not a feasible option.

Finally, because SQL Service Broker has a wide range of supported features that I could not cover in this article, I suspect that SQL Service Broker will slowly overtake MSMQ as the dominant queuing technology used by MS developers. This migration will only accelerate as SQL Server 2005 adoption progresses, causing the cost barrier to fall. If you are interested in developing applications using SQL Service Broker, the most complete source of information is Roger Wolter’s book “The Rational Guide to SQL Server 2005 Service Broker.”

devx-admin

devx-admin

Share the Post:
Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India,

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with

Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in and explore the leaders in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India, and kickstart your journey to

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner for your online project. Your

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the state. A Senate committee meeting

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor supply chain and enhance its

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with minimal coding. These platforms not

Cybersecurity Strategy

Five Powerful Strategies to Bolster Your Cybersecurity

In today’s increasingly digital landscape, businesses of all sizes must prioritize cyber security measures to defend against potential dangers. Cyber security professionals suggest five simple technological strategies to help companies

Global Layoffs

Tech Layoffs Are Getting Worse Globally

Since the start of 2023, the global technology sector has experienced a significant rise in layoffs, with over 236,000 workers being let go by 1,019 tech firms, as per data

Huawei Electric Dazzle

Huawei Dazzles with Electric Vehicles and Wireless Earbuds

During a prominent unveiling event, Huawei, the Chinese telecommunications powerhouse, kept quiet about its enigmatic new 5G phone and alleged cutting-edge chip development. Instead, Huawei astounded the audience by presenting

Cybersecurity Banking Revolution

Digital Banking Needs Cybersecurity

The banking, financial, and insurance (BFSI) sectors are pioneers in digital transformation, using web applications and application programming interfaces (APIs) to provide seamless services to customers around the world. Rising

FinTech Leadership

Terry Clune’s Fintech Empire

Over the past 30 years, Terry Clune has built a remarkable business empire, with CluneTech at the helm. The CEO and Founder has successfully created eight fintech firms, attracting renowned

The Role Of AI Within A Web Design Agency?

In the digital age, the role of Artificial Intelligence (AI) in web design is rapidly evolving, transitioning from a futuristic concept to practical tools used in design, coding, content writing

Generative AI Revolution

Is Generative AI the Next Internet?

The increasing demand for Generative AI models has led to a surge in its adoption across diverse sectors, with healthcare, automotive, and financial services being among the top beneficiaries. These

Microsoft Laptop

The New Surface Laptop Studio 2 Is Nuts

The Surface Laptop Studio 2 is a dynamic and robust all-in-one laptop designed for creators and professionals alike. It features a 14.4″ touchscreen and a cutting-edge design that is over

5G Innovations

GPU-Accelerated 5G in Japan

NTT DOCOMO, a global telecommunications giant, is set to break new ground in the industry as it prepares to launch a GPU-accelerated 5G network in Japan. This innovative approach will

AI Ethics

AI Journalism: Balancing Integrity and Innovation

An op-ed, produced using Microsoft’s Bing Chat AI software, recently appeared in the St. Louis Post-Dispatch, discussing the potential concerns surrounding the employment of artificial intelligence (AI) in journalism. These

Savings Extravaganza

Big Deal Days Extravaganza

The highly awaited Big Deal Days event for October 2023 is nearly here, scheduled for the 10th and 11th. Similar to the previous year, this autumn sale has already created

Cisco Splunk Deal

Cisco Splunk Deal Sparks Tech Acquisition Frenzy

Cisco’s recent massive purchase of Splunk, an AI-powered cybersecurity firm, for $28 billion signals a potential boost in tech deals after a year of subdued mergers and acquisitions in the

Iran Drone Expansion

Iran’s Jet-Propelled Drone Reshapes Power Balance

Iran has recently unveiled a jet-propelled variant of its Shahed series drone, marking a significant advancement in the nation’s drone technology. The new drone is poised to reshape the regional

Solar Geoengineering

Did the Overshoot Commission Shoot Down Geoengineering?

The Overshoot Commission has recently released a comprehensive report that discusses the controversial topic of Solar Geoengineering, also known as Solar Radiation Modification (SRM). The Commission’s primary objective is to

Remote Learning

Revolutionizing Remote Learning for Success

School districts are preparing to reveal a substantial technological upgrade designed to significantly improve remote learning experiences for both educators and students amid the ongoing pandemic. This major investment, which

Revolutionary SABERS Transforming

SABERS Batteries Transforming Industries

Scientists John Connell and Yi Lin from NASA’s Solid-state Architecture Batteries for Enhanced Rechargeability and Safety (SABERS) project are working on experimental solid-state battery packs that could dramatically change the

Build a Website

How Much Does It Cost to Build a Website?

Are you wondering how much it costs to build a website? The approximated cost is based on several factors, including which add-ons and platforms you choose. For example, a self-hosted

Battery Investments

Battery Startups Attract Billion-Dollar Investments

In recent times, battery startups have experienced a significant boost in investments, with three businesses obtaining over $1 billion in funding within the last month. French company Verkor amassed $2.1