public static void CreateMessage(string content, string serverHost, string strTopic, string strkey, string strTag) { try { //mq对象 using (var mq = new Producer() { Topic = strTopic, NameServerAddress = serverHost, }) { mq.Start(); CommonTools.Logs.LogInfo("连接服务器成功,准备发送消息!"); for (int i = 0; i < 3; i++) { try { CommonTools.Logs.LogInfo($"第{(i + 1).ToString()}次尝试发送消息!"); var sr = mq.Publish(content, strTag, strkey); string log = $"发送成功的消息:>{strTopic}-{serverHost}-{content}"; CommonTools.Logs.LogInfo(log); break; } catch (Exception ex) { CommonTools.Logs.LogError(ex); } Thread.Sleep(3000); } mq.Stop(); } } catch (Exception ex) { CommonTools.Logs.LogError(ex); } } }
标签:CommonTools,string,C#,发送,mq,ex,RocketMQ,Logs From: https://www.cnblogs.com/yangxk666/p/17888336.html