/// <summary> /// 接收消息 /// </summary> /// <param name="model"></param> /// <param name="ea"></param> private async void ReceivedMessage(object model, BasicDeliverEventArgs ea) { await subscribeHandler.HandlerAsync(ea.RoutingKey, Encoding.UTF8.GetString(ea.Body.ToArray())); //确认消费完此消息 channel.BasicAck(ea.DeliveryTag, false); }
/// <summary> /// 处理订阅信息 /// </summary> /// <param name="subscribeName"></param> /// <returns></returns> public async Task SubscribeAsync(List <string> subscribeNames) { subscribeNames.CheckNull(); foreach (var subscribeName in subscribeNames) { logger.LogInformation("开始订阅[{subscribeName}]信息", subscribeName); //订阅消息 await redis.Subscribe.SubscribeAsync(subscribeName, async (subscribeName, msg) => { //处理消息 await subscribeHandler.HandlerAsync(subscribeName, msg); }); logger.LogInformation("订阅成功[{subscribeName}]", subscribeName); } }