public void Send(T message) { lock(_locker) { using (Bus.Start()) { var publishTask = Bus.Publish<T>(message); publishTask.Wait(); } } }
The code always succeds when I call it from my ASP.NET web application , but it fails when i call it from some of my consumer thread.
It seems some consumers struggle to send messages using the Publish method , generall it seems to be consumers which are small .
For example this code inside one of my consumers fails consistenlty
lock(ExpectedTaskCode) { try {// get the wrapper class which has the Publish method in it.var msg = Container.GetInstanceWrapper<IMessageBus<NotificationEvent>>();// call the Send function above which is part of wrapper class msg.Send(new NotificationEvent() { }" }); } catch(Exception ex) {// always get a 'Task was cancelled' exception.}What could be the reason ? My guess is that the parent thread in which the send function is executing is dying before the publishTask finishes .But i dont know what else to check to debug this issue .Is there a log i can switch on to see whats really going wrong ?
PS :This error only occurs when calling the publish inside a consumer , it works fine otherwise
--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/27fca0d6-8b0d-4272-b268-e1f91069a217%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Yeah, so you're mixing things like lock() and calling .Wait() and all sorts of ways to really block the .NET thread pool which is a really bad way to use the TPL. I'd highly suggest looking at some of the samples on the MassTransit GitHib repo to see some examples of how to properly use Tasks from controllers.Also, it looks like you're using a custom wrapper on the bus, which I can't see but may contain some of the same threading problems.Another thing, if you're in a consumer, you should use the ConsumeContext to Publish, since it maintains the lineage of the ConversationId.__
Chris Patterson
--PS :This error only occurs when calling the publish inside a consumer , it works fine otherwise
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.