Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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