コード例 #1
0
        public mq_published GenerateMsgEntity(IPublishQueueConfig publishQueueConfig, object message, string queryurl = null, string callbakcurl = null)
        {
            var config = publishQueueConfig as RabbitPublishQueueConfig;

            config.CheckObjectNull(nameof(config));

            var publishentity = new mq_published();

            publishentity.service_name  = options.ServiceName;
            publishentity.exchange_name = config.ExchangeName;
            publishentity.route_key     = config.RouteKey;
            publishentity.queue_name    = config.QueueName;
            if (string.IsNullOrEmpty(publishentity.exchange_name))
            {
                publishentity.exchange_name = mqoptions.DeafaultExchangeName;
            }
            if (string.IsNullOrEmpty(publishentity.route_key))
            {
                publishentity.route_key = mqoptions.DeafaultRouteKey;
            }
            if (string.IsNullOrEmpty(publishentity.queue_name))
            {
                publishentity.queue_name = mqoptions.DeafaultQueueName;
            }
            publishentity.message   = (new Message {
                MsgBody = message, CallbackUrl = callbakcurl, SourceMsgId = publishentity.id, QueueName = publishentity.queue_name
            }).ToString();
            publishentity.query_url = queryurl;
            if (config.Args != null)
            {
                publishentity.remark = JsonConvert.SerializeObject(config.Args);
            }
            return(publishentity);
        }
コード例 #2
0
        public IPublishQueueConfig GenerateQueueConfig(mq_published entity)
        {
            RabbitPublishQueueConfig rabbitQueueConfig = new RabbitPublishQueueConfig();

            if (!string.IsNullOrEmpty(entity.remark))
            {
                rabbitQueueConfig.Args = JsonConvert.DeserializeObject <Dictionary <string, object> >(entity.remark);
            }
            rabbitQueueConfig.ExchangeName = entity.exchange_name;
            rabbitQueueConfig.QueueName    = entity.queue_name;
            rabbitQueueConfig.RouteKey     = entity.route_key;
            return(rabbitQueueConfig);
        }
コード例 #3
0
 public void UpdateCallbackStatus(mq_published entity, bool queryResult, int retryCount)
 {
     if (queryResult)
     {
         entity.status = Models.Entity.published_status.处理完成;
     }
     else //没找到
     {
         if (entity.retries + 1 > retryCount)
         {
             entity.status = Models.Entity.published_status.发送失败;
         }
         else
         {
             entity.retries += 1;
             entity.status   = Models.Entity.published_status.未发送;
         }
     }
 }
コード例 #4
0
ファイル: RabbitOperate.cs プロジェクト: cysnet/mq-trans
 public MQResult DirectPublish(mq_published published)
 {
     try
     {
         var     config  = generateMsgBody.GenerateQueueConfig(published) as RabbitPublishQueueConfig;
         Message message = JsonConvert.DeserializeObject <Message>(published.message);
         message.MsgSeq = 1;
         using (var channel = mqConnection.CreateModel())
         {
             channel.ConfirmSelect();
             channel.QueueDeclare(queue: config.QueueName, durable: true, exclusive: false, autoDelete: false, arguments: config.Args);
             channel.ExchangeDeclare(config.ExchangeName, ExchangeType.Direct);
             channel.QueueBind(config.QueueName, config.ExchangeName, config.RouteKey, null);
             var properties = channel.CreateBasicProperties();
             properties.Persistent = true;
             channel.BasicPublish(exchange: config.ExchangeName, routingKey: config.RouteKey, basicProperties: properties, body: message.ToBytes());
             if (!channel.WaitForConfirms(new TimeSpan(0, 0, 5)))
             {
                 return(new MQResult()
                 {
                     IsSucess = false, ExceptionMsg = "sent message failed"
                 });
             }
             Console.WriteLine($"[P] sent_message,queue={config.QueueName},msg={message.ToString()}");
             return(new MQResult()
             {
                 IsSucess = true, ChannelNumber = channel.ChannelNumber
             });
         }
     }
     catch (Exception ex)
     {
         //记log
         return(new MQResult()
         {
             IsSucess = false, ExceptionMsg = ex.Message
         });
     }
 }
コード例 #5
0
 public void UpdateSuccessStatus(mq_published entity, int expiresMinute)
 {
     entity.status = published_status.已发送;
     //10分钟后不是“处理成功状态”,则发起查询,未查到改为“发送失败”,查到改为处理成功
     entity.expires_time = DateTime.Now.AddMinutes(expiresMinute);
 }
コード例 #6
0
 public MQResult DirectPublish(mq_published published)
 {
     return(this.mQOperate.DirectPublish(published));
 }