add event loadbalancing

This commit is contained in:
2024-07-27 01:33:17 +08:00
parent 1ee8d941e9
commit 683cf9176a
2 changed files with 12 additions and 1 deletions
+6
View File
@@ -13,6 +13,12 @@ public class SimApiSynapseOptions
public string? AppId { get; set; } public string? AppId { get; set; }
public int RpcTimeout { get; set; } = 3; public int RpcTimeout { get; set; } = 3;
/// <summary>
/// Event是否使用负载均衡
/// 也就是订阅$queue主题,消息会分发给不同的AppId
/// 如果false,多个AppId都可以同时收到消息
/// </summary>
public bool EventLoadBalancing { get; set; } = false;
public bool EnableConfigStore { get; set; } = true; public bool EnableConfigStore { get; set; } = true;
public bool DisableEventClient { get; set; } = false; public bool DisableEventClient { get; set; } = false;
public bool DisableRpcClient { get; set; } = false; public bool DisableRpcClient { get; set; } = false;
+6 -1
View File
@@ -53,7 +53,12 @@ public partial class Synapse
}; };
foreach (var ev in EventRegistry) foreach (var ev in EventRegistry)
{ {
var topic = $"$queue/{esTopicPrefix}{ev.Key}";
var topic = $"{esTopicPrefix}{ev.Key}";
if (Options.EventLoadBalancing)
{
topic = "$queue/" + topic;
}
var evSubOpts = MqttFactory.CreateSubscribeOptionsBuilder() var evSubOpts = MqttFactory.CreateSubscribeOptionsBuilder()
.WithTopicFilter(o => o.WithTopic(topic)).Build(); .WithTopicFilter(o => o.WithTopic(topic)).Build();
Client.SubscribeAsync(evSubOpts).Wait(); Client.SubscribeAsync(evSubOpts).Wait();