通过http://masstransit-project.com/MassTransit/usage/configuration.html按照说明配置MassTransit之后
您如何在
中使用(发布/订阅)它namespace App1.Message.API
{
public class Startup
{
.....
private IContainer container { get; set; }
public IServiceProvider ConfigureServices(IServiceCollection services)
{
......
var builder = new ContainerBuilder();
builder.Register(c =>
{
return Bus.Factory.CreateUsingRabbitMq(sbc =>
sbc.Host("localhost", "/", h =>
{
h.Username("guest");
h.Password("guest");
})
);
})
.As<IBusControl>()
.As<IBus>()
.As<IPublishEndpoint>()
.SingleInstance();
builder.Populate(services);
container = builder.Build();
return new AutofacServiceProvider(container);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime)
{
......
//resolve the bus from the container
var bus = container.Resolve<IBusControl>();
//start the bus
var busHandle = TaskUtil.Await(() => bus.StartAsync());
//register an action to call when the application is shutting down
lifetime.ApplicationStopping.Register(() => busHandle.Stop());
}
}
}