Commit e0de7a16 authored by yangxiaodong's avatar yangxiaodong

fixed kafka client bugs.

parent ca38bff1
...@@ -10,6 +10,9 @@ namespace DotNetCore.CAP ...@@ -10,6 +10,9 @@ namespace DotNetCore.CAP
/// </summary> /// </summary>
public class KafkaOptions public class KafkaOptions
{ {
private IEnumerable<KeyValuePair<string, object>> _kafkaConfig;
public KafkaOptions() public KafkaOptions()
{ {
MainConfig = new Dictionary<string, object>(); MainConfig = new Dictionary<string, object>();
...@@ -33,23 +36,21 @@ namespace DotNetCore.CAP ...@@ -33,23 +36,21 @@ namespace DotNetCore.CAP
internal IEnumerable<KeyValuePair<string, object>> AskafkaConfig() internal IEnumerable<KeyValuePair<string, object>> AskafkaConfig()
{ {
if (MainConfig.ContainsKey("bootstrap.servers")) if (_kafkaConfig == null)
{
return MainConfig.AsEnumerable();
}
if (string.IsNullOrWhiteSpace(Servers))
{ {
throw new ArgumentNullException(nameof(Servers)); if (string.IsNullOrWhiteSpace(Servers))
} {
throw new ArgumentNullException(nameof(Servers));
}
MainConfig.Add("bootstrap.servers", Servers); MainConfig["bootstrap.servers"] = Servers;
MainConfig["queue.buffering.max.ms"] = "10";
MainConfig["socket.blocking.max.ms"] = "10";
MainConfig["enable.auto.commit"] = "false";
MainConfig["queue.buffering.max.ms"] = "10"; _kafkaConfig = MainConfig.AsEnumerable();
MainConfig["socket.blocking.max.ms"] = "10"; }
MainConfig["enable.auto.commit"] = "false"; return _kafkaConfig;
return MainConfig.AsEnumerable();
} }
} }
} }
\ No newline at end of file
...@@ -63,7 +63,7 @@ namespace DotNetCore.CAP.Kafka ...@@ -63,7 +63,7 @@ namespace DotNetCore.CAP.Kafka
private void InitKafkaClient() private void InitKafkaClient()
{ {
_kafkaOptions.MainConfig.Add("group.id", _groupId); _kafkaOptions.MainConfig["group.id"] = _groupId;
var config = _kafkaOptions.AskafkaConfig(); var config = _kafkaOptions.AskafkaConfig();
_consumerClient = new Consumer<Null, string>(config, null, StringDeserializer); _consumerClient = new Consumer<Null, string>(config, null, StringDeserializer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment