Skip to content

Instantly share code, notes, and snippets.

@alexeyzimarev
Created January 9, 2018 20:31
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
MassTransit v4 and .NET Core console app to run in a Docker container
using System;
using System.IO;
using System.Runtime.Loader;
using System.Threading;
using System.Threading.Tasks;
using GreenPipes;
using MassTransit;
using Microsoft.Extensions.Configuration;
using Serilog;
namespace Abax.Events.Log
{
internal static class Program
{
private static IBusControl _busControl;
private static readonly AutoResetEvent WaitHandle = new AutoResetEvent(false);
internal static void Main(string[] args)
{
AssemblyLoadContext.Default.Unloading += _ => Exit();
Console.CancelKeyPress += (_, __) => Exit();
Serilog.Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("name", typeof(Program).Assembly.GetName().Name)
.WriteTo.Console()
.CreateLogger();
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var rmqSettings = config.GetSection("RabbitMq").Get<Configuration.RabbitMq>();
_busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.PrefetchCount = 50;
cfg.UseConcurrencyLimit(50);
var host = cfg.Host(new Uri(rmqSettings.Host), h =>
{
h.Username(rmqSettings.User);
h.Password(rmqSettings.Password);
});
cfg.ReceiveEndpoint(host, rmqSettings.Endpoint,
ep =>
{
// Endpoint configuration stuff
});
});
Serilog.Log.Information("Starting...");
_busControl.Start();
Serilog.Log.Information("Started");
WaitHandle.WaitOne();
}
private static void Exit()
{
Serilog.Log.Information("Exiting...");
_busControl.Stop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment