Commit 019baee2 authored by Savorboard's avatar Savorboard

add default group name configuartion to CapOptions.

parent e21cdd13
...@@ -20,9 +20,10 @@ namespace DotNetCore.CAP.Abstractions ...@@ -20,9 +20,10 @@ namespace DotNetCore.CAP.Abstractions
public string Name { get; } public string Name { get; }
/// <summary> /// <summary>
/// Default group name is CapOptions setting.(Assembly name)
/// kafka --> groups.id /// kafka --> groups.id
/// rabbit MQ --> queue.name /// rabbit MQ --> queue.name
/// </summary> /// </summary>
public string Group { get; set; } = "cap.default.group"; public string Group { get; set; }
} }
} }
\ No newline at end of file
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using DotNetCore.CAP.Models; using DotNetCore.CAP.Models;
namespace DotNetCore.CAP namespace DotNetCore.CAP
...@@ -34,6 +35,7 @@ namespace DotNetCore.CAP ...@@ -34,6 +35,7 @@ namespace DotNetCore.CAP
/// </summary> /// </summary>
public const int DefaultFailedRetryCount = 100; public const int DefaultFailedRetryCount = 100;
public CapOptions() public CapOptions()
{ {
PollingDelay = DefaultPollingDelay; PollingDelay = DefaultPollingDelay;
...@@ -42,10 +44,16 @@ namespace DotNetCore.CAP ...@@ -42,10 +44,16 @@ namespace DotNetCore.CAP
FailedRetryInterval = DefaultFailedMessageWaitingInterval; FailedRetryInterval = DefaultFailedMessageWaitingInterval;
FailedRetryCount = DefaultFailedRetryCount; FailedRetryCount = DefaultFailedRetryCount;
Extensions = new List<ICapOptionsExtension>(); Extensions = new List<ICapOptionsExtension>();
DefaultGroup = "cap.queue." + Assembly.GetEntryAssembly().GetName().Name.ToLower();
} }
internal IList<ICapOptionsExtension> Extensions { get; } internal IList<ICapOptionsExtension> Extensions { get; }
/// <summary>
/// Subscriber default group name. kafka-->group name. rabbitmq --> queue name.
/// </summary>
public string DefaultGroup { get; set; }
/// <summary> /// <summary>
/// Producer job polling delay time. /// Producer job polling delay time.
/// Default is 15 sec. /// Default is 15 sec.
......
...@@ -10,23 +10,26 @@ namespace DotNetCore.CAP.Internal ...@@ -10,23 +10,26 @@ namespace DotNetCore.CAP.Internal
{ {
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
/// A default <see cref="T:DotNetCore.CAP.Abstractions.IConsumerServiceSelector" /> implementation. /// A default <see cref="T:DotNetCore.CAP.Abstractions.IConsumerServiceSelector" /> implementation.
/// </summary> /// </summary>
internal class DefaultConsumerServiceSelector : IConsumerServiceSelector internal class DefaultConsumerServiceSelector : IConsumerServiceSelector
{ {
private readonly CapOptions _capOptions;
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
/// <summary> /// <summary>
/// Creates a new <see cref="DefaultConsumerServiceSelector" />. /// Creates a new <see cref="DefaultConsumerServiceSelector" />.
/// </summary> /// </summary>
public DefaultConsumerServiceSelector(IServiceProvider serviceProvider) public DefaultConsumerServiceSelector(IServiceProvider serviceProvider, CapOptions capOptions)
{ {
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_capOptions = capOptions;
} }
/// <summary> /// <summary>
/// Selects the best <see cref="ConsumerExecutorDescriptor" /> candidate from <paramref name="executeDescriptor" /> for the /// Selects the best <see cref="ConsumerExecutorDescriptor" /> candidate from <paramref name="executeDescriptor" /> for
/// current message associated. /// the
/// current message associated.
/// </summary> /// </summary>
public ConsumerExecutorDescriptor SelectBestCandidate(string key, public ConsumerExecutorDescriptor SelectBestCandidate(string key,
IReadOnlyList<ConsumerExecutorDescriptor> executeDescriptor) IReadOnlyList<ConsumerExecutorDescriptor> executeDescriptor)
...@@ -45,7 +48,7 @@ namespace DotNetCore.CAP.Internal ...@@ -45,7 +48,7 @@ namespace DotNetCore.CAP.Internal
return executorDescriptorList; return executorDescriptorList;
} }
private static IEnumerable<ConsumerExecutorDescriptor> FindConsumersFromInterfaceTypes( private IEnumerable<ConsumerExecutorDescriptor> FindConsumersFromInterfaceTypes(
IServiceProvider provider) IServiceProvider provider)
{ {
var executorDescriptorList = new List<ConsumerExecutorDescriptor>(); var executorDescriptorList = new List<ConsumerExecutorDescriptor>();
...@@ -66,7 +69,7 @@ namespace DotNetCore.CAP.Internal ...@@ -66,7 +69,7 @@ namespace DotNetCore.CAP.Internal
} }
} }
private static IEnumerable<ConsumerExecutorDescriptor> FindConsumersFromControllerTypes() private IEnumerable<ConsumerExecutorDescriptor> FindConsumersFromControllerTypes()
{ {
var executorDescriptorList = new List<ConsumerExecutorDescriptor>(); var executorDescriptorList = new List<ConsumerExecutorDescriptor>();
...@@ -81,18 +84,21 @@ namespace DotNetCore.CAP.Internal ...@@ -81,18 +84,21 @@ namespace DotNetCore.CAP.Internal
return executorDescriptorList; return executorDescriptorList;
} }
private static IEnumerable<ConsumerExecutorDescriptor> GetTopicAttributesDescription(TypeInfo typeInfo) private IEnumerable<ConsumerExecutorDescriptor> GetTopicAttributesDescription(TypeInfo typeInfo)
{ {
foreach (var method in typeInfo.DeclaredMethods) foreach (var method in typeInfo.DeclaredMethods)
{ {
var topicAttr = method.GetCustomAttributes<TopicAttribute>(true); var topicAttr = method.GetCustomAttributes<TopicAttribute>(true);
var topicAttributes = topicAttr as IList<TopicAttribute> ?? topicAttr.ToList(); var topicAttributes = topicAttr as IList<TopicAttribute> ?? topicAttr.ToList();
if (!topicAttributes.Any()) continue; if (!topicAttributes.Any()) continue;
foreach (var attr in topicAttributes) foreach (var attr in topicAttributes)
{
if (attr.Group == null)
attr.Group = _capOptions.DefaultGroup;
yield return InitDescriptor(attr, method, typeInfo); yield return InitDescriptor(attr, method, typeInfo);
}
} }
} }
......
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