示例#1
0
        public void Subscribe <TService>(IEnumerable <TService> svcs)
            where TService : class
        {
            var queueSpecs = QuRegulation <TService> .TakeAllQueueSpec();

            queueSpecs.ForEach(qpspec => Subscribe <TService>(qpspec, svcs, ProcessEvent));
        }
示例#2
0
        private object DispatchMethod(IModel channel, MethodInfo methodInfo, ref object[] args)
        {
            QuSpecAttribute queueSpec;

            if (!queueOfMethodMap.TryGetValue(methodInfo, out queueSpec))
            {
                queueSpec = QuRegulation <TService> .TakeQueueSpec(methodInfo);

                queueOfMethodMap[methodInfo] = queueSpec;
            }
            var              msg                   = CreateQueueMessage(methodInfo, args);
            var              targetQueue           = string.IsNullOrEmpty(msg.TargetQueue) ? queueSpec.Queue : msg.TargetQueue;
            var              replyQueue            = string.IsNullOrEmpty(msg.ReplyQueue) ? queueSpec.ReplyQueue : msg.ReplyQueue;
            IQuCorrleation   quRlt                 = null;
            IBasicProperties props                 = null;
            bool             immediatelyWaitRasult = false;
            bool             noReturn              = methodInfo.ReturnType.Equals(typeof(void));

            if (!noReturn)
            {
                quRlt = RegistQuReslut(methodInfo, queueSpec, msg, out immediatelyWaitRasult);
                if (quRlt != null)
                {
                    props               = channel.CreateBasicProperties();
                    props.ReplyTo       = queueSpec.ReplyQueue;
                    props.CorrelationId = quRlt.CorrleationId;
                }
            }
            channel.QueueDeclare(targetQueue, queueSpec.Durable, queueSpec.Exclusive, queueSpec.AutoDelete, null);
            var message = QuRegulation.Transfer.ToText(msg);//JsonConvert.SerializeObject(msg);
            var body    = Encoding.UTF8.GetBytes(message);

            if (quRlt != null)
            {
                responseService.Register(quRlt);
                StartListeningReslutQueue(replyQueue);
            }
            channel.BasicPublish("", targetQueue, props, body);
            if (noReturn || quRlt == null)
            {
                return(null);
            }
            if (immediatelyWaitRasult)
            {
                var obj = responseService.Wait(methodInfo.ReturnParameter.ParameterType, quRlt, defaultWaitTimeout);
                return(obj);
            }
            return(quRlt);
            //return Activator.CreateInstance(methodInfo.ReturnParameter.ParameterType);
        }
示例#3
0
        private void StartListeningReslutQueue(string replyQueue)
        {
            var quSpec = QuRegulation <IQuResponseService> .TakeQueueSpec();

            quSpec.Queue = replyQueue;
            ResultListener.Subscribe <IQuResponseService>(responseService, quSpec);
            //if (!isListeningReslutQueue)
            //{
            //    Channel.QueueDeclare(replyQueue, false, true, false, null);
            //    var consumer = new AsyncEventingBasicConsumer(Channel);
            //    consumer.Received += ResultReceived;
            //    Channel.BasicConsume(replyQueue, true, consumer);
            //    isListeningReslutQueue = true;
            //}
        }