c# - MassTransit (over RabbitMQ) IServiceBus.Publish(...) hangs unexpectedly -


i'm developing web based solution using masstransit + rabbitmq. time ago noticed when run integration tests of them start unexpectedly , very inconsistently hanging loooong time. after short investigation found out code hangs somewhere inside servicebus.publish(t message) method.

unfortunately masstransit documentation , blog posts found not answer reason , how solve problem. here resolve it.

here how initialize service bus:

servicebusfactory.new(sbc =>       {         sbc.receivefrom(busaddress);         sbc.userabbitmq(r =>         {           r.configurehost(new uri(busaddress),             cfg =>             {               if (!string.isnullorempty(bususer) && !string.isnullorempty(buspass))               {                 cfg.setpassword(buspass);                 cfg.setusername(bususer);               }             });         });          sbc.usecontrolbus();         sbc.setcreatemissingqueues(true);         sbc.setcreatetransactionalqueues(true);         sbc.setnetwork("workgroup");         sbc.usebsonserializer();         sbc.setdefaultretrylimit(2);         sbc.setdefaulttransactiontimeout(new timespan(0, 0, timeoutsec));          sbc.validate();       }); 

timeoutsec value 10 service bus initialized once , registered in autofac container.

publishing happens calling iservicebus.publish(...) method.

one of solutions wrap publish(...) method task , use task.wait(...) method enforce timeout not solution.

i appreciated kind of help!

important update 2017-01-26: question related mt v2. seems mt v3 has similar issue if 1 forgets "await". problem not related "await" , (still) not have solution (as far know). recommend migrate mt v3.

send , publish in masstransit v3 asynchronous nature. how designed. typical issue when calling async methods without awaiting them - calling context gets disposed before task completed. common. have to await it. masstransit gives utility call synchronous method:

taskutil.await(() => bus.publish(message)); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -