rebus-org / Rebus.ServiceProvider

:bus: Microsoft Extensions Dependency Injection container adapter for Rebus
https://mookid.dk/category/rebus
Other
65 stars 32 forks source link

Handlers are not getting properly registered #62

Closed tgrieger-sf closed 2 years ago

tgrieger-sf commented 2 years ago

I've been trying to get a simple POC of Rebus using this package up and running and have been unable to. I pulled the repo down and ran the Sample.WebApp project and it worked successfully. I copied out that project, changed the framework to net5.0, and added the Rebus 6.6.4 and Rebus.ServiceProvider 7.0.0 (I also tried 6.4.1) nuget packages and it no longer worked. Messages are sent correctly but they are never getting picked up by the handler. Any help would be greatly appreciated.

It's also worth noting that I updated the sample project to net5.0 in cloned repo and that still worked.

Here is the log from the copied project:

Content root path: C:\Users\tgrieger\source\repos\sfdc-mc-mj\DRHAM.POC\RebusPOC\TestProj
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 GET http://localhost:5000/ - -
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped Microsoft.CodeAnalysis.EmbeddedAttribute -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped System.Runtime.CompilerServices.NullableAttribute -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped System.Runtime.CompilerServices.NullableContextAttribute -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped Program -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped TestProj.Handler1 -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped TestProj.Message1 -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped TestProj.Startup -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped TestProj.Startup+<>c -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped TestProj.Startup+<>c__DisplayClass3_0 -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped TestProj.Startup+<>c__DisplayClass3_1 -> "Messages"
[INF] Rebus.Routing.TypeBased.TypeBasedRouter (Thread #11): Mapped TestProj.Startup+<>c__DisplayClass3_0+<<Configure>b__0>d -> "Messages"
[INF] Rebus.Threading.TaskParallelLibrary.TplAsyncTask (Thread #11): Starting periodic task "CleanupTrackedErrors" with interval 00:00:10
[INF] Rebus.Bus.RebusBus (Thread #11): Bus "Rebus 1" started
info: TestProj.Startup[0]
      Publishing 10 messages
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : d41a9069-0e2b-41c0-8812-6434adda09c9 -> "Messages"
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : 2625ccb8-328a-4433-ab6d-78836156032c -> "Messages"
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : 717d0930-6c12-45e0-b284-c37ba5634893 -> "Messages"
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : 9604001d-1445-4cb4-8dd2-fc233f95945f -> "Messages"
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : 327e85a3-e373-4e38-9b0f-27fede0e4c46 -> "Messages"
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : 67445b3e-a003-4908-8ee2-8f5cd180e662 -> "Messages"
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : ea5511e0-06d2-426b-9abc-2bb42fb4c732 -> "Messages"
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : fe72fde7-b0a0-4e38-9d3c-44f6a3dab4d3 -> "Messages"
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : 44b7c928-278b-472a-bcf3-088d2ee5360a -> "Messages"
[DBG] Rebus.Pipeline.Send.SendOutgoingMessageStep (Thread #11): Sending Message1 : 9e068d4b-8c51-4506-a8c4-83ec862cd261 -> "Messages"
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/1.1 GET http://localhost:5000/ - - - 200 - - 674.8306ms
tgrieger-sf commented 2 years ago

I found a two answers:

  1. Updating to the 8.0.0-b05 version of Rebus.ServiceProvider fixes the issue. I figured that would work because that's what the sample is essentially using (the latest) instead of a released nuget package
  2. When using version 7.0.0, I fixed the issue by adding app.ApplicationServices.UseRebus(); to the Configure method in Startup. That's what was in an earlier version of the WebApp sample (it's been renamed to StartRebus in the beta version).
mookid8000 commented 2 years ago

You are right about (1) and (2) above. Thanks for posting it here 🙂

BUT there's a small caveat: In versions >= 8 it's only necessary to call the StartRebus extension method if you are outside of the generic host!

Versions >= 8 rely on BackgroundService to start, and so it hooks into the normal startup/shutdown phases of the host.

tgrieger-sf commented 2 years ago

Got it, thanks for the extra info!