Esempio n. 1
0
        public async Task Handle(MqClient client, HorseMessage message, bool fromNode)
        {
            HorseQueue queue = await FindQueue(client, message.Target, message);

            if (queue == null)
            {
                return;
            }

            //if there is at least one cc header
            //we need to create a clone of the message
            //clone does not have cc headers but others
            HorseMessage  clone  = null;
            List <string> ccList = null;
            List <KeyValuePair <string, string> > additionalHeaders = null;

            if (message.HasHeader && message.FindHeader(HorseHeaders.CC) != null)
            {
                additionalHeaders = message.Headers.Where(x => !x.Key.Equals(HorseHeaders.CC, StringComparison.InvariantCultureIgnoreCase)).ToList();
                ccList            = new List <string>(message.Headers.Where(x => x.Key.Equals(HorseHeaders.CC, StringComparison.InvariantCultureIgnoreCase)).Select(x => x.Value));
                clone             = message.Clone(false, true, _server.MessageIdGenerator.Create(), additionalHeaders);
            }

            await HandlePush(client, message, queue, true);

            //if there are cc headers, we will push the message to other queues
            if (clone != null)
            {
                await PushOtherQueues(client, clone, ccList, additionalHeaders);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sends the message to binding receivers
        /// </summary>
        public override async Task <bool> Send(MqClient sender, HorseMessage message)
        {
            try
            {
                HorseQueue queue = await GetQueue(message);

                if (queue == null)
                {
                    return(false);
                }

                string messageId = Interaction == BindingInteraction.None
                                       ? Router.Server.MessageIdGenerator.Create()
                                       : message.MessageId;

                HorseMessage msg = message.Clone(true, true, messageId);

                msg.Type = MessageType.QueueMessage;
                msg.SetTarget(Target);
                msg.WaitResponse = Interaction == BindingInteraction.Response;

                QueueMessage queueMessage = new QueueMessage(msg);
                queueMessage.Source = sender;

                PushResult result = await queue.Push(queueMessage, sender);

                return(result == PushResult.Success);
            }
            catch (Exception e)
            {
                Router.Server.SendError("BINDING_SEND", e, $"Type:AutoQueue, Binding:{Name}");
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Pushes clones of the message to cc queues
        /// </summary>
        private async Task PushOtherQueues(MqClient client, HorseMessage clone, List <string> ccList, List <KeyValuePair <string, string> > additionalHeaders)
        {
            for (int i = 0; i < ccList.Count; i++)
            {
                string cc = ccList[i];

                string[] split = cc.Split(';');
                if (split.Length < 1)
                {
                    continue;
                }

                string queueName = split[0].Trim();
                string messageId = null;
                if (split.Length > 1)
                {
                    messageId = split[1];
                }

                HorseQueue queue = await FindQueue(null, queueName, clone);

                if (queue == null)
                {
                    continue;
                }

                HorseMessage msg = clone;
                if (i < ccList.Count - 1)
                {
                    clone = clone.Clone(false, true, _server.MessageIdGenerator.Create(), additionalHeaders);
                }

                if (!string.IsNullOrEmpty(messageId))
                {
                    msg.SetMessageId(messageId);
                }

                _ = HandlePush(client, msg, queue, false);
            }
        }
Esempio n. 4
0
        private Task <bool> SendDistribute(HorseMessage message)
        {
            bool sent = false;

            foreach (HorseQueue queue in _queues)
            {
                string messageId = sent || Interaction == BindingInteraction.None
                                       ? message.MessageId
                                       : _idGenerator.Create();

                if (!sent)
                {
                    sent = true;
                }

                HorseMessage msg          = message.Clone(true, true, messageId);
                QueueMessage queueMessage = new QueueMessage(msg);
                queue.AddMessage(queueMessage);
            }

            return(Task.FromResult(sent));
        }