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

Joe Nemer
Joe Nemer
— September 15, 2020

New Content: Azure DP-100 Certification, Alibaba Cloud Certified Associate Prep, 13 Security Labs, and Much More

This past month our Content Team served up a heaping spoonful of new and updated content. Not only did our experts release the brand new Azure DP-100 Certification Learning Path, but they also created 18 new hands-on labs — and so much more! New content on Cloud Academy At any time, y...

Read more
  • AWS
  • Azure
  • DevOps
  • Google Cloud Platform
  • Machine Learning
  • programming
Avatar
Andrew Larkin
— August 18, 2020

Constant Content: Cloud Academy’s Q3 2020 Roadmap

Hello —  Andy Larkin here, VP of Content at Cloud Academy. I am pleased to release our roadmap for the next three months of 2020 — August through October. Let me walk you through the content we have planned for you and how this content can help you gain skills, get certified, and...

Read more
  • alibaba
  • AWS
  • Azure
  • content roadmap
  • Content updates
  • DevOps
  • GCP
  • Google Cloud
  • New content
Alisha Reyes
Alisha Reyes
— August 5, 2020

New Content: Alibaba, Azure AZ-303 and AZ-304, Site Reliability Engineering (SRE) Foundation, Python 3 Programming, 16 Hands-on Labs, and Much More

This month our Content Team did an amazing job at publishing and updating a ton of new content. Not only did our experts release the brand new AZ-303 and AZ-304 Certification Learning Paths, but they also created 16 new hands-on labs — and so much more! New content on Cloud Academy At...

Read more
  • AWS
  • Azure
  • DevOps
  • Google Cloud Platform
  • Machine Learning
  • programming
Alisha Reyes
Alisha Reyes
— July 16, 2020

Blog Digest: Which Certifications Should I Get?, The 12 Microsoft Azure Certifications, 6 Ways to Prevent a Data Breach, and More

This month, we were excited to announce that Cloud Academy was recognized in the G2 Summer 2020 reports! These reports highlight the top-rated solutions in the industry, as chosen by the source that matters most: customers. We're grateful to have been nominated as a High Performer in se...

Read more
  • AWS
  • Azure
  • blog digest
  • Certifications
  • Cloud Academy
  • OWASP
  • OWASP Top 10
  • Security
  • VPCs
Avatar
Cloud Academy Team
— July 9, 2020

Which Certifications Should I Get?

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 companies. With all that in mind, the s...

Read more
  • AWS
  • Azure
  • Certifications
  • Cloud Computing
  • Google Cloud Platform
Alisha Reyes
Alisha Reyes
— July 2, 2020

New Content: AWS, Azure, Typescript, Java, Docker, 13 New Labs, and Much More

This month, our Content Team released a whopping 13 new labs in real cloud environments! If you haven't tried out our labs, you might not understand why we think that number is so impressive. Our labs are not “simulated” experiences — they are real cloud environments using accounts on A...

Read more
  • AWS
  • Azure
  • DevOps
  • Google Cloud Platform
  • Machine Learning
  • programming
Joe Nemer
Joe Nemer
— June 19, 2020

Kickstart Your Tech Training With a Free Week on Cloud Academy

Are you looking to make a jump in your technical career? Want to get trained or certified on AWS, Azure, Google Cloud Platform, DevOps, Kubernetes, Python, or another in-demand skill? Then you'll want to mark your calendar. Starting Monday, June 22 at 12:00 a.m. PDT (3:00 a.m. EDT), ...

Read more
  • AWS
  • Azure
  • cloud academy content
  • complimentary access
  • GCP
  • on the house
Joe Nemer
Joe Nemer
— June 12, 2020

Azure Certifications: Our Experts Explain Which Is Best for You

How do you choose an Azure certification? It can be hard to get started when choosing an Azure certification. There are so many to sift through, so many interesting options, and it requires a time commitment to just understand the cert landscape. To help guide you through the select...

Read more
  • AZ-900
  • Azure
  • Certifications
Alisha Reyes
Alisha Reyes
— June 11, 2020

New Content: AZ-500 and AZ-400 Updates, 3 Google Professional Exam Preps, Practical ML Learning Path, C# Programming, and More

This month, our Content Team released tons of new content and labs in real cloud environments. Not only that, but we introduced our very first highly interactive "Office Hours" webinar. This webinar, Acing the AWS Solutions Architect Associate Certification, started with a quick overvie...

Read more
  • AWS
  • Azure
  • DevOps
  • Google Cloud Platform
  • Machine Learning
  • programming
Rebecca Willis
Rebecca Willis
— June 3, 2020

Azure vs. AWS: Which Certification Provides the Brighter Future?

More and more companies are using cloud services, prompting more and more people to switch their current IT position to something cloud-related. The problem is most people only have that much time after work to learn new technologies, and there are plenty of cloud services that you can ...

Read more
  • AWS
  • Azure
  • certification
Alisha Reyes
Alisha Reyes
— June 2, 2020

Blog Digest: 5 Reasons to Get AWS Certified, OWASP Top 10, Getting Started with VPCs, Top 10 Soft Skills, and More

Thank you for being a valued member of our community! We recently sent out a short survey to understand what type of content you would like us to add to Cloud Academy, and we want to thank everyone who gave us their input. If you would like to complete the survey, it's not too late. It ...

Read more
  • AWS
  • Azure
  • blog digest
  • Certifications
  • Cloud Academy
  • OWASP
  • OWASP Top 10
  • Security
  • VPCs
Alisha Reyes
Alisha Reyes
— May 11, 2020

New Content: Alibaba, Azure Cert Prep: AI-100, AZ-104, AZ-204 & AZ-400, Amazon Athena Playground, Google Cloud Developer Challenge, and much more

This month, our Content Team released 8 new learning paths, 4 courses, 7 labs in real cloud environments, and 4 new knowledge check assessments. Not only that, but we introduced our very first course on Alibaba Cloud, and our expert instructors are working 'round the clock to create 6 n...

Read more
  • alibaba
  • AWS
  • Azure
  • gitops
  • Google Cloud Platform
  • lab playground
  • programming