Skip to content

AlfredBr/simple-azure-service-bus-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-azure-service-bus-example

This is the simplest Azure Service Bus example I could dream up.

(All code is written in C#. The Azure config scripts are written in PowerShell.)

You'll have to configure your Azure Service Bus accordingly in order for this sample application to work correctly, but that should be fairly easy. I've added PowerShell scripts in each folder to create and delete the queue's in Azure.

First, create an environment variable called 'azure-subscription-id' and set it to your Azure Subscription Id (it is read in from your environment on line #2 of azure-variables.ps1).

Then, in simple-queue run the create-queue.ps1 script.

Here are some hints...

  1. Create a queue named demo-asb-queuename.
  2. Create a topic named demo-asb-topicname.
  3. Create two subscriptions, one named even and the other named odd.
  4. The even subscription should have a custom property filter with a key named "messageTopic" and a value "even".
  5. The odd subscription should have a custom property filter with a key named "messageTopic" and a value "odd".
  6. Both subscriptions should have a system property named "contentType" with a value of "text/string".

simple-queue is just two console apps and a small class library.

  • sender sends the current time, a random 5 character string and an index to a Azure Service Bus queue.
  • receiver receives (and removes) the message from the queue.
  • shared is a library containing Config.cs to which you must add your endpoint connection string.

Run both the sender and the receiver with "dotnet run"


topic-queue is also a pair of console apps and a small class library.

  • publisher sends the current time, a random 5 character string and an index to a Azure Service Bus queue, but also sets a MessageTopic property to either even or odd depending on if the index is an even or an odd number.
  • subscriber subscribes to a topic subscription with the name even or odd and will receive messages from that subscription only.
  • shared is a library containing Config.cs to which you must add your endpoint connection string.

Run the publisher and it will begin publishing into the topic queue, sending messages into both the "even" and "odd" subscriptions.

dotnet run --subscribe even will select the "even" subscription.

Run the subscriber with the argument "even" or "odd" to subscribe to one of the subscriptions.

dotnet run --subscribe odd will select the "odd" subscription.

About

Simplest Azure Service Bus example I could come up with...

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published