Ejemplo n.º 1
0
        private async Task EventInsertAfterHandle(IEventBase <K> @event, byte[] bytes, int recursion = 0, string mqHashKey = null)
        {
            try
            {
                if (SendEventToMQ)
                {
                    if (string.IsNullOrEmpty(mqHashKey))
                    {
                        mqHashKey = GrainId.ToString();
                    }
                    //消息写入消息队列
                    await MQService.Send(@event, bytes, mqHashKey);
                }
                //更改消息状态
                await EventStorage.Complete(@event);

                //保存快照
                await SaveSnapshotAsync();
            }
            catch (Exception e)
            {
                if (recursion > 5)
                {
                    throw e;
                }
                this.GetLogger("Event_Raise").Log(LogCodes.EventCompleteError, Orleans.Runtime.Severity.Error, "事件complate操作出现致命异常:" + string.Format("Grain类型={0},GrainId={1},StateId={2},Version={3},错误信息:{4}", ThisType.FullName, GrainId, @event.StateId, @event.Version, e.Message), null, e);
                int newRecursion = recursion + 1;
                await Task.Delay(newRecursion * 200);
                await EventInsertAfterHandle(@event, bytes, newRecursion, mqHashKey : mqHashKey);
            }
        }
Ejemplo n.º 2
0
        protected virtual async Task AfterEventSavedHandle(IEventBase <K> @event, byte[] bytes, int recursion = 0, string hashKey = null)
        {
            try
            {
                if (string.IsNullOrEmpty(hashKey))
                {
                    hashKey = GrainId.ToString();
                }
                //消息写入消息队列
                await MQService.Publish(@event, bytes, hashKey);

                //更改消息状态
                await EventStorage.CompleteAsync(@event);
            }
            catch (Exception e)
            {
                if (recursion > 5)
                {
                    throw e;
                }
                this.GetLogger("Event_Raise").Log(LogCodes.EventCompleteError, Orleans.Runtime.Severity.Error, "事件complate操作出现致命异常:" + string.Format("Grain类型={0},GrainId={1},StateId={2},Version={3},错误信息:{4}", ThisType.FullName, GrainId, @event.StateId, @event.Version, e.Message), null, e);
                int newRecursion = recursion + 1;
                await Task.Delay(newRecursion * 200);
                await AfterEventSavedHandle(@event, bytes, newRecursion, hashKey : hashKey);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 发送无状态更改的消息到消息队列
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 public async Task Publish(IActorOwnMessage <K> msg)
 {
     msg.StateId = this.GrainId;
     using (var ms = new PooledMemoryStream())
     {
         Serializer.Serialize(ms, msg);
         await MQService.Publish(msg, ms.ToArray(), GrainId.ToString());
     }
 }
        public JsonResult MQSendMsg(string queueName = "TestQueue111", string message = "hello MQ")
        {
            var result = new ResponseModel();

            try
            {
                result.returnCode = CodeEnum.success;
                MQService service = new MQService(queueName, message);
                service.ExeSend();
                Thread.Sleep(1000);
                service.ExeReceive();
                result.returnMsg = "执行成功";
            }
            catch (Exception ex)
            {
                result.returnCode = CodeEnum.failed;
                result.returnMsg  = ex.Message;
                Logger.Error(ex);
            }

            return(Json(result));
        }
Ejemplo n.º 5
0
 protected virtual async Task AfterEventSavedHandle(IEventBase <K> @event, byte[] bytes, string hashKey = null)
 {
     try
     {
         if (string.IsNullOrEmpty(hashKey))
         {
             hashKey = GrainId.ToString();
         }
         //消息写入消息队列
         if (PublishEventToMq)
         {
             await MQService.Publish(@event, bytes, hashKey);
         }
         //更改消息状态
         await EventStorage.CompleteAsync(@event);
     }
     catch (Exception e)
     {
         Logger.LogError(LogCodes.EventCompleteError, e, "事件complate操作出现致命异常:" + string.Format("Grain类型={0},GrainId={1},StateId={2},Version={3},错误信息:{4}", ThisType.FullName, GrainId, @event.StateId, @event.Version, e.Message), null, e);
         throw e;
     }
 }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (mqSrv == null)
                mqSrv = new MQService();

            mqSrv.Hostname = this.tbxHostName.Text;
            mqSrv.Port = int.Parse(this.tbxPort.Text);
            mqSrv.MQCCSID = this.tbxCCSID.Text;
            mqSrv.Channel = this.tbxChannel.Text;
            mqSrv.UserId = this.tbxUserId.Text;
            mqSrv.QmgrName = this.tbxQmgrName.Text;
            mqSrv.QueueName = this.tbxQueueName.Text;
            try
            {
                mqSrv.Init();
                MessageBox.Show("连接成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!" + ex.Message);
                return;
            }
        }
Ejemplo n.º 7
0
 public HomeController(MQService mqService, ILogger <HomeController> logger)
 {
     this.MQService = mqService;
     this.Logger    = logger;
 }
Ejemplo n.º 8
0
 public MQServerController(MQService mQService)
 {
     this.mQService = mQService;
 }