Commit 1e69d71a authored by Savorboard's avatar Savorboard

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

parent 2504c7af
using System; using System;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using DotNetCore.CAP.Abstractions; using DotNetCore.CAP.Abstractions;
using DotNetCore.CAP.Models; using DotNetCore.CAP.Models;
...@@ -28,22 +29,18 @@ namespace DotNetCore.CAP.Internal ...@@ -28,22 +29,18 @@ namespace DotNetCore.CAP.Internal
public async Task<OperateResult> ExecuteAsync(CapReceivedMessage receivedMessage) public async Task<OperateResult> ExecuteAsync(CapReceivedMessage receivedMessage)
{ {
try if (!_selector.TryGetTopicExector(receivedMessage.Name, receivedMessage.Group,
out var executor))
{ {
var executeDescriptorGroup = _selector.GetTopicExector(receivedMessage.Name); var error = "this message can not be found subscriber. Message:" + receivedMessage;
error += "\r\n see: https://github.com/dotnetcore/CAP/issues/63";
if (!executeDescriptorGroup.ContainsKey(receivedMessage.Group)) throw new SubscriberNotFoundException(error);
{ }
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 consumerContext = new ConsumerContext(executor, receivedMessage.ToMessageContext());
try
{
var ret = await Invoker.InvokeAsync(consumerContext); var ret = await Invoker.InvokeAsync(consumerContext);
if (!string.IsNullOrEmpty(ret.CallbackName)) if (!string.IsNullOrEmpty(ret.CallbackName))
await _callbackMessageSender.SendAsync(ret.MessageId, ret.CallbackName, ret.Result); await _callbackMessageSender.SendAsync(ret.MessageId, ret.CallbackName, ret.Result);
......
...@@ -55,6 +55,29 @@ namespace DotNetCore.CAP.Internal ...@@ -55,6 +55,29 @@ namespace DotNetCore.CAP.Internal
return dic; 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> /// <summary>
/// Get all subscribe topics name. /// Get all subscribe topics name.
/// </summary> /// </summary>
......
...@@ -47,7 +47,7 @@ namespace DotNetCore.CAP.Models ...@@ -47,7 +47,7 @@ namespace DotNetCore.CAP.Models
public override string ToString() public override string ToString()
{ {
return "name:" + Name + ", content:" + Content; return "name:" + Name + ", group:" + Group + ", content:" + Content;
} }
} }
} }
\ 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