Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PublishAsync methoed PersistentConnection: Attempt to create a channel while being disconnected. #504

Closed
zhujinhu21 opened this issue Nov 4, 2015 · 3 comments

Comments

@zhujinhu21
Copy link

my easynetq is v0.50.12.407.

in the web(mvc) action I use PublishAsync method ,sometimes it happens error ,error message is
EasyNetQ.EasyNetQException: PersistentConnection: Attempt to create a channel while being disconnected.
在 EasyNetQ.PersistentConnection.CreateModel()
在 EasyNetQ.Producer.PersistentChannel.OpenChannel()
在 EasyNetQ.Producer.PersistentChannel.InvokeChannelActionInternal(Action1 channelAction, DateTime startTime) 在 EasyNetQ.Producer.PersistentChannel.InvokeChannelAction(Action1 channelAction)
在 EasyNetQ.Producer.ClientCommandDispatcherSingleton.<>c__DisplayClass5`1.b__2()

my code is
// POST api/values
public HttpResponseMessage Post([FromBody] TeslaOrder order)
{
using (var messageBus = RabbitHutch.CreateBus("host=localhost;username=zhujinhu;password=123456;publisherConfirms=true;timeout=60"))
{
//messageBus.Publish(order);
messageBus.PublishAsync(order).ContinueWith(task =>
{
// this only checks that the task finished
// IsCompleted will be true even for tasks in a faulted state
// we use if (task.IsCompleted && !task.IsFaulted) to check for success
if (task.IsCompleted && !task.IsFaulted)
{
Console.Out.WriteLine("{0} Completed", 11);
}
if (task.IsFaulted)
{
Console.Out.WriteLine("\n\n");
Console.Out.WriteLine(task.Exception);
Console.Out.WriteLine("\n\n");
}
});
}
return Request.CreateResponse(HttpStatusCode.Created);
}

when debug it go into task.IsFaulted。

@zhujinhu21
Copy link
Author

my consumer is not running

@zidad
Copy link
Member

zidad commented Nov 4, 2015

Your bus instance is getting disposed before the message is published. Don't create an instance per call, create 1 instance per application domain.

@zidad
Copy link
Member

zidad commented Nov 4, 2015

Also, you're not returning the task from your controller action, so it executes outside the context of your controller action, that is not a good idea.

@Pliner Pliner closed this as completed May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants