Shuttle / Shuttle.Esb

A highly extensible service bus implementation.
http://shuttle.github.io/shuttle-esb/
BSD 3-Clause "New" or "Revised" License
95 stars 30 forks source link

ISubscriptionManager defaulting to NullSubscriptionManager imp #37

Closed WoozChucky closed 6 years ago

WoozChucky commented 6 years ago

Hello, i'm trying to follow the GitHub sample for the Shuttle.PublishSubscribe example.

Everything works as intended except the Subscriber part.

I'm using RabbitMQ 3.7.7 and the message is published successfully from the client app to the server app. Also, the MemberRegisteredEvent is fired.

I'm using Autofac for IoC.

The error occurs in the Subscriber app whenever I try to fetch the ISubscriptionManager to Subscribe to the MemberRegisteredEvent.

Here is my Host.cs code:

public class Host : IServiceHost
    {

        IServiceBus _bus;

        public void Start()
        {
            var containerBuilder = new ContainerBuilder();

            var registry = new AutofacComponentRegistry(containerBuilder);

            ServiceBus.Register(registry);

            var resolver = new AutofacComponentResolver(containerBuilder.Build());

            resolver.Resolve<ISubscriptionManager>().Subscribe<MemberRegisteredEvent>();
            //Line above throws NotImplementedException("NullSubscriptionManager");

            _bus = ServiceBus.Create(resolver).Start();
        }

        public void Stop()
        {
            _bus.Dispose();
        }
    }

Am I missing something ?

eben-roux commented 6 years ago

This seems to indicate that the subscription manager implementation from Shuttle.Esb.Sql.Subscription has not been registered.

Perhaps check that the package is being referenced in your "Subscriber" application.

The package is included in the csproj file so it is rather odd: https://github.com/Shuttle/Shuttle.Esb.Samples/blob/master/Shuttle.PublishSubscribe/Shuttle.PublishSubscribe.Subscriber/Shuttle.PublishSubscribe.Subscriber.csproj

eben-roux commented 6 years ago

Apologies, somehow I thought you were running the samples but I see that you are following the guides (by the looks of it).

The default behaviour is to use the NullSubscriptionManager if no ISubscriptionManager is registered before getting to the default registration portion in the ServiceBus.Register(registry); method.

You could simply add the Shuttle.Esb.Sql.Subscription package and it will use the bootstrapping mechanism to register the Shuttle.Esb.Sql.Subscription.SubscriptionManager type.

It is also possible to register any other implementaion of the ISubscriptionManager interface manually before calling the ServiceBus.Register(registry); method.

WoozChucky commented 6 years ago

Thanks for the information @eben-roux ! I managed to get it working with the Shuttle.Esb.Sql.Subscriptionpackage.

Is there any other implementation of ISubscriptionManagerthat uses for example InMemory subscription rather than SQL ? Or it is easy enough to implement it myself ?

eben-roux commented 6 years ago

The Shuttle.Esb.Sql.Subscription package includes a Postgresql implementation also thanks to "Vincent Verschuren".

However, it certainly should be a simple process to add any other implementation. One of the "pros" of Shuttle.Esb is that it can easily be extended.

As stated above you can register an implementation of ISubscriptionManager before calling the ServiceBus.Register(registry); method (or use the bootstrapping).

It is a rather simple interface but please let me know if you need some guidance on any of the bits.

After having a look at that interface again I think I'll simplify it at some point. A couple of those methods can be extension methods since they are really there for convenience.

WoozChucky commented 6 years ago

Thanks a lot for your help, managed to create a very basic in memory implementation!

Closing this now 👍