Skip to content

Instantly share code, notes, and snippets.

@hd9
Last active February 10, 2020 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hd9/0809f4638a8167486960a6ca52841db3 to your computer and use it in GitHub Desktop.
Save hd9/0809f4638a8167486960a6ca52841db3 to your computer and use it in GitHub Desktop.
MassTransit - Example os simple server
// **********************************************
// Fore more information, visit:
// Blog: https://blog.hildenco.com/2018/08/masstransit-real-alternative-to.html
// Source: https://github.com/MassTransit/Sample-Direct
// **********************************************
using System;
using System.Threading.Tasks;
using Contracts;
using MassTransit;
namespace DirectServer
{
class Program
{
static async Task Main()
{
var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var host = cfg.Host("localhost", "/");
cfg.ConfigureMessageTopology();
cfg.ReceiveEndpoint(host, "direct.server", endpoint =>
{
endpoint.Handler<ClientAvailable>(async context =>
{
await context.Publish<ContentReceived>(new
{
Id = NewId.NextGuid(),
}, x => x.SetRoutingKey(context.Message.NodeId));
});
});
});
await bus.StartAsync();
try
{
await Task.Run(() =>
{
Console.WriteLine("Press <enter> to quit..");
Console.ReadLine();
});
}
finally
{
await bus.StopAsync();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment