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.
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:
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 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)|
|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|
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.
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.
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.
For more blog posts on Azure, follow this link.
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...
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...
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), ...
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...
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...
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 ...
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 ...
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...
Introducing Our Newest Lab Environments: Lab Playgrounds
Want to train in a real cloud environment, but feel slowed down by spinning up your own deployments? When you consider security or pricing costs, it can be costly and challenging to get up to speed quickly for self-training. To solve this problem, Cloud Academy created a new suite of la...
Blog Digest: AWS Breaking News, Azure DevOps, AWS Study Guide, 8 Ways to Prevent a Ransomware Attack, and More
New articles by topicAWS Azure Data Science Google Cloud Cloud Adoption Platform Updates & New Content Security Women in TechAWSBreaking News: All AWS Certification Exams Now Available Online As an Advanced AWS Technology Partner, C...
New on Cloud Academy: AWS Solutions Architect Exam Prep, Azure Courses, GCP Engineer Exam Prep, Programming, and 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...
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...