public virtual IBasicProperties Create(IModel channel, MessageProperties properties)
 {
     var basicProperties = channel.CreateBasicProperties();
     if(!string.IsNullOrWhiteSpace(properties.MessageId))
     {
         basicProperties.MessageId = properties.MessageId;
     }
     if(!string.IsNullOrWhiteSpace(properties.CorrelationId))
     {
         basicProperties.CorrelationId = properties.CorrelationId;
     }
     if(!string.IsNullOrWhiteSpace(properties.ContentType))
     {
         basicProperties.ContentType = properties.ContentType;
     }
     if(!string.IsNullOrWhiteSpace(properties.ContentEncoding))
     {
         basicProperties.ContentEncoding = properties.ContentEncoding;
     }
     basicProperties.DeliveryMode = (byte) properties.DeliveryMode;
     if(properties.Headers.Keys.Any())
     {
         basicProperties.Headers = new Dictionary<object, object>();
         foreach(var key in properties.Headers.Keys)
         {
             basicProperties.Headers.Add(key, properties.Headers[key]);
         }
     }
     return basicProperties;
 }
Example #2
0
 public ReceivedMessage(byte[] data, string exchange, MessageProperties properties, string routingKey = "")
 {
     Data = data;
     Exchange = exchange;
     Properties = properties;
     RoutingKey = routingKey;
     SuppressAck = false;
 }
Example #3
0
 public virtual void Send(string endpointName, byte[] data, MessageProperties properties, string routingKey)
 {
     ValidateInput(endpointName, data, properties);
     var endpoint = _queueEndpointProvider.GetEndpointByName(endpointName);
     _logger.Log("Endpoint " + endpointName + " read from config.");
     var factory = _rabbitMqFactory.GetConnectionFactory(endpoint);
     using (IConnection connection = factory.CreateConnection())
     {
         using (IModel channel = connection.CreateModel())
         {
             _channelConfiguratior.ConfigureQueue(endpoint, channel);
             var basicProperties = new BasicPropertiesFactory().Create(channel, properties);
             _logger.Log("Before Sender.Publish");
             var exchangeName = GetExchangeName(endpoint);
             LogEndpointData(factory, endpoint);
             channel.BasicPublish(GetExchangeName(endpoint), routingKey, basicProperties, data);
             _logger.Log("After Sender.Publish, bytes.Length: " + data.Length);
         }
     }
 }
Example #4
0
 private void OnMessageReceived(byte[] data, string exchange, string routingKey, MessageProperties properties, out ReceivedMessage message)
 {
     var receivedMessage = new ReceivedMessage(data, exchange, properties, routingKey);
     message = receivedMessage;
     Receivers.ForEach(x => x.Receive(receivedMessage));
 }
Example #5
0
 private void LogReceivedMessage(byte[] data, string exchange, MessageProperties properties)
 {
     Logger.Log("Message received");
     Logger.Log("Message.Exchange=" + exchange);
     Logger.Log("Message.Size(bytes)=" + (data != null ? data.Length.ToString(CultureInfo.InvariantCulture) : "0"));
     Logger.Log("Message.Id" + properties.MessageId);
     foreach (var header in properties.Headers)
     {
         Logger.Log(string.Format("Header: '{0}': '{1}'", header.Key, header.Value));
     }
 }
Example #6
0
        private MessageProperties BuildMessageProperties(IModel channel, SubscriptionConfiguration subscription, IBasicProperties properties)
        {
            var messageProperties = new MessageProperties
            {
                MessageId = properties.MessageId,
                CorrelationId = properties.CorrelationId,
                ContentType = properties.ContentType,
                ContentEncoding = properties.ContentEncoding
            };
            if (properties.Headers != null && properties.Headers.Keys.Count > 0)
            {
                foreach (var key in properties.Headers.Keys)
                {
                    try
                    {
                        var val = GetStringFromByteArray(properties.Headers[key], properties.ContentEncoding) ?? string.Empty;
                        messageProperties.Headers.Add(key.ToString(), val);
                    }
                    catch { }

                }
            }
            return messageProperties;
        }
Example #7
0
 private static void ValidateInput(string endpointName, byte[] data, MessageProperties properties)
 {
     if(properties == null) throw new ArgumentNullException("properties");
 }
Example #8
0
 public virtual void Send(string endpointName, byte[] data, MessageProperties properties)
 {
     var endpoint = _queueEndpointProvider.GetEndpointByName(endpointName);
     Send(endpointName, data, properties, endpoint.RoutingKey);
 }
Example #9
0
 public virtual void Send(string endpointName, string data, MessageProperties properties)
 {
     if (properties == null) throw new ArgumentNullException("properties");
     var bodyBytes = properties.GetEncoding().GetBytes(data);
     Send(endpointName, bodyBytes, properties);
 }