/// <summary> /// Get a message from a destination. This claims the message without removing it from the destination. /// Ensure you use `Finish` on the result if you have processed the message /// </summary> public byte[] GetBytes(string destinationName, out MessageProperties properties) { try { var result = _longTermConnection.GetWithChannel(channel => channel?.BasicGet(destinationName, false)); if (result == null) { properties = default; return(null); } properties.DeliveryTag = result.DeliveryTag; properties.Exchange = result.Exchange; properties.CorrelationId = result.BasicProperties?.CorrelationId; properties.SenderName = result.BasicProperties?.ReplyTo; // 'OriginalType' tries to hold all contract types that match the message // BasicProperties.Type is limited to 255 chars, but is easier for clients to send. // Headers don't have this restriction, so we use them preferentially if they exist. properties.OriginalType = Coalesce(TryGet(result.BasicProperties?.Headers, RoutingHeaderKey), result.BasicProperties?.Type); return(result.Body); } catch { properties = default; return(null); } }
public void can_shutdown_and_restart_connections_on_seperate_threads() { new MessagingBaseConfiguration() .WithDefaults() .WithConnection(ConfigurationHelpers.RabbitMqConnectionWithConfigSettings()); var anyFails = false; var b = new Thread(() => { for (int i = 0; i < 100; i++) { _conn.Dispose(); Thread.Sleep(100); } }); var a = new Thread(() => { for (int i = 0; i < 100; i++) { if (!_conn.GetWithChannel(c => c.IsOpen)) { anyFails = true; } Thread.Sleep(100); } }); a.Start(); b.Start(); Assert.That(a.Join(TimeSpan.FromSeconds(20))); Assert.That(b.Join(TimeSpan.FromSeconds(20))); Assert.False(anyFails, "channel was closed during an operation"); }