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); } } }
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)); }
private void AckMessage(IModel channel, ulong deliveryTag, bool noAck, ReceivedMessage message) { if (!noAck && message != null && !message.SuppressAck) { channel.BasicAck(deliveryTag, false); } }