Sfoglia il codice sorgente

modify prompted info when received message can not be found subscriber. #63

undefined
Savorboard 7 anni fa
parent
commit
1e69d71a43
3 ha cambiato i file con 34 aggiunte e 14 eliminazioni
  1. +10
    -13
      src/DotNetCore.CAP/Internal/ISubscriberExecutor.Default.cs
  2. +23
    -0
      src/DotNetCore.CAP/Internal/MethodMatcherCache.cs
  3. +1
    -1
      src/DotNetCore.CAP/Models/CapReceivedMessage.cs

+ 10
- 13
src/DotNetCore.CAP/Internal/ISubscriberExecutor.Default.cs Vedi File

@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using DotNetCore.CAP.Abstractions;
using DotNetCore.CAP.Models;
@@ -28,22 +29,18 @@ namespace DotNetCore.CAP.Internal

public async Task<OperateResult> ExecuteAsync(CapReceivedMessage receivedMessage)
{
try
if (!_selector.TryGetTopicExector(receivedMessage.Name, receivedMessage.Group,
out var executor))
{
var executeDescriptorGroup = _selector.GetTopicExector(receivedMessage.Name);

if (!executeDescriptorGroup.ContainsKey(receivedMessage.Group))
{
var error = $"Topic:{receivedMessage.Name}, can not be found subscriber method.";
throw new SubscriberNotFoundException(error);
}

// If there are multiple consumers in the same group, we will take the first
var executeDescriptor = executeDescriptorGroup[receivedMessage.Group][0];
var consumerContext = new ConsumerContext(executeDescriptor, receivedMessage.ToMessageContext());
var error = "this message can not be found subscriber. Message:" + receivedMessage;
error += "\r\n see: https://github.com/dotnetcore/CAP/issues/63";
throw new SubscriberNotFoundException(error);
}

var consumerContext = new ConsumerContext(executor, receivedMessage.ToMessageContext());
try
{
var ret = await Invoker.InvokeAsync(consumerContext);

if (!string.IsNullOrEmpty(ret.CallbackName))
await _callbackMessageSender.SendAsync(ret.MessageId, ret.CallbackName, ret.Result);



+ 23
- 0
src/DotNetCore.CAP/Internal/MethodMatcherCache.cs Vedi File

@@ -55,6 +55,29 @@ namespace DotNetCore.CAP.Internal
return dic;
}

/// <summary>
/// Attempts to get the topic exector associated with the specified topic name and group name from the <see cref="Entries"/>.
/// </summary>
/// <param name="topicName">The topic name of the value to get.</param>
/// <param name="groupName">The group name of the value to get.</param>
/// <param name="matchTopic">topic exector of the value.</param>
/// <returns>true if the key was found, otherwise false. </returns>
public bool TryGetTopicExector(string topicName, string groupName,
out ConsumerExecutorDescriptor matchTopic)
{
if (Entries == null)
throw new ArgumentNullException(nameof(Entries));

matchTopic = null;

if (Entries.TryGetValue(groupName, out var groupMatchTopics))
{
matchTopic = groupMatchTopics.FirstOrDefault(x => x.Attribute.Name == topicName);
return matchTopic != null;
}
return false;
}

/// <summary>
/// Get all subscribe topics name.
/// </summary>


+ 1
- 1
src/DotNetCore.CAP/Models/CapReceivedMessage.cs Vedi File

@@ -47,7 +47,7 @@ namespace DotNetCore.CAP.Models

public override string ToString()
{
return "name:" + Name + ", content:" + Content;
return "name:" + Name + ", group:" + Group + ", content:" + Content;
}
}
}

Caricamento…
Annulla
Salva