添加项目文件。
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Reflection;
|
||||
|
||||
namespace IM.InitCommon
|
||||
{
|
||||
public static class RabbitMqExtension
|
||||
{
|
||||
public static IServiceCollection AddRabbitMq(this IServiceCollection services, RabbitMqOptions options, IEnumerable<Assembly> assemblies)
|
||||
{
|
||||
|
||||
var safeAssemblies = assemblies
|
||||
.Where(a => a.FullName != null &&
|
||||
!a.FullName.StartsWith("MassTransit", StringComparison.OrdinalIgnoreCase) &&
|
||||
!a.FullName.StartsWith("System", StringComparison.OrdinalIgnoreCase) &&
|
||||
!a.FullName.StartsWith("Microsoft", StringComparison.OrdinalIgnoreCase))
|
||||
.ToArray();
|
||||
|
||||
return services.AddMassTransit(x =>
|
||||
{
|
||||
x.AddConsumers(safeAssemblies);
|
||||
|
||||
x.UsingRabbitMq((context, cfg) =>
|
||||
{
|
||||
cfg.Host(options.Host, (ushort)options.Port, "/", c =>
|
||||
{
|
||||
c.Username(options.Username);
|
||||
c.Password(options.Password);
|
||||
});
|
||||
|
||||
cfg.ConfigureEndpoints(context);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user