1
0
mirror of synced 2024-12-22 09:13:07 +01:00

Fixed consumers not restarting after a reconnect

This commit is contained in:
Mark van Renswoude 2019-09-10 19:38:59 +02:00
parent a9045eea7e
commit 99bc839814
2 changed files with 25 additions and 6 deletions

View File

@ -40,6 +40,20 @@ namespace Tapeti.Connection
}
/// <summary>
/// Called after the connection is lost and regained. Reapplies the bindings and if Resume
/// has already been called, restarts the consumers. For internal use only.
/// </summary>
/// <returns></returns>
public async Task Reconnect()
{
await ApplyBindings();
if (consuming)
await ConsumeQueues();
}
/// <inheritdoc />
public async Task Resume()
{
@ -47,7 +61,12 @@ namespace Tapeti.Connection
return;
consuming = true;
await ConsumeQueues();
}
private async Task ConsumeQueues()
{
var queues = config.Bindings.GroupBy(binding => binding.QueueName);
await Task.WhenAll(queues.Select(async group =>

View File

@ -145,15 +145,15 @@ namespace Tapeti
protected virtual void OnReconnected(EventArgs e)
{
var reconnectedEvent = Reconnected;
if (reconnectedEvent == null)
if (reconnectedEvent == null && subscriber == null)
return;
Task.Run(() =>
Task.Run(async () =>
{
subscriber?.ApplyBindings().ContinueWith(t =>
{
reconnectedEvent.Invoke(this, e);
});
if (subscriber != null)
await subscriber.Reconnect();
reconnectedEvent?.Invoke(this, e);
});
}