Skip to content

Commit 85fb2ff

Browse files
Merge pull request #4 from hetaoos/master
Create a separate message for each consumption.
2 parents d95d06e + 91529c8 commit 85fb2ff

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/Savorboard.CAP.InMemoryMessageQueue/InMemoryConsumerClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void Subscribe(IEnumerable<string> topics)
3737
{
3838
_queue.Subscribe(_groupId, OnConsumerReceived, topic);
3939

40-
_logger.LogInformation($"InMemory message queue initialize the topic: {topic}");
40+
_logger.LogInformation($"InMemory message queue initialize the topic: {_groupId} {topic}");
4141
}
4242
}
4343

src/Savorboard.CAP.InMemoryMessageQueue/InMemoryQueue.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using DotNetCore.CAP.Messages;
45
using Microsoft.Extensions.Logging;
56

@@ -44,19 +45,18 @@ public void ClearSubscriber()
4445

4546
public void Send(TransportMessage message)
4647
{
47-
foreach (var groupTopic in _groupTopics)
48+
var name = message.GetName();
49+
foreach (var groupTopic in _groupTopics.Where(o => o.Value.Item2.Contains(name)))
4850
{
49-
if (groupTopic.Value.Item2.Contains(message.GetName()))
51+
try
5052
{
51-
try
52-
{
53-
message.Headers[Headers.Group] = groupTopic.Key;
54-
groupTopic.Value.Item1?.Invoke(message);
55-
}
56-
catch (Exception e)
57-
{
58-
_logger.LogError(e, $"Consumption message raises an exception. Group-->{groupTopic.Key} Name-->{message.GetName()}");
59-
}
53+
var message_copy = new TransportMessage(message.Headers.ToDictionary(o => o.Key, o => o.Value), message.Body);
54+
message_copy.Headers[Headers.Group] = groupTopic.Key;
55+
groupTopic.Value.Item1?.Invoke(message_copy);
56+
}
57+
catch (Exception e)
58+
{
59+
_logger.LogError(e, $"Consumption message raises an exception. Group-->{groupTopic.Key} Name-->{name}");
6060
}
6161
}
6262
}

0 commit comments

Comments
 (0)