Skip to main content

Service Bus: Messaging as a service on Azure

Your messaging application will need to interact with other applications and services to deliver and exchange information. Microsoft Azure allows us to send and receive messages through a simple queue. If an ordinary queue isn’t enough, a queue with a publish and subscribe mechanism could solve the problem. Otherwise, some applications on Azure need a connection between applications and queues. To perform such tasks, the platform offers the Azure Service Bus. Service Bus is a reliable Cloud Messaging as a Service on Azure (MaaS) application that supports hybrid integration in a simple way.
In this post, we’ll walk you through the features of Service Bus and how you can use it.

What is Azure Service Bus?

Azure Service Bus is a collection of services that allow us to manage communication between our different application components.

Service Bus is a multi-tenant cloud service. As mentioned in Marco Parenzan’s post Creating multi-tenant applications in Microsoft Azure, multi-tenancy is one of the founding principles of cloud computing. When we said that Service Bus is multi-tenant, this means that the service is shared by multiple users for connecting applications through the cloud.

General overview

Service Bus is made up of four communication services. You can create one or more instances of each service to connect to our applications. These services include:
Queues: Queues act as an intermediary layer between application components and they store messages that other application components can receive.
Topics: A one-directional communication mechanism that allows client applications or devices to subscribe to a topic. A separate application or device can publish messages to topics for consumption by the client applications.
Relays: Relays are a bidirectional proxy for communication with a Windows Communication Foundation (WCF) service. Client applications can bind directly to the relay endpoint and the relay infrastructure routes messages to the appropriate WCF service endpoint.
Notification Hubs: A managed, brokered system for distributing messages from server applications to client devices across various platforms using local notifications.
This is how Service Bus works in the cloud:
Azure Service Bus

What are namespaces?

Namespaces serve as a basic logical grouping of Service Bus service instances. An application developer would first use Service Bus to create a namespace, and then define the communication mechanisms he or she needs within that namespace. On Azure, what you call the namespace is globally unique. When you create a queue, topic, or relay in a namespace, the name is then combined with the namespace to create a unique identifier for the object. Applications can provide this name to Service Bus, and then use that queue, topic, or relay to communicate with one another. Service Bus namespaces can also contain management credentials or shared keys, that client applications can use to connect to Service Bus.

What are Storage Queues?

Storage queues provide a consistent and reliable way to store messages that can be consumed by any number of workers. It provides multi-messaging between the role instances as well as build for massive scale and multiple messages. Common scenarios for using storage queues include:
• Creating a backlog of work to process asynchronously
• Passing messages from an Azure web role to an Azure worker role

Differences between storage queues and Service Bus queues

In my previous post, Getting started with Azure, I wrote about cloud design patterns implemented by Microsoft Azure to solve queue-based load leveling problems for a service whose peaks in demand cause it to overload and therefore unable to respond to requests in a timely manner. Flooding a service with a large number of concurrent requests can also result in the service failing if it’s unable to handle the contention these requests cause. The solution here is to use a queue. The queue acts as a buffer, storing the message until it’s retrieved by the service. The service retrieves the messages from the queue and processes them.
Microsoft Azure Message queue
Microsoft Azure supports two types of queue mechanisms: Storage queues and Service Bus queues.
Storage queues: As part of the Azure storage infrastructure, storage queues feature a simple REST-based Get/Put/Peek interface, providing reliable, persistent messaging within and between services.
Service Bus queues: Are part of a broader Azure messaging infrastructure that supports queuing as well as publish/subscribe, and more advanced integration patterns.

Service Bus queues guarantee that messages are processed in a FIFO order. Storage queues do not guarantee this. Both of them can guarantee that messages are delivered at least once and Service Bus queues can also guarantee that a message is delivered only once.

Here is an at-a-glance comparison of the capabilities available with storage queues and Service Bus queues.

Comparison criteria Storage queues Service Bus queues
Ordering guarantee No Yes: first in first out (FIFO)
Delivery guarantee At-Least-Once At-Least-Once
At-Most-Once
Transaction support No Yes
Receive mode Peek and Lease Peek and Lock
Receive and Delete
Exclusive access mode Lease-based Lock-based
Lease/Lock granularity Message level Queue level
Batched receive Yes Yes
Batched send No Yes

For more details, please refer to the Azure documentation Storage queues and Service Bus queues – compared and contrasted.

What is a Service Bus Relay?

Service Bus Relay provides a flexible way to connect WCF services and clients without having to redesign the network architecture. The Azure Relay service facilitates hybrid applications by including a relay component that can connect existing services to new client applications without exposing the true location or address of the service which allows you to securely expose services.

Relay supports a variety of different transport protocols and web services standards such as Simple Object Access Protocol (SOAP), Web Services standards (WS*), and Representational State Transfer (REST).

Azure Relay has two features:

  • WCF Relays: Uses Windows Communication Foundation (WCF) to enable remote procedure calls. WCF Relay is the legacy Relay offering that many customers already use with their WCF programming models.
  • Hybrid Connections: Uses the open standard web sockets, enabling multi-platform scenarios.

Hybrid Connections and WCF Relays both enable a secure connection to assets that exist within a corporate enterprise network. For more information, please consult the Relay FAQ in the Azure documentation.

Service Bus Relay Architecture

The Service Bus relay allows you to host WCF services within an existing enterprise environment. We can delegate the task of listening to incoming sessions and requests to the Service Bus service running within Azure. These messages are then routed to the appropriate WCF service. This exposes these services to the application code that is running in Azure, or to mobile workers or extranet partner environments.

Service Bus allows you to securely control who can access these services at a detailed level. It provides a powerful and secure way to expose application functionality and data from existing enterprise solutions and take advantage of it from the cloud.
Microsoft Azure Service Application Send/Receive

What is the Service Bus Notification Hub?

The Service Bus Notification Hub is a combination of service infrastructure and a set of client libraries that publishes push notifications to mobile applications from any application service component.
With Notification Hubs, we can send notifications that are personalized to a specific user, notifications that are distributed to many users across various platforms, and notifications that are filtered to a specific set of users.

The Notification Hubs infrastructure abstracts the implementation of the various Platform Notification Systems (PNS) for each mobile platform. By using a single method call, we can send notifications to various device platforms without having to implement a different message structure or communication mechanism for each platform.

Here are some general scenarios for using the Service Bus Notification Hub:

  • Send breaking news notifications to millions with low latency.
  • Send location-based coupons to interested user segments.
  • Send event-related notifications to users or groups for media/sports/finance/gaming applications.
  • Push promotional content to apps to engage with and market to customers.
  • Notify users of enterprise events such as new messages and work items.
  • Send codes for multi-factor authentication.

Learn more about push notifications for a few popular platforms:

Why use Notification Hubs?

Notification Hubs eliminate the challenges that are involved in managing push notifications. Notification Hubs use a full multi-platform, scaled-out push notification infrastructure and considerably reduce the push-specific code that runs in the app.
Notification Hubs implement all the functionality of a push infrastructure. Devices are only responsible for registering PNS handles, and the backend is responsible for sending platform-independent messages to users or interest groups.

Notification Hubs provide a push infrastructure with the following advantages:
Multiple platforms:

  • Support for all major mobile platforms: Windows, Windows Phone, iOS, and Android.
  • No platform-specific protocols: The application only communicates with Notification Hubs.
  • Device handle management: Notification Hubs maintain the handle registry and feedback from PNSs.

Works with any backend: It works with cloud or on-premises applications written in .NET, PHP, Java, or Node.
Scale: Notification Hubs scale to millions of devices without rearchitecting or sharding.
– Rich set of delivery patterns: Associate devices with tags to represent logical users or interest groups:

  • Broadcast: Allows for near-simultaneous broadcast to millions of devices with a single Application Programming Interface (API) call.
  • Unicast/Multicast: Push to tags representing individual users, including all their devices or a wider group. For example, a user could use the app on separate devices (tablet, phone, etc.) and would require push notifications to either be pushed to all devices or to a specific device.
  • Segmentation: Push to a complex segment that is defined by tag expressions (For example, devices in New York following the Yankees).

Personalization: Each device can have one or more templates to achieve per-device localization and personalization without affecting the backend code.

Notification Hubs architecture

At a high level, all platform notification systems follow the same pattern:
1. The client application contacts the PNS to retrieve its handle. The handle type depends on the system. For Windows Notification Service (WNS), it is a URI or notification channel. For Apple Push Notification Service (APNS), it is a token.
2. The client application stores this handle in the app backend for later usage. For WNS, the backend is typically a cloud service. For APNS, the system is called a provider.
3. To send a push notification, the app backend contacts the PNS by using the handle to target an instance of a specific client application.
4. The PNS forwards the notification to the device specified by the handle.

Typical PNS infrastructure

With Notification Hubs, we can rely on the service infrastructure to handle the most complex features and have the application focus only on sending messages. Notification Hubs implement all of the functionality of a push infrastructure. It can be used in flexible ways to register devices and eventually to send a message to the device. Devices can register themselves and receive notifications using the following method:
1. The client device reaches out to the PNS by using the Notification Hubs SDK. It registers a unique PNS handle that is used by the service to send notifications to the device whether the application is running or not.
2. Alternately, the client device can send its PNS handle to the application backend to have the application register the device.
3. When the application backend sends a message to the Notification Hubs service, the service sends the message to the appropriate target clients by using their registered PNS handles. The application backend simply requests that the message be sent and the Notification Hubs service and the PNS handle the actual distribution of messages to client devices.
Microsoft Azure Send/Receive Process

Messaging as a service on Azure Summary

I absolutely recommend spending some time with Azure documentation to learn more about Azure Service Bus. This topic is also covered in the 70-534 Architecting Azure Solutions Exam, so a better understanding of this service not only help you for certification prep, but also for real-world development for three-tier applications.
Architecting Microsoft Azure Solutions–70-534 Certification Preparation (ARM)

For more blog posts on Azure, follow this link.

Avatar

Written by

Cloud Academy Team

Related Posts

Avatar
Guy Hummel
— June 26, 2019

Running Apache Spark on Azure Databricks

In this article, we’ll cover how to set up an Azure Databricks cluster and how to run queries in an interactive notebook. However, this article only scratches the surface of what you can do with Azure Databricks. If you would like to learn more, including how to create graphs, run sched...

Read more
  • Azure
Avatar
Thomas Mitchell
— June 25, 2019

Understanding the Core Azure Architectural Components

Microsoft Azure relies on a few key architectural components to provide redundancy and high availability. Core Azure architectural components include Azure regions, Azure Availability Zones, resource groups, and the Azure Resource Manager. In this article, we’ll discuss the basics ab...

Read more
  • Azure
Avatar
Guy Hummel
— June 6, 2019

How to Become a Microsoft Certified Azure Administrator

Microsoft Azure is one of the hottest cloud services on the planet, and it’s growing at a phenomenal rate. This rapid growth has created a huge demand for people who know how to administer and manage Azure implementations. To make it easier for employers to verify the skills of Azure...

Read more
  • Azure
  • exam
Avatar
Guy Hummel
— May 20, 2019

Preparing for the Microsoft AZ-900 Exam

Microsoft has offered Azure certification exams for years, but until recently, they were all meant for technical IT professionals. Now non-technical professionals, such as salespeople and managers, can take the new AZ-900 exam to prove their understanding of Azure fundamentals. People w...

Read more
  • Azure
Avatar
Thomas Mitchell
— May 16, 2019

An Overview of Azure Storage (Part 2)

Archive Storage Archive Storage offers the lowest storage costs of all Azure storage. Its retrieval costs, however, are higher when compared to Hot and Cool storage. The archive tier of storage is designed for data that can tolerate several hours of latency when being retrieved. It’s a...

Read more
  • Azure
  • Storage
Avatar
Thomas Mitchell
— May 14, 2019

An Overview of Azure Storage (Part 1)

Welcome to part one of our series on Azure Storage. Stay tuned for the second part. An Overview of Azure Storage Microsoft Azure Storage is a cloud-based storage offering that provides multiple storage solutions for organizations. In addition to a massively scalable object store for ...

Read more
  • Azure
  • Storage
Avatar
Giacomo Marinangeli
— March 29, 2019

NEW: Custom Hands-On Labs for Azure and Google Cloud Platform

Harvard Business Review recently estimated that some 90% of corporate training never gets applied on the job. Given the $200B training industry, that is a staggering amount of waste. One reason for the disconnect? Lack of context. Cloud Academy’s platform was built to make it extraor...

Read more
  • Azure
  • Content Engine
  • Google Cloud Platform
  • Hands-on Labs
Avatar
Guy Hummel
— March 28, 2019

How to Become a Microsoft Certified Azure Solutions Architect

Microsoft Azure is the fastest growing cloud provider. Azure’s revenue grew an incredible 76% in the last quarter of 2018. As more and more businesses move their IT infrastructure to Microsoft’s cloud platform, the demand for Azure professionals keeps rising. Since there are relatively ...

Read more
  • Azure
Avatar
Nitheesh Poojary
— March 20, 2019

What is Heroku? Getting Started with PaaS Development

So just what is Heroku? It's a service for developers eager to get their applications online without having to worry about infrastructure details. Metered, pay-as-you-go Cloud Computing services come in all kinds of flavors. Infrastructure as a Service (IaaS) offerings like AWS allow e...

Read more
  • Azure
  • Development & Deploy
Avatar
Nitheesh Poojary
— March 12, 2019

Understanding Object Storage and Block Storage Use Cases

Cloud Computing, like any computing, is a combination of CPU, memory, networking, and storage. Infrastructure as a Service (IaaS) platforms allow you to store your data in either Block Storage or Object Storage formats. Understanding the differences between these two formats - and how ...

Read more
  • Azure
  • Storage
Avatar
Thomas Mitchell
— January 29, 2019

What are Azure Blueprints?

What are Azure Blueprints? Blueprints, in the traditional sense, are used by architects and engineers to design and build new things.  They are used to ensure that the final products are built to specifications and in compliance with certain standards and requirements. Azure Bluepri...

Read more
  • Azure
  • Blueprints
Avatar
Thomas Mitchell
— January 22, 2019

Azure Hybrid Identity Authentication Methods

The move to the cloud is picking up steam.  As such, many corporations are beginning to find themselves supporting a mixture of on-prem apps as well as cloud apps. Users are finding that they need access to this mix of applications as well.  As one would expect, this can become a challe...

Read more
  • Azure
  • Hybrid Cloud
  • Hybrid Identity