コード例 #1
0
        protected MessageFinalResponse OnDequeue(string message, IConsumer sender, ulong deliveryTag)
        {
#if DEBUG
            Debug.WriteLine(message);
#endif

            // A new instance has been passed to us
            var newInstance =
                (NewDialogInfo)JsonConvert.DeserializeObject(message, typeof(NewDialogInfo));

            // Check Dialogue Limit
            if (ActiveDialogs.Count >= ActiveDialogueLimit)
            {
                Debug.WriteLine("Rejected new dialogue due to ActiveDialogueLimit ({0}) being exceeded {1}", ActiveDialogueLimit, ActiveDialogs.Count);
                OnOnDialogueRejected(Guid.Parse(newInstance.DialogId));
                return(MessageFinalResponse.RejectWithReQueue); // Requeue dialogue
            }



            // Create new message queues
            var newApp = new BrokerSession(
                this,
                newInstance.DialogId,
                newInstance.ServerId,
                _queueProvider.CreateConsumer("events_" + newInstance.DialogId, newInstance.DialogId),
                _queueProvider.CreateConsumer("responses_" + newInstance.DialogId, newInstance.DialogId),
                _queueProvider.CreateProducer("commands_" + newInstance.DialogId, newInstance.DialogId));

            // Record this new instance
            _applicationQueues.Add(newInstance.DialogId, newApp);

            // Raise event NewDialog (event runner has not yet been started!)
            if (OnNewDialogue != null)
            {
                OnNewDialogue(this, newApp);
            }

            // Start the event runner
            newApp.Start();

            return(MessageFinalResponse.Accept);
        }