public async Task <string> InternalSubscribeAsync(string subject, string queueGroup, Func <NATSMsgSubscriptionConfig, SubscriptionMessageHandler> messageHandlerSetup, int?maxMsg = null, string subscribeId = null) { await ConnectAsync(); var SubscribeId = subscribeId ?? $"sid{Interlocked.Increment(ref _subscribeId)}"; _logger.LogDebug($"设置订阅消息队列订阅编号 Subject = {subject} QueueGroup = {queueGroup} SubscribeId = {SubscribeId}"); var SubscriptionConfig = new NATSMsgSubscriptionConfig(subject, SubscribeId, queueGroup, maxMsg); //处理订阅响应的管道 var messageHandler = messageHandlerSetup(SubscriptionConfig); _logger.LogDebug($"开始添加消息队列处理器 Subject = {subject} QueueGroup = {queueGroup} SubscribeId = {SubscribeId}"); //添加订阅响应管道 _embed_channel.Pipeline.AddLast(messageHandler); _logger.LogDebug($"结束添加消息队列处理器 Subject = {subject} QueueGroup = {queueGroup} SubscribeId = {SubscribeId}"); _logger.LogDebug($"开始发送订阅请求 订阅主题 {subject } 订阅编号 {SubscribeId}"); var SubscribePacketMsg = new SubscribePacket(SubscribeId, subject, queueGroup); await _embed_channel.WriteAndFlushAsync(SubscribePacketMsg); _logger.LogDebug($"结束发送订阅请求 订阅主题 {subject } 订阅编号 {SubscribeId}"); //添加消息处理到消息处理集合 _subscriptionMessageHandler.Add(messageHandler); return(SubscribeId); }
public SubscriptionMessageSyncHandler( ILogger logger, NATSMsgSubscriptionConfig subscriptionConfig, Action <NATSMsgContent> messageHandler) : base(logger, subscriptionConfig) { _messageHandler = messageHandler; }
public SubscriptionMessageAsynHandler( ILogger logger, NATSMsgSubscriptionConfig subscriptionConfig, Func <NATSMsgContent, ValueTask> messageHandler) : base(logger, subscriptionConfig) { _messageHandler = messageHandler; }
public SubscriptionMessageSyncHandler( ILogger logger, NATSMsgSubscriptionConfig subscriptionConfig, Action <NATSMsgContent> messageHandler, Func <NATSMsgSubscriptionConfig, Task> unSubscriptionCallback) : base(logger, subscriptionConfig, unSubscriptionCallback) { _messageHandler = messageHandler; }
public async Task UnSubscribeAsync(NATSMsgSubscriptionConfig subscriptionConfig) { await _policy.ExecuteAsync(async (content) => { await ConnectAsync(); var UnSubscribePacket = new UnSubscribePacket(subscriptionConfig.SubscribeId); await _embed_channel.WriteAndFlushAsync(UnSubscribePacket); }, new Dictionary <string, object>() { { "hld", "UnSubscribeAsync" } }); }
public SubscriptionMessageHandler( ILogger logger, NATSMsgSubscriptionConfig subscriptionConfig, Func <NATSMsgSubscriptionConfig, Task> unSubscriptionCallback = null) : base(logger) { _subscriptionConfig = subscriptionConfig; _unSubscriptionCallback = unSubscriptionCallback; if (subscriptionConfig.MaxMsg.HasValue) { _messageHandler = LimitedMessageHandler; } else { _messageHandler = EndlessMessageHandler; } }