Browse Source

refactor

master
yangxiaodong 7 years ago
parent
commit
904a6933be
1 changed files with 13 additions and 6 deletions
  1. +13
    -6
      src/Cap.Consistency/Internal/ConsumerExcutorSelector.cs

+ 13
- 6
src/Cap.Consistency/Internal/ConsumerExcutorSelector.cs View File

@@ -14,13 +14,16 @@ namespace Cap.Consistency.Internal
{ {
public class ConsumerExcutorSelector : IConsumerExcutorSelector public class ConsumerExcutorSelector : IConsumerExcutorSelector
{ {
public ConsumerExecutorDescriptor SelectBestCandidate(TopicRouteContext context,
IReadOnlyList<ConsumerExecutorDescriptor> executeDescriptor) {
private readonly IServiceProvider _serviceProvider;


var key = context.Message.MessageKey;
public ConsumerExcutorSelector(IServiceProvider serviceProvider) {
_serviceProvider = serviceProvider;
}

public ConsumerExecutorDescriptor SelectBestCandidate(string key, IReadOnlyList<ConsumerExecutorDescriptor> executeDescriptor) {
return executeDescriptor.FirstOrDefault(x => x.Topic.Name == key); return executeDescriptor.FirstOrDefault(x => x.Topic.Name == key);
} }
public IReadOnlyList<ConsumerExecutorDescriptor> SelectCandidates(TopicRouteContext context) { public IReadOnlyList<ConsumerExecutorDescriptor> SelectCandidates(TopicRouteContext context) {


var consumerServices = context.ServiceProvider.GetServices<IConsumerService>(); var consumerServices = context.ServiceProvider.GetServices<IConsumerService>();
@@ -37,16 +40,20 @@ namespace Cap.Consistency.Internal
var topicAttr = method.GetCustomAttribute<TopicAttribute>(true); var topicAttr = method.GetCustomAttribute<TopicAttribute>(true);
if (topicAttr == null) continue; if (topicAttr == null) continue;


executorDescriptorList.Add(InitDescriptor(topicAttr));
executorDescriptorList.Add(InitDescriptor(topicAttr, method, typeInfo));
} }
} }


return executorDescriptorList; return executorDescriptorList;
} }
private ConsumerExecutorDescriptor InitDescriptor(TopicAttribute attr) {
private ConsumerExecutorDescriptor InitDescriptor(TopicAttribute attr,
MethodInfo methodInfo, TypeInfo implType
) {
var descriptor = new ConsumerExecutorDescriptor(); var descriptor = new ConsumerExecutorDescriptor();


descriptor.Topic = new TopicInfo(attr.Name); descriptor.Topic = new TopicInfo(attr.Name);
descriptor.MethodInfo = methodInfo;
descriptor.ImplTypeInfo = implType;


return descriptor; return descriptor;
} }


Loading…
Cancel
Save