コード例 #1
0
 private void OnReceivedTaskFinishedMessage()
 {
     _channel.QueueDeclare(queue: "TaskFinishedMessage", durable: true, exclusive: false, autoDelete: false, arguments: null);
     _channel.ExchangeDeclare(exchange: "TaskFinishedMessageExchange", type: ExchangeType.Direct, durable: true, autoDelete: false, arguments: null);
     _channel.QueueBind(queue: "TaskFinishedMessage", exchange: "TaskFinishedMessageExchange", routingKey: string.Empty, arguments: null);
     try
     {
         if (_consumer == null)
         {
             _consumer = new EventingBasicConsumer(_channel);
         }
         _consumer.Received += (model, ea) =>
         {
             var body    = ea.Body;
             var message = Encoding.UTF8.GetString(body.ToArray());
             message = $"【{ConfigHelper.GetCustomerName(message)}】版本编译已完成";
             string errMsg = string.Empty;
             string path   = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "MessageBox.exe");
             JobHelper.ExecBatch(path, false, false, false, $"{message.Replace(" ", "{SPACE}")}", ref errMsg);
         };
         _channel.BasicConsume(queue: "TaskFinishedMessage",
                               autoAck: true,
                               consumer: _consumer);
     }
     catch (Exception ex)
     {
         using (StreamWriter sw = new StreamWriter(@"E:\err_msg.log", true, Encoding.UTF8))
         {
             sw.WriteLine($"接收消息队列异常:{ex.Message}-{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}");
         }
     }
 }