Пример #1
0
        public void SendMessage(CallBackMessage message, string messageId)
        {
            var messageBody = JsonConvert.SerializeObject(message);
            var brokerMessage = new BrokeredMessage(messageBody);
            brokerMessage.MessageId = messageId;

            QueueClient.Send(brokerMessage);
        }
Пример #2
0
        protected void ProcessMessage(CallBackMessage message)
        {
            try
            {
                var callBackMessageProcessor = new CallBackMessageProcessor(_consumerEventLog);

                callBackMessageProcessor.ProcessCallBackMessage(message);
            }
            catch (Exception e)
            {
                _consumerEventLog.WriteEntry("Error to process message (" + message.JobId+"): "+e.Message+".\n" + e.StackTrace);
            }
        }
        public void ProcessCallBackMessage(CallBackMessage message)
        {
            var result = PostManager.PostRequest(message.Url, message.PlayLoad);

            if (result.Success)
            {
                UpdateJobStatus(message.JobId, message.UpdateJobStatusUrl, ResultStatus.Success);
            }
            else
            {
                UpdateJobStatus(message.JobId, message.UpdateJobStatusUrl, ResultStatus.Error);
                var msg = GetBadResultMessage(result.Result);

                _consumerEventLog.WriteEntry("Fail to update job status (" + message.JobId +"): "+msg);
            }

            CompleteJob(message.JobId, message.CompleteJobUrl);
        }
Пример #4
0
        public JobDetail CreateJob(JobDetail detail, string doJobUrl, string updateStatusUrl, string completeJobUrl)
        {
            var job = new Job()
            {
                Id = Guid.NewGuid(),
                RequestDateTime = detail.RequestDateTime,
                CompletedDateTime = detail.CompletedDateTime
            };

            job = MyDbContext.Jobs.Add(job);
            MyDbContext.SaveChanges();

            try
            {
                var messageSender = new MessageSender("testqueue");
                var callBackMessage = new CallBackMessage()
                {
                    Url = doJobUrl,
                    PlayLoad = "abcd",
                    JobId = job.Id.ToString(),
                    UpdateJobStatusUrl = updateStatusUrl,
                    CompleteJobUrl = completeJobUrl
                };
                messageSender.SendMessage(callBackMessage, job.Id.ToString());

                detail.Id = job.Id;
                detail.ProcessResult.Messages.Add("Job Created.");

                return detail;
            }
            catch (Exception e)
            {
                detail.ProcessResult.Errors.Add("Fail to crete job: " + e.Message +"\n" + e.StackTrace);
                job.ProcessStatus = ProcessStatus.FailToPublish;
                MyDbContext.SaveChanges();
                return detail;
            }
        }