Skip to content

Commit

Permalink
add producer configure action
Browse files Browse the repository at this point in the history
  • Loading branch information
wanlitao committed Apr 26, 2021
1 parent 3430d41 commit 66fd32e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion NewLife.RocketMQ.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTest", "ConsoleTest\ConsoleTest.csproj", "{9380D4DB-935B-4E4C-894B-7F35B2AA8F8E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTest", "ConsoleTest\ConsoleTest.csproj", "{9380D4DB-935B-4E4C-894B-7F35B2AA8F8E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
9 changes: 6 additions & 3 deletions NewLife.RocketMQ/Extensions/ProducerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public ProducerFactory(string nameServerAddress, int topicQueueNum = 0)
/// <summary>
/// 获取Topic对应Producer
/// </summary>
public Producer GetTopicProducer(string topic)
public Producer GetTopicProducer(string topic, Action<Producer> producerConfigure = null)
{
if (topic.IsNullOrWhiteSpace())
throw new ArgumentNullException(nameof(topic));

return _topicProducerCache.GetOrAdd(topic, CreateTopicProducer);
return _topicProducerCache.GetOrAdd(topic, (key) => CreateTopicProducer(key, producerConfigure));
}

private Producer CreateTopicProducer(string topic)
private Producer CreateTopicProducer(string topic, Action<Producer> producerConfigure)
{
_masterProducer.CreateTopic(topic, _topicQueueNum);

Expand All @@ -51,6 +51,9 @@ private Producer CreateTopicProducer(string topic)
Topic = topic,
NameServerAddress = _masterProducer.NameServerAddress
};

producerConfigure?.Invoke(topicProducer);

topicProducer.Start();

return topicProducer;
Expand Down

0 comments on commit 66fd32e

Please sign in to comment.