Browse Source

add default group name configuartion to CapOptions.

undefined
Savorboard 7 years ago
parent
commit
019baee29e
3 changed files with 25 additions and 10 deletions
  1. +2
    -1
      src/DotNetCore.CAP/Abstractions/TopicAttribute.cs
  2. +8
    -0
      src/DotNetCore.CAP/CAP.Options.cs
  3. +15
    -9
      src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs

+ 2
- 1
src/DotNetCore.CAP/Abstractions/TopicAttribute.cs View File

@@ -20,9 +20,10 @@ namespace DotNetCore.CAP.Abstractions
public string Name { get; }

/// <summary>
/// Default group name is CapOptions setting.(Assembly name)
/// kafka --> groups.id
/// rabbit MQ --> queue.name
/// </summary>
public string Group { get; set; } = "cap.default.group";
public string Group { get; set; }
}
}

+ 8
- 0
src/DotNetCore.CAP/CAP.Options.cs View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using DotNetCore.CAP.Models;

namespace DotNetCore.CAP
@@ -34,6 +35,7 @@ namespace DotNetCore.CAP
/// </summary>
public const int DefaultFailedRetryCount = 100;


public CapOptions()
{
PollingDelay = DefaultPollingDelay;
@@ -42,10 +44,16 @@ namespace DotNetCore.CAP
FailedRetryInterval = DefaultFailedMessageWaitingInterval;
FailedRetryCount = DefaultFailedRetryCount;
Extensions = new List<ICapOptionsExtension>();
DefaultGroup = "cap.queue." + Assembly.GetEntryAssembly().GetName().Name.ToLower();
}

internal IList<ICapOptionsExtension> Extensions { get; }

/// <summary>
/// Subscriber default group name. kafka-->group name. rabbitmq --> queue name.
/// </summary>
public string DefaultGroup { get; set; }

/// <summary>
/// Producer job polling delay time.
/// Default is 15 sec.


+ 15
- 9
src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs View File

@@ -10,23 +10,26 @@ namespace DotNetCore.CAP.Internal
{
/// <inheritdoc />
/// <summary>
/// A default <see cref="T:DotNetCore.CAP.Abstractions.IConsumerServiceSelector" /> implementation.
/// A default <see cref="T:DotNetCore.CAP.Abstractions.IConsumerServiceSelector" /> implementation.
/// </summary>
internal class DefaultConsumerServiceSelector : IConsumerServiceSelector
{
private readonly CapOptions _capOptions;
private readonly IServiceProvider _serviceProvider;

/// <summary>
/// Creates a new <see cref="DefaultConsumerServiceSelector" />.
/// Creates a new <see cref="DefaultConsumerServiceSelector" />.
/// </summary>
public DefaultConsumerServiceSelector(IServiceProvider serviceProvider)
public DefaultConsumerServiceSelector(IServiceProvider serviceProvider, CapOptions capOptions)
{
_serviceProvider = serviceProvider;
_capOptions = capOptions;
}

/// <summary>
/// Selects the best <see cref="ConsumerExecutorDescriptor" /> candidate from <paramref name="executeDescriptor" /> for the
/// current message associated.
/// Selects the best <see cref="ConsumerExecutorDescriptor" /> candidate from <paramref name="executeDescriptor" /> for
/// the
/// current message associated.
/// </summary>
public ConsumerExecutorDescriptor SelectBestCandidate(string key,
IReadOnlyList<ConsumerExecutorDescriptor> executeDescriptor)
@@ -45,7 +48,7 @@ namespace DotNetCore.CAP.Internal
return executorDescriptorList;
}

private static IEnumerable<ConsumerExecutorDescriptor> FindConsumersFromInterfaceTypes(
private IEnumerable<ConsumerExecutorDescriptor> FindConsumersFromInterfaceTypes(
IServiceProvider provider)
{
var executorDescriptorList = new List<ConsumerExecutorDescriptor>();
@@ -66,7 +69,7 @@ namespace DotNetCore.CAP.Internal
}
}

private static IEnumerable<ConsumerExecutorDescriptor> FindConsumersFromControllerTypes()
private IEnumerable<ConsumerExecutorDescriptor> FindConsumersFromControllerTypes()
{
var executorDescriptorList = new List<ConsumerExecutorDescriptor>();

@@ -81,18 +84,21 @@ namespace DotNetCore.CAP.Internal
return executorDescriptorList;
}

private static IEnumerable<ConsumerExecutorDescriptor> GetTopicAttributesDescription(TypeInfo typeInfo)
private IEnumerable<ConsumerExecutorDescriptor> GetTopicAttributesDescription(TypeInfo typeInfo)
{
foreach (var method in typeInfo.DeclaredMethods)
{
var topicAttr = method.GetCustomAttributes<TopicAttribute>(true);

var topicAttributes = topicAttr as IList<TopicAttribute> ?? topicAttr.ToList();

if (!topicAttributes.Any()) continue;

foreach (var attr in topicAttributes)
{
if (attr.Group == null)
attr.Group = _capOptions.DefaultGroup;
yield return InitDescriptor(attr, method, typeInfo);
}
}
}



Loading…
Cancel
Save