Пример #1
0
 public HpScheduleJob(string rabbitmq_url, string jobKey)
 {
     this.rabbitmq_url = rabbitmq_url;
     this.jobKey       = jobKey;
     //创建MQ工厂
     this.mFactory = new WorkQueueFactory(rabbitmq_url);
 }
        public static IMQFactory AddRabbitMQ(this IMQFactory factory, Action <RabbitMQOptions> action)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            RabbitMQOptions options = new RabbitMQOptions();

            action?.Invoke(options);

            factory.AddProvider(new RabbitMQProvider(options));
            return(factory);
        }
Пример #3
0
        private bool sendMsg(string message, int?progress)
        {
            IMQFactory factory = null;

            if (!mFactory.TryGetTarget(out factory))
            {
                return(false);
            }

            HpSchedulerJob.NET.Foundation.Log.i(String.Format("Task({0}) ::: send message = {1}, progress = {2}", this.taskid, message, progress == null ? "null" : progress.ToString()));

            try
            {
                CallBackModel callback = new CallBackModel()
                {
                    task_id  = this.taskid,
                    message  = message,
                    progress = progress,
                    time     = DateTimeUtil.timestamp(DateTime.Now)// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
                };

                var jsonstr = JsonConvert.SerializeObject(callback);

                using (var producer = factory.CreateMqProducer(routingkey))
                {
                    producer.sendMessage(jsonstr);
                }

                return(true);
            }
            catch (Exception ex)
            {
                HpSchedulerJob.NET.Foundation.Log.e(ex);
                return(false);
            }
        }
 public static IMQFactory AddRabbitMQ(this IMQFactory factory)
 {
     return(AddRabbitMQ(factory, null));
 }
Пример #5
0
 internal HpScheduleContext(IMQFactory factory)
 {
     this.mFactory = new WeakReference <IMQFactory>(factory);
 }