Skip to content
Garry Mc edited this page Jun 8, 2015 · 2 revisions

Getting started with ABus is quick and simple and only requires a few steps. The sample below walks through how to create the ubiquitous Hello World app using messaging.

Receiver

The message receiver will process the message that was sent, which is usually a long running process. We'll make use of the ABus.Host which can be used to host message handlers. The host can be run as either a console application or installed as a windows service. For now we'll run it as a console application.

Steps

  1. Create a new class Library
  2. Install ABus.Host
PM> Install-Package ABus.Host
  1. Add the following code to the project, which configures your host to receive messages
    public class StartupClient : IConfigureHost
    {
        public void Configure(ConfigurationGrammar configure)
        {
            configure
                .EnsureQueueExists()
                .UseTransport<AzureBusTransport>("HellowWorld")
                .WithConnectionString(
                    "Endpoint=sb://<NAMESPACE>.servicebus.windows.net;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<KEY>");

            configure.UseContainer(new UnityBootstraper());
        }
    }
  1. Change the and values to the ones from your Azure subscription.
  2. Add a Handler to receive the message
    public class HelloWorldHandler : IHandleMessage<HelloWorldCommand>
    {
        public void Handler(HelloWorldCommand message)
        {
            Console.WriteLine("Received message: " + message.World);
        }
    }

Sender

The sender sends a message to the receiver. As the sender doesn't have to be a long running process as its not waiting to receive messages. It can be a simple console application.

Steps

  1. Create a new console application
  2. Install ABus
PM> Install-Package ABus
  1. Install ABus.AzureServiceBus
PM> Install-Package ABus.AzureServiceBus
  1. Copy the StartUpClient class from the receiver as this project needs the same configuration as the receiver. Add this code to the program.cs file
    static void Main(string[] args)
    {
        var bus = new Pipeline().StartUsingConfigureHost();
        bus.Send(new HelloWorldCommand {World = "Hello World!"});

        Console.ReadLine();
    }

Enabling Tracing output (Recommended)

Add the following to your app.config file to see detailed messaging about what is happening.

<configuration>
   <system.diagnostics>
    <sources> 
      <source name="ABus" switchValue="All">
        <listeners>
          <add name="Console" type="ABus.ColorConsoleTraceListener, ABus" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

Clone this wiki locally