2024-10-25 19:11:43 +08:00
|
|
|
|
using JiShe.CollectBus.RabbitMQ.Consumers;
|
|
|
|
|
|
using MassTransit;
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using RabbitMQ.Client;
|
|
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
|
|
namespace Microsoft.Extensions.DependencyInjection
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class ServiceCollectionExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static IServiceCollection AddMassTransit(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddMassTransit(x =>
|
|
|
|
|
|
{
|
|
|
|
|
|
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:Push"] ?? string.Empty, x =>
|
|
|
|
|
|
{
|
|
|
|
|
|
x.ConfigureConsumeTopology = false;
|
|
|
|
|
|
|
|
|
|
|
|
x.Consumer<PushConsumer>();
|
|
|
|
|
|
|
|
|
|
|
|
x.Bind("commands", s =>
|
|
|
|
|
|
{
|
|
|
|
|
|
s.RoutingKey = configuration["MQ:Queue:Push"];
|
|
|
|
|
|
s.ExchangeType = ExchangeType.Direct;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
cfg.ReceiveEndpoint(configuration["MQ:Queue:Report"] ?? string.Empty, x =>
|
|
|
|
|
|
{
|
|
|
|
|
|
x.ConfigureConsumeTopology = false;
|
|
|
|
|
|
|
|
|
|
|
|
x.Consumer<ReportConsumer>();
|
|
|
|
|
|
|
|
|
|
|
|
x.Bind("commands", s =>
|
|
|
|
|
|
{
|
|
|
|
|
|
s.RoutingKey = configuration["MQ:Queue:Report"];
|
|
|
|
|
|
s.ExchangeType = ExchangeType.Direct;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2024-10-26 22:27:19 +08:00
|
|
|
|
//cfg.UseRawJsonSerializer();
|
2024-10-25 19:11:43 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
services.AddMassTransitHostedService();
|
|
|
|
|
|
return services;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|