public static void UseRabbitMQ(this IApplicationBuilder app, Action <BrokerOption> action) { var option = new BrokerOption(); action.Invoke(option); IBusClient client = app.ApplicationServices.GetRequiredService <IBusClient>(); client.CreateConnection(option.Host, option.UserName, option.Password); foreach (var bindOption in option.BindOptions) { client.Bind(bindOption.Exchange, bindOption.Queue, bindOption.RoutingKey); } }
public static void AddRabbitMQ(this IServiceCollection services, Action <BrokerOption> action) { var option = new BrokerOption(); action.Invoke(option); IBusClient client = new RabbitMQClient(); client.CreateConnection(option.Host, option.UserName, option.Password); foreach (var bindOption in option.BindOptions) { client.Bind(bindOption.Exchange, bindOption.Queue, bindOption.RoutingKey); } services.AddSingleton <IBusClient>(client); }