Procházet zdrojové kódy

fix multiple subscribing only received one message bug.

master
Savorboard před 7 roky
rodič
revize
f8759398a8
3 změnil soubory, kde provedl 11 přidání a 14 odebrání
  1. +7
    -7
      src/DotNetCore.CAP.Kafka/KafkaConsumerClient.cs
  2. +2
    -3
      src/DotNetCore.CAP/IConsumerClient.cs
  3. +2
    -4
      src/DotNetCore.CAP/IConsumerHandler.Default.cs

+ 7
- 7
src/DotNetCore.CAP.Kafka/KafkaConsumerClient.cs Zobrazit soubor

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Confluent.Kafka;
@@ -25,19 +26,18 @@ namespace DotNetCore.CAP.Kafka
StringDeserializer = new StringDeserializer(Encoding.UTF8);
}

public void Subscribe(string topic)
public void Subscribe(IEnumerable<string> topics)
{
Subscribe(topic, 0);
}
if (topics == null)
throw new ArgumentNullException(nameof(topics));

public void Subscribe(string topicName, int partition)
{
if (_consumerClient == null)
{
InitKafkaClient();
}
_consumerClient.Assignment.Add(new TopicPartition(topicName, partition));
_consumerClient.Subscribe(topicName);

//_consumerClient.Assign(topics.Select(x=> new TopicPartition(x, 0)));
_consumerClient.Subscribe(topics);
}

public void Listening(TimeSpan timeout, CancellationToken cancellationToken)


+ 2
- 3
src/DotNetCore.CAP/IConsumerClient.cs Zobrazit soubor

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading;

namespace DotNetCore.CAP
@@ -8,9 +9,7 @@ namespace DotNetCore.CAP
/// </summary>
public interface IConsumerClient : IDisposable
{
void Subscribe(string topic);

void Subscribe(string topic, int partition);
void Subscribe(IEnumerable<string> topics);

void Listening(TimeSpan timeout, CancellationToken cancellationToken);



+ 2
- 4
src/DotNetCore.CAP/IConsumerHandler.Default.cs Zobrazit soubor

@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DotNetCore.CAP.Infrastructure;
@@ -56,10 +57,7 @@ namespace DotNetCore.CAP
{
RegisterMessageProcessor(client);

foreach (var item in matchGroup.Value)
{
client.Subscribe(item.Attribute.Name);
}
client.Subscribe(matchGroup.Value.Select(x => x.Attribute.Name));

client.Listening(_pollingDelay, _cts.Token);
}


Načítá se…
Zrušit
Uložit