Извините за длинный текст!
Я пытаюсь создать прослушиватель сообщений для RabbitMQ в ядре aspnet 2.1.Как только я отправляю сообщение, я получаю эту ошибку в журнале:
2018-09-29 12: 35: 35.459 INFO NServiceBus.RecoverabilityExecutor Immediate Retry собирается повторить сообщение 'ab43' из-за исключения: System.InvalidOperationException: Невозможно разрешить тип: Event.Processor.Listener.CustomerReceivedHandler, имя службы: ---> System.InvalidOperationException: неразрешенная зависимость [Тип цели: Event.Processor.Listener.CustomerReceivedHandler], [Параметр: DbProvider (Event.Processor.Listener.IDbProvider.Core \ ObjectBuilder \ LightInject \ LightInject.g.cs: строка 3443 в LightInject.ServiceContainer.EmitConstructorDependency (эмиттер IEmitter, зависимость Dependency) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ LightInjectject.IjectBuder,cs: строка 3402 в LightInject.ServiceContainer.EmitConstructorDependencies (ConstructionInfo constructionInfo, IEmitter emitter, действие 1 decoratorTargetEmitter) in C:\BuildAgent\work\b549d46003942065\src\NServiceBus.Core\ObjectBuilder\LightInject\LightInject.g.cs:line 3368
at LightInject.ServiceContainer.EmitNewInstanceUsingImplementingType(IEmitter emitter, ConstructionInfo constructionInfo, Action
1 decoratorTargetEmitMethod) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBject.In.Inject.Sject.ject.ject.ject.ject.ject.Inject.ject.Injectстрока 3329 в LightInject.ServiceContainer.EmitNewInstance (ServiceRegistration serviceRegistration, эмиттер IEmitter) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ ObjectBuilder \ LightInject \ LightInject.g.cs: lineynamerDideDate.DirectMateCate.DirectMateCate.DirectMateCate.DirectMateCate.DirectMateCateDate.DateMateCate.Действие 1 serviceEmitter) in C:\BuildAgent\work\b549d46003942065\src\NServiceBus.Core\ObjectBuilder\LightInject\LightInject.g.cs:line 3030
at LightInject.ServiceContainer.CreateInstanceDelegateIndex(Action
1 emitMethod) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ ObjectBuilder \ LightInject \ LightInject.g.cs: строка 3868 в LightInject.ServiceContainer.EmitLifetime (ServiceRegistration serviceRe7istration, действие 1serviceEmitter) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ ObjectBuilder \ LightInject \ LightInject.g.cs: строка 3030 в LightInject.ServiceContainer.CreateDelegate (введите serviceType, StringserviceName, Boolean throwError) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ ObjectBuilder \ LightInject \ LightInject.g.cs: строка 3915 --- Конец внутренней трассировки стека исключений --- в LightInject.ServiceContainer.CreateDelegate (введите serviceType, String serviceName, Boolean throwError) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ ObjectBuilder \ LightInject \ LightInject.g.cs: строка 3920 в LightInject.ServiceContainer.DateatethrowError) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ ObjectBuilder \ LightInject \ LightInject.g.cs: строка 3878 в LightInject.ServiceContainer.GetInstance (тип serviceType) в C: \ BuildAgent \65 \ work \ 465505src \ NServiceBus.Core \ ObjectBuilder \ LightInject \ LightInject.g.cs: строка 2740 на LightInject.Scope.WithThisScope [T] (этап Func 1 function) in C:\BuildAgent\work\b549d46003942065\src\NServiceBus.Core\ObjectBuilder\LightInject\LightInject.g.cs:line 6220
at NServiceBus.LoadHandlersConnector.Invoke(IIncomingLogicalMessageContext context, Func
2) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core\ Pipeline \ Incoming \ LoadHandlersConnector.cs: строка 45 в NServiceBus.MutateIncomingMessageBehavior.InvokeIncomingMessageMutators (контекст IIncomingLogicalMessageContext, стадия Func 2 next) in C:\BuildAgent\work\b549d46003942065\src\NServiceBus.Core\MessageMutators\MutateInstanceMessage\MutateIncomingMessageBehavior.cs:line 60
at NServiceBus.DeserializeLogicalMessagesConnector.Invoke(IIncomingPhysicalMessageContext context, Func
2) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ Pipeline \ Incoming \ DeserializeLogicalMessagesConnect.conv.1010 * 2 следующий) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ UnitOfWork \ UnitOfWorkBehavior.cs: строка 62 в NServiceBus.MutateIncomingTransportMessageBehavior.InvokeIncoming_Tyxt_Tyxt_Tyxt_MBBuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ Performance \ Statistics \ ProcessingStatisticsBehavior.cs: строка 25в NServiceBus.TransportReceiveToPhysicalMessageProcessingConnector.Invoke (контекст ITransportReceiveContext, Func`2 следующий) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ Inline \ Pipeline \ Incoming \) в C: \ BuildAgent \ work \ b549d46003942065 \ src \ NServiceBus.Core \ Pipeline \ MainPipelineExecutor.cs: строка 34 в NServiceBus.Transport.RabbitMQ.MessagePump.Process (сообщение BasicDeliverEventArgs) в C: \ Builddf6 \ sfdb6\ NServiceBus.Transport.RabbitMQ \ Receiving \ MessagePump.cs: строка 249
csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>Event.Processor</AssemblyName>
<RootNamespace>Event.Processor</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Customer.Models" Version="1.0.21875" />
<PackageReference Include="lightinject" Version="5.2.0" />
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="2.0.8" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="nservicebus" Version="7.1.4" />
<PackageReference Include="NServiceBus.RabbitMQ" Version="5.0.1" />
<PackageReference Include="odp.netcore" Version="2.0.12" />
<PackageReference Include="serilog" Version="2.7.1" />
<PackageReference Include="Serilog.aspnetcore" Version="2.1.1" />
<PackageReference Include="serilog.settings.configuration" Version="2.6.1" />
<PackageReference Include="serilog.sinks.console" Version="3.1.1" />
<PackageReference Include="serilog.sinks.file" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
app.Run(async context =>
{
await context.Response.WriteAsync("Hello Processor");
});
}
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
ServiceContainer container = new ServiceContainer(new ContainerOptions
{
EnablePropertyInjection = false
});
//The below didn't work either!
//services.AddSingleton<IDbProvider, DbProvider>();
//services.AddSingleton<IConfigSettings, ConfigSettings>();
//services.AddSingleton<IEncryptor, Encryptor>();
container.Register<IDbProvider, DbProvider>();
container.Register<IConfigSettings, ConfigSettings>();
container.Register<IEncryptor, Encryptor>();
return container.CreateServiceProvider(services);
}
}
Program.cs
public class Program
{
public static void Main(string[] args)
try
{
var endpointConfiguration = new EndpointConfiguration("MSG_QUEUE");
var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
transport.UseConventionalRoutingTopology();
transport.ConnectionString("ConxnString");
endpointConfiguration.EnableInstallers();
endpointConfiguration.SendFailedMessagesTo("error");
endpointConfiguration.AutoSubscribe();
endpointConfiguration.UsePersistence<InMemoryPersistence>();
endpointConfiguration.UseSerialization<XmlSerializer>();
Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
//IEndpointInstance endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
//endpointInstance.Stop().ConfigureAwait(false);
//Log.Information("Starting web host");
CreateWebHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
//Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
//Log.CloseAndFlush();
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
MessageHandler.cs
public class CustomerReceivedHandler : IHandleMessages<PubSubObject>
{
private readonly IDbProvider _DbProvider;
private static readonly ILog Log = LogManager.GetLogger<CustomerReceivedHandler>();
public CustomerReceivedHandler(IDbProvider DbProvider)
{
_DbProvider = DbProvider;
// If I don't inject and initialize as below, it works fine
//_DbProvider = new DbProvider(new ConfigSettings(new Encryptor());
}
public Task Handle(PubSubObject message, IMessageHandlerContext context)
{
Log.Info($"Received message with id {context.MessageId}");
}
}