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

Alisha Reyes
Alisha Reyes
— April 9, 2020

New on Cloud Academy: AWS Solutions Architect – Associate Exam Prep, Azure Courses, Google Associate Cloud Engineer Exam Prep, Programming Labs, and Much More

Free content on Cloud Academy More and more customers are relying on our technology and content to keep upskilling their people in these months, and we are doing our best to keep supporting them. While the world fights the COVID-19 pandemic, we wanted to make a small contribution to he...

Read more
  • AWS
  • Azure
  • Google Cloud Platform
  • programming
Avatar
Logan Rakai
— April 7, 2020

How to Effectively Use Azure DevOps

Azure DevOps is a suite of services that collaborate on software development following DevOps principles. The services in Azure DevOps are: Azure Repos for hosting Git repositories for source control of your code Azure Boards for planning and tracking your work using proven agil...

Read more
  • Azure
  • DevOps
Alisha Reyes
Alisha Reyes
— March 17, 2020

Cloud Academy’s Blog Digest: How Do AWS Certifications Increase Your Employability, How to Become a Microsoft Certified Azure Data Engineer, and more

With everything going on right now, it's likely that the only thing you've been reading lately is related to the coronavirus pandemic. It's important to stay informed during these times, but it's also good to jump into something that can take your mind off of the current situation for j...

Read more
  • AWS
  • Azure
  • blog digest
  • Certifications
  • Cloud Academy
  • programming
  • Security
Avatar
Cloud Academy Team
— March 13, 2020

Which Certifications Should I Get?

As we mentioned in an earlier post, the old AWS slogan, “Cloud is the new normal” is indeed a reality today. Really, cloud has been the new normal for a while now and getting credentials has become an increasingly effective way to quickly showcase your abilities to recruiters and compan...

Read more
  • AWS
  • Azure
  • Certifications
  • Cloud Computing
  • Google Cloud Platform
Avatar
Guy Hummel
— March 10, 2020

How to Become a Microsoft Certified Azure Data Engineer

Data engineering is one of the most sought-after skills in the job market. According to a 2019 Dice.com report, there was an 88% year-over-year growth in job postings for data engineers, which was the highest growth rate among all technology jobs. If you want to become a data enginee...

Read more
  • Azure
  • Data Engineer
  • DP-200
  • DP-201
  • Microsoft
Alisha Reyes
Alisha Reyes
— March 7, 2020

New on Cloud Academy: Intro to GitOps; AWS Courses; Java, Python, Amazon Linux 2, Ubuntu, & Docker Playgrounds; and much more

New Lab Playgrounds This month, our Content Team released six new "playground labs." Our playground labs provide a safe and secure sandbox environment for you to explore your own ideas, follow along with Cloud Academy courses, or answer your own questions — all without having to instal...

Read more
  • AWS
  • Azure
  • gitops
  • Google Cloud Platform
  • lab playground
  • programming
Alisha Reyes
Alisha Reyes
— March 6, 2020

New on Cloud Academy: Intro to GitOps; AWS Courses; Java, Python, Amazon Linux 2, Ubuntu, & Docker Playgrounds; and much more

New Lab Playgrounds This month, our Content Team released six new "playground labs." Our playground labs provide a safe and secure sandbox environment for you to explore your own ideas, follow along with Cloud Academy courses, or answer your own questions — all without having to instal...

Read more
  • AWS
  • Azure
  • gitops
  • Google Cloud Platform
  • lab playground
  • programming
Avatar
Thomas Mitchell
— February 27, 2020

5 Steps to Vulnerability Management for Containers

Organizations have begun embracing containers due to their simplicity and to the fact that they allow for a faster development and deployment velocity. Although developers are thrilled with containers because they allow them to deliver solutions more quickly, security teams are sometime...

Read more
  • AZ-500
  • AZ-500 Exam
  • Azure
  • vulnerability management
Avatar
Chandan Patra
— February 21, 2020

Elasticsearch vs. CloudSearch: AWS Cloud Search Choices

Elasticsearch vs. CloudSearch: What's the main difference? Let's compare AWS-based cloud tools: Elasticsearch vs. CloudSearch. While both services use proven technologies, Elasticsearch is more popular, open source, and has a flexible API to use for customization; in comparison, CloudS...

Read more
  • AWS
  • Azure
  • cloudsearch
  • elasticsearch
Avatar
Andrew Larkin
— February 13, 2020

Cloud Academy Content Roadmap Updates

Welcome to our Q1 2020 roadmap. This is the content we plan to build over the next three months, between February 1 - and April 30, 2020. Let's look at some of our roadmap highlights. Atlassian Bamboo for CI/CD We had a lot of requests for practical guides on how to apply DevOps tool...

Read more
  • Artificial Intelligence
  • AWS
  • Azure
  • Docker
  • Google Cloud Platform
  • Kubernetes
  • Machine Learning
Alisha Reyes
Alisha Reyes
— February 7, 2020

New on Cloud Academy: Git Labs, CKA and CKAD Lab Challenges, AWS and Azure Learning Paths, AGILE, and Much More

We just kicked off our first Free Weekend of 2020. This means we've unlocked our Training Library for just 72 hours. Until Sunday at 11:59 pm (PST), you can get unlimited access to our industry-leading learning paths, courses, certification prep exams, and our most popular hands-on labs...

Read more
  • agile
  • AWS
  • Azure
  • Google Cloud Platform
  • Linux
  • OWASP
  • programming
  • red hat
  • scrum
Alisha Reyes
Alisha Reyes
— January 31, 2020

How to Unlock Complimentary Access to Cloud Academy

Are you looking to get trained or certified on AWS, Azure, Google Cloud Platform, DevOps, Cybersecurity, Information Security, Python, Java, or another technical skill? Then you'll want to mark your calendars. Starting Friday, February 7 at 12:00 a.m. PST (3:00 a.m. EST), Cloud Acade...

Read more
  • AWS
  • Azure
  • cloud academy content
  • complimentary access
  • GCP
  • on the house