This is the seventh blog post in this series on Windows Azure Service Bus. You can find the previous posts here:
March 6, 2014
Service Bus topics and subscriptions are based on a publish-subscribe messaging pattern. When using topics and subscriptions, components of a distributed application achieve temporal decoupling, i.e., the producers and consumers do not need to be sending and receiving messages at the same time, they instead exchange messages via a topic, which acts as an intermediary. A related benefit is load leveling, which enables producers and consumers to send and receive messages at different rates. In these aspects, topics are similar to a queue. However, in contrast to queues, where each message is processed by a single consumer, topics and subscriptions provide a one-to-many form of communication.
Topic
A topic is similar to the enqueueing side of a queue. Clients can send messages to a topic, but it provides no means to receive message directly. Instead, a topic has a collection of subscriptions that subscribe to messages sent to the topic based on filters. When a message is sent to a topic, a copy of the message is made available to each eligible subscription to process independently. Topics provide support for batching, message expiration, dead-lettering, and duplicate detection.
Subscription
A subscription resembles a virtual queue that receives copies of the messages that were sent to the topic. A subscription can belong to only a single topic. A subscription can optionally register rules based on message properties, which filter/restrict which messages, sent to the topic, are received by the subscription. A subscription provides support for message sessions, batching, message expiration, dead-lettering, and auto-forwarding.
Rules
In many scenarios, messages having specific properties need to be processed in specific ways. To enable this, subscriptions can be configured to find messages having the desired properties and then perform certain modifications to those properties. This is accomplished using subscription rules. A rule consists of a filter expression (filters the messages in the topic and enqueues only eligible messages to the subscription), and a filter action (modifies the message properties for the filtered messages, before messages are dequeued from the subscription).
Scenario
In this tutorial we will create a console application, called TradePublisher, that will publish messages to a Windows Azure Service Bus Topic. We will also add another console application, called TradeSubscriber, that will work as the subscriber, and consume messages from a number of subscriptions, defined for the topic. The subscriptions will use different types of filters to restrict the messages they will receive. Later on we will extend our solution to support duplicate message handling and deferred message processing.
Prerequisites
Following are the administrative and prerequisite steps you should follow before beginning the tutorial. The first is to create a service namespace, and to obtain a shared secret key. A service namespace provides an application boundary for each application exposed through the Service Bus. A shared secret key is automatically generated by the system when a service namespace is created. The combination of service namespace and shared secret key provides a credential for the Service Bus to authenticate access to an application.
Create a Service Bus service namespace
Configure security for service namespace
Applications can authenticate to the Service Bus using either Shared Access Signature (SAS) authentication, or by authenticating through the Access Control Service (ACS).
For the purpose of this tutorial, we will use SAS for authenticating against the Service Bus. Below, are the steps for setting up the relevant configuration:
Connecting Visual Studio 2012 to Windows Azure
Create Tutorial Solution in Visual Studio
Create Data Contract
Sending Messages to the Topic
All steps in this section will be completed in the TopicPublisher project under the solution
Create Topic
A topic can be created in multiple ways:
In this tutorial, we will use Visual Studio to create the topic.
Azure Service Bus Explorer Path ServiceCreate Service Bus Connection String
Implement method to Generate Sample Trades
Implement method to Send Trades to Topic
In this step, we will publish the messages contained in the trade list to the topic.
Putting it all together
Note: Although we have published messages to the topic at this stage; however, since we have not yet created any subscription for this topic, all the messages will be discarded by the messaging system.
Receive Messages from the Subscription
The steps in this section will be completed in the TopicSubscriber project
Setting up Management Credentials
Now we are going to define the management operations that we will use to create secure (shared secret) credentials that will authorize our application.
Create subscriptions
Receiving Messages
For reading messages from a subscription, we use a SubscriptionClient object, which takes in the topic path, subscription name and Receive Mode as arguments. Similar to Service Bus Queues, messages can be received from subscriptions in two modes:
Steps:
Putting it all together
Running the Complete Scenario
Managing Duplicate Messages
In a messaging system, there could be scenarios where a message publisher sends identical messages multiple times. Rather than having the consuming application handle duplicate messages, the Service Bus infrastructure provides the capability to detect duplicate messages based on the MessageId property and ensure that only one message is enqueued into the topic. This is done by enabling Duplicate Message Detection and supplying a Duplication Detection History Time Window while creating the topic. The messaging system maintains a history of all MessageId’s sent to the Topic within that Time Window, and if a duplicate MessageId arrives, it ignores it.
Sending Duplicate Messages (Without Duplicate Message Detection)
Creating Topic with Duplicate Message Detection
Modifying and running the solution
Deferring Message Processing
In the PeekLock Receive Mode, the consuming applications have the option to mark a message as deferred. In this case, the message stays in the subscription channel, but is hidden from the normal message processing. Deferred messages can only be retrieved again by passing in the unique Message.SequenceNumber. Below we will extend our solution to allow deferring of messages based on their volume property, and once all normal messages have been processed, we will process the deferred messages.
Extend RecieveTradesFromSubscription() Method
Build & Run the Modified Application
This post covers most of the steps needed to setup and use Service Bus Topics and Subscriptions using the .NET API in an application. However there are still some areas that we did not explored as part of this post, e.g. Session Support, Chaining Queues / Topics / Subscriptions via auto-forwarding, Request-Response pattern implementation to name a few. Additionally, the Service Bus Messaging infrastructure also supports connecting to and working with Topics and Subscriptions via REST API, which is especially useful when connecting with applications not based on .NET platform. We will cover these topics in a later post.
Microsoft Azure Service Bus provides an PaaS (Platform as a Service) communications platform built to allow more robust, multi-tenant software systems to be built in the cloud. There are four main feature sets within Azure Service Bus (Queues, Topics, Relays, and Event Hubs) that all offer different communications mediums for use with and between the different tenants of cloud hosted and hybrid (cloud and on-premises) hosted applications.
Azure Service Bus Namespace
The primary container that all of the Azure Service Bus services (Queues, Topics, Relays, and Event Hubs) reside within is an Azure Service Bus Namespace. The term Namespace can initially appear a bit ambiguous. The Service Bus Namespace offers a logical grouping of all related Service Bus services used within the same application.
An Azure Service Bus Namespace must first be created before any of the Azure Service Bus services can be created and used. There are a few different ways to create a new Azure Service Bus Namespace. The most straightforward method is to just login to the Azure Portal, and manually create the namespace.
While creating a new Azure Service Bus Namespace manually is easy enough to do, when automation or DevOps are factors within your team culture then you’ll likely need to script out the creation of the Azure Service Bus Namespace. Fortunately, there are few different ways to do this; these include: PowerShell, X-plat CLI, and .NET SDK.
Azure Service Bus Queue
The Azure Service Bus Queue feature offers easy to implement infrastructure for implementing brokered messaging communication.
Implementing a Message Queue requires the implementation of 2 tenants; a Sender and a Receiver. The Sender sends the messages into the Queue, and then the Receiver retrieves messages from the Queue; both asynchronously.
Service Bus Queues work on a “First In, First Out” model. The first message into the Queue will be the first out when a Receiver Application checks the queue for messages and grabs the next in the Queue.
Azure Service Bus Topic
Azure Service Bus Topic provides a “more robust” messaging queue infrastructure than that offered by Service Bus Queues. At it’s core, Service Bus Topic offers a very similar brokered messaging infrastructure. However, Azure Service Bus Topic offers a few additional features that make it more robust under certain circumstances.
Message Sender applications submit messages to an Azure Service Bus Topic in a similar fashion to Service Bus Queues. The main difference lies with how the messages are received via Subscriptions.
Azure Service Bus Topic implements a Publish / Subscribe model to the messaging queue. Each Service Bus Topic Subscription can optionally implement a Filter that specifies which messages it will receive. This allows for not just a single receiver to receive each message (as with Service Bus Queue), but with Azure Service Bus Topic multiple receivers can receive the same messages given that their Subscriptions have a Filter that catches the messages. Using Subscriptions also allows for the receiver to be automatically notified of new messages, rather than need to implement periodic polling.
Cyber law cases.1.CYBER LAW ASSIGNMENTONIT ACT 2000 UNDER SECTIONS(43,65,66,66A,66B,66C,66D,66E,67,67A,67B,69,70,71,72,73)Submitted toProf. T s balan message center.
Azure Service Bus Relay
Azure Service Bus Relay allows for on-premises WCF (Windows Communication Foundation) services to securely and easily accessed by applications in the cloud. Service Bus Relay also allows this to be done without requiring any additional open ports or firewall configurations.
Essentially, the WCF service configured to use Azure Service Bus Relay will connect outbound to Azure using a TCP connection. Then other applications can connect to the Azure Service Bus Relay endpoint, and Service Bus Relay handles tunneling the communications through the TCP connection.
Azure Service Bus Relay allows for secure connection to the WCF service since it relies on Azure security to establish and encrypt the connection / communication. By including the security of the Relay into the Infrastructure of the service, it takes the responsibility of implementing the best security off of the developers. This ensures that security is implemented correctly, by Microsoft Azure, so there aren’t any vulnerabilities introduced by the application developers.
Azure Event Hubs
Microsoft Azure Event Hubs is a highly scalable service that is built for handling millions of events / messages per second. This is a message queue built for the ingress of gathering high amounts of event data.
While Service Bus Topic or Queue could be used for the same purpose, the Azure Event Hubs are built to scale to the demands of Big Data and IoT (Internet of Things.)
Further Reading
Microsoft Azure Service Bus offers quite a wide range of infrastructure functionality. This post is basically just an introduction into what each of these services are. This is also the first is a series of coming posts on working with the Microsoft Azure Service Bus.
Related Articles:
Future Articles: Civilization 2 test of time deutsch download.
RelatedComments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |