46 lines
1.8 KiB
C#
46 lines
1.8 KiB
C#
|
|
using System;
|
|||
|
|
using JiShe.CollectBus.Common.Interfaces;
|
|||
|
|
using JiShe.CollectBus.RabbitMQ.Consumers;
|
|||
|
|
using MassTransit;
|
|||
|
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
|
using Microsoft.Extensions.Hosting;
|
|||
|
|
using RabbitMQ.Client;
|
|||
|
|
|
|||
|
|
namespace JiShe.CollectBus.RabbitMQ
|
|||
|
|
{
|
|||
|
|
public class JiSheCollectBusRabbitMqModule: IJiSheModule
|
|||
|
|
{
|
|||
|
|
public void ConfigureServices(IServiceCollection services, HostBuilderContext hostContext)
|
|||
|
|
{
|
|||
|
|
var configuration = hostContext.Configuration;
|
|||
|
|
services.AddMassTransit(x =>
|
|||
|
|
{
|
|||
|
|
x.AddConsumer<MessageReceivedConsumer>();
|
|||
|
|
x.AddConsumer<MessageIssuedConsumer>();
|
|||
|
|
x.UsingRabbitMq((context, cfg) =>
|
|||
|
|
{
|
|||
|
|
cfg.Host(configuration["MQ:Host"], ushort.Parse(configuration["MQ:Port"] ?? string.Empty), configuration["MQ:VirtualHost"], h =>
|
|||
|
|
{
|
|||
|
|
h.Username(configuration["MQ:UserName"] ?? string.Empty);
|
|||
|
|
h.Password(configuration["MQ:Password"] ?? string.Empty);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 消息接收队列
|
|||
|
|
cfg.ReceiveEndpoint(configuration["MQ:Queue:Received"] ?? string.Empty,configurator =>
|
|||
|
|
{
|
|||
|
|
configurator.ConfigureConsumeTopology = false;
|
|||
|
|
configurator.Consumer<MessageReceivedConsumer>(context);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 消息下发队列
|
|||
|
|
cfg.ReceiveEndpoint(configuration["MQ:Queue:Issued"] ?? string.Empty, configurator =>
|
|||
|
|
{
|
|||
|
|
configurator.ConfigureConsumeTopology = false;
|
|||
|
|
configurator.Consumer<MessageIssuedConsumer>(context);
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|