private void PublishMessage(ProducerChannel channel, DaJetMessage message)
        {
            string mapping = null;

            if (Settings.MessageTypeRouting != null)
            {
                _ = Settings.MessageTypeRouting.TryGetValue(message.MessageType, out mapping);
            }

            string routingKey = string.Empty;

            if (mapping == null)
            {
                routingKey = message.MessageType;
            }

            string exchangeName = CreateExchangeName(mapping);

            byte[] messageBytes = Encoding.UTF8.GetBytes(message.MessageBody);

            channel.Properties.Type      = message.MessageType;
            channel.Properties.MessageId = message.Uuid.ToString();
            SetOperationTypeHeader(message, channel.Properties);

            channel.Channel.BasicPublish(exchangeName, routingKey, channel.Properties, messageBytes);
        }
Exemple #2
0
        private DaJetMessage ProduceMessage(SqlDataReader reader)
        {
            DaJetMessage message = new DaJetMessage()
            {
                UTC           = reader.IsDBNull("МоментВремени") ? 0 : (long)reader.GetDecimal("МоментВремени"),
                Uuid          = reader.IsDBNull("Идентификатор") ? Guid.Empty : reader.GetGuid("Идентификатор"),
                MessageType   = reader.IsDBNull("ТипСообщения") ? string.Empty : reader.GetString("ТипСообщения"),
                MessageBody   = reader.IsDBNull("ТелоСообщения") ? string.Empty : reader.GetString("ТелоСообщения"),
                OperationType = reader.IsDBNull("ТипОперации") ? string.Empty : reader.GetString("ТипОперации")
            };

            return(message);
        }
        private void SetOperationTypeHeader(DaJetMessage message, IBasicProperties properties)
        {
            if (string.IsNullOrWhiteSpace(message.OperationType))
            {
                return;
            }

            if (properties.Headers == null)
            {
                properties.Headers = new Dictionary <string, object>();
            }

            if (!properties.Headers.TryAdd("OperationType", message.OperationType))
            {
                properties.Headers["OperationType"] = message.OperationType;
            }
        }