2

I have a .NET Core service publishing events to Rebus with RMQ Transport with the following configuration:

            services.AddRebus(configure => configure
                .Logging(x => x.Serilog())
                .Transport(x => x.UseRabbitMq(rabbitMqConnection, "ServiceA"))
                .Routing(x => x.TypeBased()));

When I run it, it appears to publish the event to the RebusTopics exchange. So then service B has config like this:

            services.AutoRegisterHandlersFromAssemblyOf<MyHandler1>();

            services.AddRebus(configure => configure
                .Logging(x => x.Serilog() )
                .Transport(x => x.UseRabbitMq(rabbitMqConnection, "ServiceB"))
                .Routing(x => x.TypeBased()));

and a handler:

    public class MyHandler1: IHandleMessages<ServiceAEvent>
    {
        public CreateMinisiteWhenPageIsCreated(){}

        public Task Handle(PageCreated message)
        {

            //do stuff..

            return Task.CompletedTask;
        }

There appears to be a binding to the RebusDirect exchange to a new ServiceB queue, but when I publish an event from ServiceA, the handler never fires in ServiceB... there is no binding on the RebusTopics exchange for that message type also.

Im going crazy wondering why, its quite similar in syntax to NServiceBus so very confused as to why its not working.

user1957687
  • 89
  • 1
  • 11

2 Answers2

2

just add app.ApplicationServices.UseRebus(); in the Consumer's Starup.cs no need to subscribe also. ProducerApp can bus.Send() instead of bus.Publish();

maniac
  • 159
  • 2
  • 10
1

It sounds to me like your subscriber needs to

await bus.Subscribe<ServiceAEvent>();

If the bus instance with the input queue named ServiceB makes the call above, a binding will be created from a topic, whose name is derived from the ServiceAEvent type, to the bus' input queue.

After that is done, it will receive the event whenever another bus instance calls

await bus.Publish(new ServiceAEvent(...));
mookid8000
  • 18,258
  • 2
  • 39
  • 63
  • Oh do I actually have to call bus.subscribe for each event? I would have that this would be done by the auto registration of the handler no? – user1957687 May 20 '19 at 22:40
  • I just seen your comment here: https://github.com/rebus-org/Rebus/issues/437.i had searched through the docs and examples quite a bit and struggled to see that it was needed :). Would it be useful to make this explicit in the pub sub section maybe? – user1957687 May 20 '19 at 22:57
  • 1
    Rebus has no "auto-registration" of handlers – you have to register handlers in your IoC container yourself, and Rebus does not know whether your messages are commands or events, so it doesn't automatically subscribe to them. – mookid8000 May 21 '19 at 06:22