From 96ff6a554329170d460f8bdbfbebb78d269e5f70 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Mon, 31 Jul 2017 23:50:42 +0800 Subject: [PATCH] support multiple topic subscribe. --- .../RabbitMQConsumerClient.cs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs index 3aae748..2526e3f 100644 --- a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs +++ b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -51,6 +52,16 @@ namespace DotNetCore.CAP.RabbitMQ _channel.QueueDeclare(_queueName, exclusive: false); } + public void Subscribe(IEnumerable topics) + { + if (topics == null) throw new ArgumentNullException(nameof(topics)); + + foreach (var topic in topics) + { + _channel.QueueBind(_queueName, _exchageName, topic); + } + } + public void Listening(TimeSpan timeout, CancellationToken cancellationToken) { var consumer = new EventingBasicConsumer(_channel); @@ -63,16 +74,6 @@ namespace DotNetCore.CAP.RabbitMQ } } - public void Subscribe(string topic) - { - _channel.QueueBind(_queueName, _exchageName, topic); - } - - public void Subscribe(string topic, int partition) - { - _channel.QueueBind(_queueName, _exchageName, topic); - } - public void Commit() { _channel.BasicAck(_deliveryTag, false);