Exemple #1
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);
         }
     }
 }
Exemple #2
0
 public virtual void HandleError(ReceivedMessage message, string endpointName)
 {
     var endpoint = _queueEndpointProvider.GetEndpointByName(endpointName);
     var errorConfig = endpoint.Subscription.ErrorHandling;
     if (errorConfig == null || !errorConfig.EnableErrorQueue) return;
     _logger.Log("Endpoint " + endpointName + " read from config.");
     var factory = _rabbitMqFactory.GetConnectionFactory(endpoint);
     using (var connection = factory.CreateConnection())
     {
         using (var channel = connection.CreateModel())
         {
             _channelConfiguratior.ConfigureQueue(endpoint, channel);
             message.Properties.DeliveryMode = DeliveryMode.Persistent;
             var basicProperties = new BasicPropertiesFactory().Create(channel, message.Properties);
             _logger.Log("Before ErrorHandler: Publish to error queue");
             LogEndpointData(factory, errorConfig);
             channel.BasicPublish(string.Empty, errorConfig.ErrorQueueName, basicProperties, message.Data);
             _logger.Log("After ErrorHandler:Publish to error queue, bytes.Length: " + message.Data.Length);
         }
     }
 }