pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
746 stars 144 forks source link

2.0.0-rc1 - System.DivideByZeroException #299

Closed yeowgit closed 6 years ago

yeowgit commented 6 years ago

Hi,

I had this exception thrown today.

[FATAL NLogLogWriter] The service threw an unhandled exception System.DivideByZeroException: Attempted to divide by zero. at RawRabbit.Channel.AutoScalingChannelPool.b__7_0(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.TimerQueueTimer.CallCallback() at System.Threading.TimerQueueTimer.Fire() at System.Threading.TimerQueue.FireNextTimers()

pardahlman commented 6 years ago

Thanks for reporting this. Could you provide some information as to how you registered/created the IBusClientFactory?

yeowgit commented 6 years ago

Sorry for the delay.

The app uses Ninject to setup 2 different IBusClient by specifying the detail connection in the binding as below.

Kernel?.Load<RawRabbitModule>();

Bind<RawRabbitOptions>()
.ToConstant(
new RawRabbitOptions
{
    ClientConfiguration = config,
    Plugins = p => p.UseProtobuf()
});

Then create new IBusClient instance to each queue listener like so...

 // message dispatcher
            Bind<IFooMessageDispatcher>()
                .ToMethod(
                    x => new FooDispatcher(
                        x.Kernel.Get<IBusClient>(),
                        new TopologyConfiguration(m_config.TicketTopology)));

In IFooMessageDispatcher, our own TopologyConfiguration class will have the method to create IPublisherConfigurationBuilder and IConsumerConfigurationBuilder builders. I can provide more detail on each specific builder on how it declare its exchange and queue if required.

Then we use the subscriber as such...

m_client.SubscribeAsync<MyMessageType>(
                HandleMessageAsync,
                ctx =>
                    {
                        m_queueContext = ctx;
                        ctx.UseSubscribeConfiguration(
                                c => m_config.UpdateBuilder(c, subscriberName));
                    });
pardahlman commented 6 years ago

Alright, thanks for the update. I'll look into this later this week!

pardahlman commented 6 years ago

Hello @yeowgit - I believe the problem you describe is the same as #301 which is addressed and will be part of the upcoming release!