2016-12-05 07:00:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-11-20 13:34:50 +00:00
|
|
|
|
using System.Linq;
|
2016-11-17 16:33:27 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2016-12-11 14:08:58 +00:00
|
|
|
|
using Tapeti.Config;
|
2016-11-16 22:11:05 +00:00
|
|
|
|
|
|
|
|
|
namespace Tapeti.Connection
|
|
|
|
|
{
|
|
|
|
|
public class TapetiSubscriber : ISubscriber
|
|
|
|
|
{
|
2016-12-05 07:00:09 +00:00
|
|
|
|
private readonly Func<TapetiWorker> workerFactory;
|
2017-02-12 14:18:12 +00:00
|
|
|
|
private readonly List<IQueue> queues;
|
|
|
|
|
private bool consuming;
|
2016-11-16 22:11:05 +00:00
|
|
|
|
|
|
|
|
|
|
2017-02-12 14:18:12 +00:00
|
|
|
|
public TapetiSubscriber(Func<TapetiWorker> workerFactory, IEnumerable<IQueue> queues)
|
2016-11-16 22:11:05 +00:00
|
|
|
|
{
|
2016-12-05 07:00:09 +00:00
|
|
|
|
this.workerFactory = workerFactory;
|
2017-02-12 14:18:12 +00:00
|
|
|
|
this.queues = queues.ToList();
|
2016-11-16 22:11:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-12 14:18:12 +00:00
|
|
|
|
public Task BindQueues()
|
|
|
|
|
{
|
|
|
|
|
return Task.WhenAll(queues.Select(queue => workerFactory().Subscribe(queue)).ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-01-25 13:52:09 +00:00
|
|
|
|
public Task RebindQueues()
|
|
|
|
|
{
|
|
|
|
|
return BindQueues();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-12 14:18:12 +00:00
|
|
|
|
public Task Resume()
|
2016-11-16 22:11:05 +00:00
|
|
|
|
{
|
2017-02-12 14:18:12 +00:00
|
|
|
|
if (consuming)
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
|
|
|
|
consuming = true;
|
|
|
|
|
return Task.WhenAll(queues.Select(queue => workerFactory().Consume(queue.Name, queue.Bindings)).ToList());
|
2016-11-16 22:11:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|