Commit bc36b3d4 authored by yangxiaodong's avatar yangxiaodong

update

parent ad7abc50
...@@ -11,8 +11,6 @@ namespace Cap.Consistency.Abstractions ...@@ -11,8 +11,6 @@ namespace Cap.Consistency.Abstractions
public TypeInfo ImplTypeInfo { get; set; } public TypeInfo ImplTypeInfo { get; set; }
public TopicInfo Topic { get; set; } public TopicAttribute Attribute { get; set; }
public string GroupId { get; set; }
} }
} }
...@@ -18,6 +18,8 @@ namespace Cap.Consistency.Abstractions ...@@ -18,6 +18,8 @@ namespace Cap.Consistency.Abstractions
get { return _name; } get { return _name; }
} }
public string GroupOrExchange { get; set; }
public bool IsOneWay { get; set; } public bool IsOneWay { get; set; }
} }
} }
...@@ -27,8 +27,6 @@ namespace Cap.Consistency ...@@ -27,8 +27,6 @@ namespace Cap.Consistency
Services = service; Services = service;
AddConsumerServices(); AddConsumerServices();
AddKafkaServices();
} }
/// <summary> /// <summary>
...@@ -70,13 +68,10 @@ namespace Cap.Consistency ...@@ -70,13 +68,10 @@ namespace Cap.Consistency
Services.AddSingleton<IConsumerInvokerFactory, ConsumerInvokerFactory>(); Services.AddSingleton<IConsumerInvokerFactory, ConsumerInvokerFactory>();
Services.AddSingleton<MethodMatcherCache>(); Services.AddSingleton<MethodMatcherCache>();
return this; Services.AddSingleton(typeof(ITopicRoute), typeof(ConsumerHandler<>).MakeGenericType(MessageType));
}
public virtual ConsistencyBuilder AddKafkaServices() {
return AddScoped(typeof(ITopicRoute), typeof(ConsumerHandler<>).MakeGenericType(MessageType)); return this;
} }
/// <summary> /// <summary>
......
...@@ -5,10 +5,9 @@ using System.Threading.Tasks; ...@@ -5,10 +5,9 @@ using System.Threading.Tasks;
using Cap.Consistency.Abstractions; using Cap.Consistency.Abstractions;
using Cap.Consistency.Infrastructure; using Cap.Consistency.Infrastructure;
using Cap.Consistency.Routing; using Cap.Consistency.Routing;
using Microsoft.AspNetCore.Builder; using Cap.Consistency.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Cap.Consistency.Internal;
namespace Cap.Consistency.Consumer namespace Cap.Consistency.Consumer
{ {
...@@ -59,18 +58,20 @@ namespace Cap.Consistency.Consumer ...@@ -59,18 +58,20 @@ namespace Cap.Consistency.Consumer
var matchs = _selector.GetCandidatesMethods(context); var matchs = _selector.GetCandidatesMethods(context);
var groupingMatchs = matchs.GroupBy(x => x.Value.GroupId); var groupingMatchs = matchs.GroupBy(x => x.Value.Attribute.GroupOrExchange);
foreach (var matchGroup in groupingMatchs) { foreach (var matchGroup in groupingMatchs) {
using (var client = _consumerClientFactory.Create(matchGroup.Key, _options.BrokerUrlList)) { Task.Factory.StartNew(() => {
client.MessageReceieved += OnMessageReceieved; using (var client = _consumerClientFactory.Create(matchGroup.Key, _options.BrokerUrlList)) {
client.MessageReceieved += OnMessageReceieved;
foreach (var item in matchGroup) { foreach (var item in matchGroup) {
client.Subscribe(item.Key, item.Value.Topic.Partition); client.Subscribe(item.Key);
} }
client.Listening(TimeSpan.Zero); client.Listening(TimeSpan.FromSeconds(1));
} }
}, TaskCreationOptions.LongRunning);
} }
return Task.CompletedTask; return Task.CompletedTask;
} }
...@@ -100,8 +101,6 @@ namespace Cap.Consistency.Consumer ...@@ -100,8 +101,6 @@ namespace Cap.Consistency.Consumer
catch (Exception ex) { catch (Exception ex) {
_logger.LogError("exception raised when excute method : " + ex.Message); _logger.LogError("exception raised when excute method : " + ex.Message);
throw ex;
} }
} }
} }
......
using Cap.Consistency;
namespace Cap.Consistency.Infrastructure
{
/// <summary>
/// Represents all the options you can use to configure the system.
/// </summary>
public class ConsistencyOptions
{
public string BrokerUrlList { get; set; } = "localhost:9092";
}
}
\ No newline at end of file
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