SteeltoeOSS / Connectors

Connectors simplify connecting to standalone and CloudFoundry services
https://steeltoe.io/docs/steeltoe-connectors/
Apache License 2.0
27 stars 13 forks source link

Unable to find ConnectionFactory, are you missing RabbitMQ assembly #6

Closed ndrscrls closed 7 years ago

ndrscrls commented 7 years ago

I just updated from the latest stable version of the Rabbit connector(1.0.0) to 1.0.1-dev-00110 to be able to use the connector with SSL, and I'm getting the following error when trying to register the Rabbit connection:

Unable to find ConnectionFactory, are you missing RabbitMQ assembly at Steeltoe.CloudFoundry.Connector.Rabbit.RabbitProviderServiceCollectionExtensions.DoAdd(IServiceCollection services, RabbitServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime) at Steeltoe.CloudFoundry.Connector.Rabbit.RabbitProviderServiceCollectionExtensions.AddRabbitConnection(IServiceCollection services, IConfiguration config, ServiceLifetime contextLifetime, ILoggerFactory logFactory)

I'm using .netcore on an asp.net webapi application. I do have the RabbitMq nuget package installed. Any thoughts? Thanks.

dtillman commented 7 years ago

@ndrscrls : With the 1.0.1 release of the Rabbit connector, you will need to add the RabbitMQ Client as a dependency in your applications .csproj file... The 1.0.0 Steeltoe connector had the dependency included in it, so you would automatically get the dependency when you did a restore on your app.

With 1.0.1, we have disconnected the dependency, so you will need to explicitly add "RabbitMQ.Client" to your apps dependency. The good news, you can choose the version of the Rabbit Client code you pick with this new approach.... Have a look at Rabbit.csproj .... https://github.com/SteeltoeOSS/Samples/blob/dev/Connectors/src/AspDotNetCore/Rabbit/Rabbit.csproj

Also, you might run into certificate validation errors if you are using self-signed certs... see brute force code in sample for disabling cert validation: https://github.com/SteeltoeOSS/Samples/blob/dev/Connectors/src/AspDotNetCore/Rabbit/Controllers/RabbitController.cs

ndrscrls commented 7 years ago

@dtillman Thanks, I do have the reference to RabbitMQ in my project, it looks like this: `

<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Steeltoe.CloudFoundry.Connector.MySql" Version="1.0.0" />
<PackageReference Include="Steeltoe.CloudFoundry.Connector.Rabbit" Version="1.0.1-dev-00110" />
<PackageReference Include="RabbitMQ.Client" Version="4.1.3" />

`

It still fails with the same error.

dtillman commented 7 years ago

@ndrscrls : Not sure this is it but could you try and update the MySql connector to 1.0.1 as well. You will need to explicitly add the MySql dependencies to your app as well, just like the Rabbit dependency.

For example if you are using EFCore with MySql you will need :

or if you want to use the Pomelo EFCore option:

See the MySQL samples on the dev branch for example .csproj files.

Let me know your findings... and thanks for testing this. Dave

jquintero33 commented 7 years ago

Looks like the issue is occurring due to the AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(name)); call in Steeltoe.CloudFoundry.Connector.ConnectorHelpers.FindAssembly. Using Assembly a = Assembly.Load(new AssemblyName(name)); instead fixes the issue.

dtillman commented 7 years ago

@jquintero33 : Thanks... are you running your app on .NET Core and on WIndows or Linux? Dave

jquintero33 commented 7 years ago

.NET Core on windows in development and Linux in production.

dtillman commented 7 years ago

@jquintero33 : Connector fails to find assembly on both WIndows and Linux?

jquintero33 commented 7 years ago

Yes, it fails on both. We are using .Net Core 1.0.1.

dtillman commented 7 years ago

@jquintero33 :

Thanks for reporting ... the AssemblyLoadContext.Default.LoadFromAssemblyName() works fine on 1.1 of .NET Core, but fails on 1.0.1 .NET Core...

I've updated the code so to support 1.0.1 of .NET Core ... its in nuget 1.0.1-dev-112.

Dave

jquintero33 commented 7 years ago

It's working now. One thing to note is I had to set the Ssl.Version property on the connection factory otherwise you get an SSL handshake error. I appreciate your help with this, thanks!

dtillman commented 7 years ago

Great.. thanks for reporting.