コード例 #1
0
        /// 接收新增订单
        public void NewOrderRequestHandle(Initials Init)
        {
            EventingBasicConsumer consumer = new EventingBasicConsumer(channel2);

            consumer.Received += (model, ea) =>
            {
                var body = ea.Body;
                try
                {
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(message);
                    RequestClass request = Newtonsoft.Json.JsonConvert.DeserializeObject <RequestClass>(message);
                    //OrderChangePosition(Init, request.businessType, request.entrust_direction, request.futures_direction, request.entrust_no, request.code, request.entrust_amount);
                    if (request.businessType == "0")
                    {
                        var pl = MQServer.AlivedOrder.Where(o => o.entrust_no == request.entrust_no).FirstOrDefault();
                        MQServer.AlivedOrder.Where(o => o.entrust_no == request.entrust_no).Take(1);
                        pl.businessType = "0";
                        pl.clordId      = request.clordId;
                        MQServer.AlivedOrder.Add(pl);
                    }
                    else
                    {
                        MQServer.AlivedOrder.Add(request);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                finally
                {
                    AckMsg();
                }

                void AckMsg()
                {
                    try
                    {
                        channel2.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                    }
                    catch (System.IO.IOException ioex)
                    {
                        AckMsg();
                    }
                }
            };
            channel2.BasicConsume(queue: Funs.CONFIG.OrderStateQueueName, autoAck: false, consumer: consumer);
        }

        #endregion
    }
コード例 #2
0
 // 发布订单更新
 public static void PublishMsg(RequestClass request, IModel channel, Initials Init)
 {
     try
     {
         string responsestring = Newtonsoft.Json.JsonConvert.SerializeObject(request);
         var    responseBytes  = Encoding.UTF8.GetBytes(responsestring);
         channel.BasicPublish(exchange: "", routingKey: request.queue_name, basicProperties: null, body: responseBytes);
         Init.db.Insertable(request).ExecuteCommand();
         Console.WriteLine($"状态更新 :{responsestring}");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }