-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
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.
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.
- Create a new class Library
- Install ABus.Host
PM> Install-Package ABus.Host- 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());
}
}- Change the and values to the ones from your Azure subscription.
- Add a Handler to receive the message
public class HelloWorldHandler : IHandleMessage<HelloWorldCommand>
{
public void Handler(HelloWorldCommand message)
{
Console.WriteLine("Received message: " + message.World);
}
}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.
- Create a new console application
- Install ABus
PM> Install-Package ABus- Install ABus.AzureServiceBus
PM> Install-Package ABus.AzureServiceBus- 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();
}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>