Esempio n. 1
0
        /// <summary>
        /// Creates and fills MapMessageBuilder for publish message into broker.
        /// </summary>
        /// <param name="message">Incoming message.</param>
        /// <param name="model">AMQP-model.</param>
        /// <returns>MapMessageBuilder with filled body header properties.</returns>
        private MapMessageBuilder BuildMessage(ServiceBusMessage message, IModel model)
        {
            var messageBuilder = new MapMessageBuilder(model);

            messageBuilder.Properties.DeliveryMode = 2;

            int normalizedPriority = (message.Priority < 0 ? 0 :
                                      message.Priority > 9 ? 9 :
                                      message.Priority);

            messageBuilder.Properties.Priority = Convert.ToByte(normalizedPriority);

            var bodyProps = _messageConverter.GetBodyProperties(message);

            foreach (var bodyProp in bodyProps)
            {
                messageBuilder.Body.Add(bodyProp.Key, bodyProp.Value);
            }

            var headerProps = _messageConverter.GetProperties(message);

            if (messageBuilder.Properties.Headers == null)
            {
                messageBuilder.Properties.Headers = headerProps;
            }
            else
            {
                foreach (var headerProp in headerProps)
                {
                    messageBuilder.Properties.Headers.Add(headerProp.Key, headerProp.Value);
                }
            }

            return(messageBuilder);
        }