diff --git a/projects/Benchmarks/ConsumerDispatching/AsyncBasicConsumerFake.cs b/projects/Benchmarks/ConsumerDispatching/AsyncBasicConsumerFake.cs index 38e38a8a1a..573db2a277 100644 --- a/projects/Benchmarks/ConsumerDispatching/AsyncBasicConsumerFake.cs +++ b/projects/Benchmarks/ConsumerDispatching/AsyncBasicConsumerFake.cs @@ -44,9 +44,9 @@ void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bo public Task HandleBasicConsumeOk(string consumerTag) => Task.CompletedTask; - public Task HandleModelShutdown(object model, ShutdownEventArgs reason) => Task.CompletedTask; + public Task HandleChannelShutdown(object channel, ShutdownEventArgs reason) => Task.CompletedTask; - public IModel Model { get; } + public IChannel Channel { get; } event EventHandler IBasicConsumer.ConsumerCancelled { @@ -68,7 +68,7 @@ void IBasicConsumer.HandleBasicConsumeOk(string consumerTag) { } - void IBasicConsumer.HandleModelShutdown(object model, ShutdownEventArgs reason) + void IBasicConsumer.HandleChannelShutdown(object channel, ShutdownEventArgs reason) { } diff --git a/projects/Benchmarks/Networking/Networking_BasicDeliver_Commons.cs b/projects/Benchmarks/Networking/Networking_BasicDeliver_Commons.cs index fb8489fff7..16a9f537cd 100644 --- a/projects/Benchmarks/Networking/Networking_BasicDeliver_Commons.cs +++ b/projects/Benchmarks/Networking/Networking_BasicDeliver_Commons.cs @@ -12,11 +12,11 @@ public class Networking_BasicDeliver_Commons public static async Task Publish_Hello_World(IConnection connection, uint messageCount, byte[] body) { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - using (var model = connection.CreateModel()) + using (var channel = connection.CreateChannel()) { - var queue = model.QueueDeclare(); + var queue = channel.QueueDeclare(); var consumed = 0; - var consumer = new EventingBasicConsumer(model); + var consumer = new EventingBasicConsumer(channel); consumer.Received += (s, args) => { if (Interlocked.Increment(ref consumed) == messageCount) @@ -24,11 +24,11 @@ public static async Task Publish_Hello_World(IConnection connection, uint messag tcs.SetResult(true); } }; - model.BasicConsume(queue.QueueName, true, consumer); + channel.BasicConsume(queue.QueueName, true, consumer); for (int i = 0; i < messageCount; i++) { - model.BasicPublish("", queue.QueueName, body); + channel.BasicPublish("", queue.QueueName, body); } await tcs.Task; diff --git a/projects/RabbitMQ.Client/client/api/AsyncDefaultBasicConsumer.cs b/projects/RabbitMQ.Client/client/api/AsyncDefaultBasicConsumer.cs index fdab6e02dd..a0c0af161a 100644 --- a/projects/RabbitMQ.Client/client/api/AsyncDefaultBasicConsumer.cs +++ b/projects/RabbitMQ.Client/client/api/AsyncDefaultBasicConsumer.cs @@ -19,17 +19,17 @@ public AsyncDefaultBasicConsumer() } /// - /// Constructor which sets the Model property to the given value. + /// Constructor which sets the Channel property to the given value. /// - /// Common AMQP model. - public AsyncDefaultBasicConsumer(IModel model) + /// Common AMQP channel. + public AsyncDefaultBasicConsumer(IChannel channel) { - Model = model; + Channel = channel; } /// /// Retrieve the consumer tags this consumer is registered as; to be used when discussing this consumer - /// with the server, for instance with . + /// with the server, for instance with . /// public string[] ConsumerTags { @@ -45,7 +45,7 @@ public string[] ConsumerTags public bool IsRunning { get; protected set; } /// - /// If our shuts down, this property will contain a description of the reason for the + /// If our shuts down, this property will contain a description of the reason for the /// shutdown. Otherwise it will contain null. See . /// public ShutdownEventArgs ShutdownReason { get; protected set; } @@ -61,10 +61,10 @@ public event AsyncEventHandler ConsumerCancelled private AsyncEventingWrapper _consumerCancelledWrapper; /// - /// Retrieve the this consumer is associated with, + /// Retrieve the this consumer is associated with, /// for use in acknowledging received messages, for instance. /// - public IModel Model { get; set; } + public IChannel Channel { get; set; } /// /// Called when the consumer is cancelled for reasons other than by a basicCancel: @@ -101,7 +101,7 @@ public virtual Task HandleBasicConsumeOk(string consumerTag) /// Called each time a message is delivered for this consumer. /// /// - /// This is a no-op implementation. It will not acknowledge deliveries via + /// This is a no-op implementation. It will not acknowledge deliveries via /// if consuming in automatic acknowledgement mode. /// Subclasses must copy or fully use delivery body before returning. /// Accessing the body at a later point is unsafe as its memory can @@ -120,11 +120,11 @@ public virtual Task HandleBasicDeliver(string consumerTag, } /// - /// Called when the model (channel) this consumer was registered on terminates. + /// Called when the channel (channel) this consumer was registered on terminates. /// - /// A channel this consumer was registered on. + /// A channel this consumer was registered on. /// Shutdown context. - public virtual Task HandleModelShutdown(object model, ShutdownEventArgs reason) + public virtual Task HandleChannelShutdown(object channel, ShutdownEventArgs reason) { ShutdownReason = reason; return OnCancel(_consumerTags.ToArray()); @@ -170,7 +170,7 @@ void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bo throw new InvalidOperationException("Should never be called. Enable 'DispatchConsumersAsync'."); } - void IBasicConsumer.HandleModelShutdown(object model, ShutdownEventArgs reason) + void IBasicConsumer.HandleChannelShutdown(object channel, ShutdownEventArgs reason) { throw new InvalidOperationException("Should never be called. Enable 'DispatchConsumersAsync'."); } diff --git a/projects/RabbitMQ.Client/client/api/BasicGetResult.cs b/projects/RabbitMQ.Client/client/api/BasicGetResult.cs index fc79fa6f06..4e9a9d1cc9 100644 --- a/projects/RabbitMQ.Client/client/api/BasicGetResult.cs +++ b/projects/RabbitMQ.Client/client/api/BasicGetResult.cs @@ -99,7 +99,7 @@ public BasicGetResult(ulong deliveryTag, bool redelivered, string exchange, stri public ReadOnlyMemory Body { get; } /// - /// Retrieve the delivery tag for this message. See also . + /// Retrieve the delivery tag for this message. See also . /// public ulong DeliveryTag { get; } diff --git a/projects/RabbitMQ.Client/client/api/CachedString.cs b/projects/RabbitMQ.Client/client/api/CachedString.cs index 16e33a1fb7..8c34433f83 100644 --- a/projects/RabbitMQ.Client/client/api/CachedString.cs +++ b/projects/RabbitMQ.Client/client/api/CachedString.cs @@ -4,7 +4,7 @@ namespace RabbitMQ.Client { /// - /// Caches a string's byte representation to be used for certain methods like IModel.BasicPublish/>. + /// Caches a string's byte representation to be used for certain methods like IChannel.BasicPublish/>. /// public sealed class CachedString { diff --git a/projects/RabbitMQ.Client/client/api/ConnectionFactory.cs b/projects/RabbitMQ.Client/client/api/ConnectionFactory.cs index 52ed90ddc5..ab8a9d8971 100644 --- a/projects/RabbitMQ.Client/client/api/ConnectionFactory.cs +++ b/projects/RabbitMQ.Client/client/api/ConnectionFactory.cs @@ -61,9 +61,9 @@ namespace RabbitMQ.Client /// // /// IConnection conn = factory.CreateConnection(); /// // - /// IModel ch = conn.CreateModel(); + /// IChannel ch = conn.CreateChannel(); /// // - /// // ... use ch's IModel methods ... + /// // ... use ch's IChannel methods ... /// // /// ch.Close(Constants.ReplySuccess, "Closing the channel"); /// conn.Close(Constants.ReplySuccess, "Closing the connection"); diff --git a/projects/RabbitMQ.Client/client/api/DefaultBasicConsumer.cs b/projects/RabbitMQ.Client/client/api/DefaultBasicConsumer.cs index 9e1b92beb0..15b40ea808 100644 --- a/projects/RabbitMQ.Client/client/api/DefaultBasicConsumer.cs +++ b/projects/RabbitMQ.Client/client/api/DefaultBasicConsumer.cs @@ -58,17 +58,17 @@ public DefaultBasicConsumer() } /// - /// Constructor which sets the Model property to the given value. + /// Constructor which sets the Channel property to the given value. /// - /// Common AMQP model. - public DefaultBasicConsumer(IModel model) + /// Common AMQP channel. + public DefaultBasicConsumer(IChannel channel) { - Model = model; + Channel = channel; } /// /// Retrieve the consumer tags this consumer is registered as; to be used to identify - /// this consumer, for example, when cancelling it with . + /// this consumer, for example, when cancelling it with . /// This value is an array because a single consumer instance can be reused to consume on /// multiple channels. /// @@ -86,7 +86,7 @@ public string[] ConsumerTags public bool IsRunning { get; protected set; } /// - /// If our shuts down, this property will contain a description of the reason for the + /// If our shuts down, this property will contain a description of the reason for the /// shutdown. Otherwise it will contain null. See . /// public ShutdownEventArgs ShutdownReason { get; protected set; } @@ -102,10 +102,10 @@ public event EventHandler ConsumerCancelled private EventingWrapper _consumerCancelledWrapper; /// - /// Retrieve the this consumer is associated with, + /// Retrieve the this consumer is associated with, /// for use in acknowledging received messages, for instance. /// - public IModel Model { get; set; } + public IChannel Channel { get; set; } /// /// Called when the consumer is cancelled for reasons other than by a basicCancel: @@ -141,7 +141,7 @@ public virtual void HandleBasicConsumeOk(string consumerTag) /// Called each time a message is delivered for this consumer. /// /// - /// This is a no-op implementation. It will not acknowledge deliveries via + /// This is a no-op implementation. It will not acknowledge deliveries via /// if consuming in automatic acknowledgement mode. /// Subclasses must copy or fully use delivery body before returning. /// Accessing the body at a later point is unsafe as its memory can @@ -159,11 +159,11 @@ public virtual void HandleBasicDeliver(string consumerTag, } /// - /// Called when the model (channel) this consumer was registered on terminates. + /// Called when the channel (channel) this consumer was registered on terminates. /// - /// A channel this consumer was registered on. + /// A channel this consumer was registered on. /// Shutdown context. - public virtual void HandleModelShutdown(object model, ShutdownEventArgs reason) + public virtual void HandleChannelShutdown(object channel, ShutdownEventArgs reason) { ShutdownReason = reason; OnCancel(_consumerTags.ToArray()); diff --git a/projects/RabbitMQ.Client/client/api/ExchangeType.cs b/projects/RabbitMQ.Client/client/api/ExchangeType.cs index d861785b09..b4e1035088 100644 --- a/projects/RabbitMQ.Client/client/api/ExchangeType.cs +++ b/projects/RabbitMQ.Client/client/api/ExchangeType.cs @@ -38,7 +38,7 @@ namespace RabbitMQ.Client /// /// /// Use the static members of this class as values for the - /// "exchangeType" arguments for IModel methods such as + /// "exchangeType" arguments for IChannel methods such as /// ExchangeDeclare. The broker may be extended with additional /// exchange types that do not appear in this class. /// diff --git a/projects/RabbitMQ.Client/client/api/IAsyncBasicConsumer.cs b/projects/RabbitMQ.Client/client/api/IAsyncBasicConsumer.cs index 24e787d691..291eda1293 100644 --- a/projects/RabbitMQ.Client/client/api/IAsyncBasicConsumer.cs +++ b/projects/RabbitMQ.Client/client/api/IAsyncBasicConsumer.cs @@ -8,10 +8,10 @@ namespace RabbitMQ.Client public interface IAsyncBasicConsumer { /// - /// Retrieve the this consumer is associated with, + /// Retrieve the this consumer is associated with, /// for use in acknowledging received messages, for instance. /// - IModel Model { get; } + IChannel Channel { get; } /// /// Signalled when the consumer gets cancelled. @@ -43,7 +43,7 @@ public interface IAsyncBasicConsumer /// /// /// Does nothing with the passed in information. - /// Note that in particular, some delivered messages may require acknowledgement via . + /// Note that in particular, some delivered messages may require acknowledgement via . /// The implementation of this method in this class does NOT acknowledge such messages. /// Task HandleBasicDeliver(string consumerTag, @@ -55,10 +55,10 @@ Task HandleBasicDeliver(string consumerTag, ReadOnlyMemory body); /// - /// Called when the model shuts down. + /// Called when the channel shuts down. /// - /// Common AMQP model. - /// Information about the reason why a particular model, session, or connection was destroyed. - Task HandleModelShutdown(object model, ShutdownEventArgs reason); + /// Common AMQP channel. + /// Information about the reason why a particular channel, session, or connection was destroyed. + Task HandleChannelShutdown(object channel, ShutdownEventArgs reason); } } diff --git a/projects/RabbitMQ.Client/client/api/IBasicConsumer.cs b/projects/RabbitMQ.Client/client/api/IBasicConsumer.cs index 94627c5a35..d5244e973e 100644 --- a/projects/RabbitMQ.Client/client/api/IBasicConsumer.cs +++ b/projects/RabbitMQ.Client/client/api/IBasicConsumer.cs @@ -39,7 +39,7 @@ namespace RabbitMQ.Client ///receive messages from a queue by subscription. /// /// - /// See IModel.BasicConsume, IModel.BasicCancel. + /// See IChannel.BasicConsume, IChannel.BasicCancel. /// /// /// Note that the "Handle*" methods run in the connection's @@ -51,10 +51,10 @@ namespace RabbitMQ.Client public interface IBasicConsumer { /// - /// Retrieve the this consumer is associated with, + /// Retrieve the this consumer is associated with, /// for use in acknowledging received messages, for instance. /// - IModel Model { get; } + IChannel Channel { get; } /// /// Signalled when the consumer gets cancelled. @@ -86,7 +86,7 @@ public interface IBasicConsumer /// /// /// Does nothing with the passed in information. - /// Note that in particular, some delivered messages may require acknowledgement via . + /// Note that in particular, some delivered messages may require acknowledgement via . /// The implementation of this method in this class does NOT acknowledge such messages. /// void HandleBasicDeliver(string consumerTag, @@ -98,10 +98,10 @@ void HandleBasicDeliver(string consumerTag, ReadOnlyMemory body); /// - /// Called when the model shuts down. + /// Called when the channel shuts down. /// - /// Common AMQP model. - /// Information about the reason why a particular model, session, or connection was destroyed. - void HandleModelShutdown(object model, ShutdownEventArgs reason); + /// Common AMQP channel. + /// Information about the reason why a particular channel, session, or connection was destroyed. + void HandleChannelShutdown(object channel, ShutdownEventArgs reason); } } diff --git a/projects/RabbitMQ.Client/client/api/IModel.cs b/projects/RabbitMQ.Client/client/api/IChannel.cs similarity index 97% rename from projects/RabbitMQ.Client/client/api/IModel.cs rename to projects/RabbitMQ.Client/client/api/IChannel.cs index 2dbafc3ada..7069b02e1a 100644 --- a/projects/RabbitMQ.Client/client/api/IModel.cs +++ b/projects/RabbitMQ.Client/client/api/IChannel.cs @@ -45,7 +45,7 @@ namespace RabbitMQ.Client /// Extends the interface, so that the "using" /// statement can be used to scope the lifetime of a channel when appropriate. /// - public interface IModel : IDisposable + public interface IChannel : IDisposable { /// /// Channel number, unique per connections. @@ -83,12 +83,12 @@ public interface IModel : IDisposable IBasicConsumer DefaultConsumer { get; set; } /// - /// Returns true if the model is no longer in a state where it can be used. + /// Returns true if the channel is no longer in a state where it can be used. /// bool IsClosed { get; } /// - /// Returns true if the model is still in a state where it can be used. + /// Returns true if the channel is still in a state where it can be used. /// Identical to checking if equals null. bool IsOpen { get; } @@ -124,24 +124,24 @@ public interface IModel : IDisposable event EventHandler BasicReturn; /// - /// Signalled when an exception occurs in a callback invoked by the model. + /// Signalled when an exception occurs in a callback invoked by the channel. /// /// Examples of cases where this event will be signalled /// include exceptions thrown in methods, or - /// exceptions thrown in delegates etc. + /// exceptions thrown in delegates etc. /// event EventHandler CallbackException; event EventHandler FlowControl; /// - /// Notifies the destruction of the model. + /// Notifies the destruction of the channel. /// /// - /// If the model is already destroyed at the time an event + /// If the channel is already destroyed at the time an event /// handler is added to this event, the event handler will be fired immediately. /// - event EventHandler ModelShutdown; + event EventHandler ChannelShutdown; /// /// Acknowledge one or more delivered message(s). @@ -172,7 +172,7 @@ string BasicConsume( /// /// Retrieve an individual message, if /// one is available; returns null if the server answers that - /// no messages are currently available. See also . + /// no messages are currently available. See also . /// BasicGetResult BasicGet(string queue, bool autoAck); diff --git a/projects/RabbitMQ.Client/client/api/IModelExtensions.cs b/projects/RabbitMQ.Client/client/api/IChannelExtensions.cs similarity index 54% rename from projects/RabbitMQ.Client/client/api/IModelExtensions.cs rename to projects/RabbitMQ.Client/client/api/IChannelExtensions.cs index 2c7f745964..7c0f776657 100644 --- a/projects/RabbitMQ.Client/client/api/IModelExtensions.cs +++ b/projects/RabbitMQ.Client/client/api/IChannelExtensions.cs @@ -35,10 +35,10 @@ namespace RabbitMQ.Client { - public static class IModelExtensions + public static class IChannelExtensions { /// Start a Basic content-class consumer. - public static string BasicConsume(this IModel model, + public static string BasicConsume(this IChannel channel, IBasicConsumer consumer, string queue, bool autoAck = false, @@ -47,32 +47,32 @@ public static string BasicConsume(this IModel model, bool exclusive = false, IDictionary arguments = null) { - return model.BasicConsume(queue, autoAck, consumerTag, noLocal, exclusive, arguments, consumer); + return channel.BasicConsume(queue, autoAck, consumerTag, noLocal, exclusive, arguments, consumer); } /// Start a Basic content-class consumer. - public static string BasicConsume(this IModel model, string queue, bool autoAck, IBasicConsumer consumer) + public static string BasicConsume(this IChannel channel, string queue, bool autoAck, IBasicConsumer consumer) { - return model.BasicConsume(queue, autoAck, "", false, false, null, consumer); + return channel.BasicConsume(queue, autoAck, "", false, false, null, consumer); } /// Start a Basic content-class consumer. - public static string BasicConsume(this IModel model, string queue, + public static string BasicConsume(this IChannel channel, string queue, bool autoAck, string consumerTag, IBasicConsumer consumer) { - return model.BasicConsume(queue, autoAck, consumerTag, false, false, null, consumer); + return channel.BasicConsume(queue, autoAck, consumerTag, false, false, null, consumer); } /// Start a Basic content-class consumer. - public static string BasicConsume(this IModel model, string queue, + public static string BasicConsume(this IChannel channel, string queue, bool autoAck, string consumerTag, IDictionary arguments, IBasicConsumer consumer) { - return model.BasicConsume(queue, autoAck, consumerTag, false, false, arguments, consumer); + return channel.BasicConsume(queue, autoAck, consumerTag, false, false, arguments, consumer); } #nullable enable @@ -82,119 +82,119 @@ public static string BasicConsume(this IModel model, string queue, /// /// The publication occurs with mandatory=false and immediate=false. /// - public static void BasicPublish(this IModel model, PublicationAddress addr, in T basicProperties, ReadOnlyMemory body) + public static void BasicPublish(this IChannel channel, PublicationAddress addr, in T basicProperties, ReadOnlyMemory body) where T : IReadOnlyBasicProperties, IAmqpHeader { - model.BasicPublish(addr.ExchangeName, addr.RoutingKey, in basicProperties, body); + channel.BasicPublish(addr.ExchangeName, addr.RoutingKey, in basicProperties, body); } - public static void BasicPublish(this IModel model, string exchange, string routingKey, ReadOnlyMemory body = default, bool mandatory = false) - => model.BasicPublish(exchange, routingKey, in EmptyBasicProperty.Empty, body, mandatory); + public static void BasicPublish(this IChannel channel, string exchange, string routingKey, ReadOnlyMemory body = default, bool mandatory = false) + => channel.BasicPublish(exchange, routingKey, in EmptyBasicProperty.Empty, body, mandatory); - public static void BasicPublish(this IModel model, CachedString exchange, CachedString routingKey, ReadOnlyMemory body = default, bool mandatory = false) - => model.BasicPublish(exchange, routingKey, in EmptyBasicProperty.Empty, body, mandatory); + public static void BasicPublish(this IChannel channel, CachedString exchange, CachedString routingKey, ReadOnlyMemory body = default, bool mandatory = false) + => channel.BasicPublish(exchange, routingKey, in EmptyBasicProperty.Empty, body, mandatory); #nullable disable /// /// (Spec method) Declare a queue. /// - public static QueueDeclareOk QueueDeclare(this IModel model, string queue = "", bool durable = false, bool exclusive = true, + public static QueueDeclareOk QueueDeclare(this IChannel channel, string queue = "", bool durable = false, bool exclusive = true, bool autoDelete = true, IDictionary arguments = null) { - return model.QueueDeclare(queue, durable, exclusive, autoDelete, arguments); + return channel.QueueDeclare(queue, durable, exclusive, autoDelete, arguments); } /// /// (Extension method) Bind an exchange to an exchange. /// - public static void ExchangeBind(this IModel model, string destination, string source, string routingKey, IDictionary arguments = null) + public static void ExchangeBind(this IChannel channel, string destination, string source, string routingKey, IDictionary arguments = null) { - model.ExchangeBind(destination, source, routingKey, arguments); + channel.ExchangeBind(destination, source, routingKey, arguments); } /// /// (Extension method) Like exchange bind but sets nowait to true. /// - public static void ExchangeBindNoWait(this IModel model, string destination, string source, string routingKey, IDictionary arguments = null) + public static void ExchangeBindNoWait(this IChannel channel, string destination, string source, string routingKey, IDictionary arguments = null) { - model.ExchangeBindNoWait(destination, source, routingKey, arguments); + channel.ExchangeBindNoWait(destination, source, routingKey, arguments); } /// /// (Spec method) Declare an exchange. /// - public static void ExchangeDeclare(this IModel model, string exchange, string type, bool durable = false, bool autoDelete = false, + public static void ExchangeDeclare(this IChannel channel, string exchange, string type, bool durable = false, bool autoDelete = false, IDictionary arguments = null) { - model.ExchangeDeclare(exchange, type, durable, autoDelete, arguments); + channel.ExchangeDeclare(exchange, type, durable, autoDelete, arguments); } /// /// (Extension method) Like ExchangeDeclare but sets nowait to true. /// - public static void ExchangeDeclareNoWait(this IModel model, string exchange, string type, bool durable = false, bool autoDelete = false, + public static void ExchangeDeclareNoWait(this IChannel channel, string exchange, string type, bool durable = false, bool autoDelete = false, IDictionary arguments = null) { - model.ExchangeDeclareNoWait(exchange, type, durable, autoDelete, arguments); + channel.ExchangeDeclareNoWait(exchange, type, durable, autoDelete, arguments); } /// /// (Spec method) Unbinds an exchange. /// - public static void ExchangeUnbind(this IModel model, string destination, + public static void ExchangeUnbind(this IChannel channel, string destination, string source, string routingKey, IDictionary arguments = null) { - model.ExchangeUnbind(destination, source, routingKey, arguments); + channel.ExchangeUnbind(destination, source, routingKey, arguments); } /// /// (Spec method) Deletes an exchange. /// - public static void ExchangeDelete(this IModel model, string exchange, bool ifUnused = false) + public static void ExchangeDelete(this IChannel channel, string exchange, bool ifUnused = false) { - model.ExchangeDelete(exchange, ifUnused); + channel.ExchangeDelete(exchange, ifUnused); } /// /// (Extension method) Like ExchangeDelete but sets nowait to true. /// - public static void ExchangeDeleteNoWait(this IModel model, string exchange, bool ifUnused = false) + public static void ExchangeDeleteNoWait(this IChannel channel, string exchange, bool ifUnused = false) { - model.ExchangeDeleteNoWait(exchange, ifUnused); + channel.ExchangeDeleteNoWait(exchange, ifUnused); } /// /// (Spec method) Binds a queue. /// - public static void QueueBind(this IModel model, string queue, string exchange, string routingKey, IDictionary arguments = null) + public static void QueueBind(this IChannel channel, string queue, string exchange, string routingKey, IDictionary arguments = null) { - model.QueueBind(queue, exchange, routingKey, arguments); + channel.QueueBind(queue, exchange, routingKey, arguments); } /// /// (Spec method) Deletes a queue. /// - public static uint QueueDelete(this IModel model, string queue, bool ifUnused = false, bool ifEmpty = false) + public static uint QueueDelete(this IChannel channel, string queue, bool ifUnused = false, bool ifEmpty = false) { - return model.QueueDelete(queue, ifUnused, ifEmpty); + return channel.QueueDelete(queue, ifUnused, ifEmpty); } /// /// (Extension method) Like QueueDelete but sets nowait to true. /// - public static void QueueDeleteNoWait(this IModel model, string queue, bool ifUnused = false, bool ifEmpty = false) + public static void QueueDeleteNoWait(this IChannel channel, string queue, bool ifUnused = false, bool ifEmpty = false) { - model.QueueDeleteNoWait(queue, ifUnused, ifEmpty); + channel.QueueDeleteNoWait(queue, ifUnused, ifEmpty); } /// /// (Spec method) Unbinds a queue. /// - public static void QueueUnbind(this IModel model, string queue, string exchange, string routingKey, IDictionary arguments = null) + public static void QueueUnbind(this IChannel channel, string queue, string exchange, string routingKey, IDictionary arguments = null) { - model.QueueUnbind(queue, exchange, routingKey, arguments); + channel.QueueUnbind(queue, exchange, routingKey, arguments); } /// @@ -205,30 +205,30 @@ public static void QueueUnbind(this IModel model, string queue, string exchange, /// method does nothing but wait for the in-progress close /// operation to complete. This method will not return to the /// caller until the shutdown is complete. - /// In comparison to normal method, will not throw - /// or or any other during closing model. + /// In comparison to normal method, will not throw + /// or or any other during closing channel. /// - public static void Abort(this IModel model) + public static void Abort(this IChannel channel) { - model.Close(Constants.ReplySuccess, "Goodbye", true); + channel.Close(Constants.ReplySuccess, "Goodbye", true); } /// /// Abort this session. /// /// - /// The method behaves in the same way as , with the only - /// difference that the model is closed with the given model close code and message. + /// The method behaves in the same way as , with the only + /// difference that the channel is closed with the given channel close code and message. /// /// The close code (See under "Reply Codes" in the AMQP specification) /// /// - /// A message indicating the reason for closing the model + /// A message indicating the reason for closing the channel /// /// - public static void Abort(this IModel model, ushort replyCode, string replyText) + public static void Abort(this IChannel channel, ushort replyCode, string replyText) { - model.Close(replyCode, replyText, true); + channel.Close(replyCode, replyText, true); } /// Close this session. @@ -238,26 +238,26 @@ public static void Abort(this IModel model, ushort replyCode, string replyText) /// operation to complete. This method will not return to the /// caller until the shutdown is complete. /// - public static void Close(this IModel model) + public static void Close(this IChannel channel) { - model.Close(Constants.ReplySuccess, "Goodbye", false); + channel.Close(Constants.ReplySuccess, "Goodbye", false); } /// Close this session. /// /// The method behaves in the same way as Close(), with the only - /// difference that the model is closed with the given model + /// difference that the channel is closed with the given channel /// close code and message. /// /// The close code (See under "Reply Codes" in the AMQP specification) /// /// - /// A message indicating the reason for closing the model + /// A message indicating the reason for closing the channel /// /// - public static void Close(this IModel model, ushort replyCode, string replyText) + public static void Close(this IChannel channel, ushort replyCode, string replyText) { - model.Close(replyCode, replyText, false); + channel.Close(replyCode, replyText, false); } } } diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 4f000e4043..745efe79e5 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -226,8 +226,8 @@ public interface IConnection : INetworkConnection, IDisposable void Close(ushort reasonCode, string reasonText, TimeSpan timeout, bool abort); /// - /// Create and return a fresh channel, session, and model. + /// Create and return a fresh channel, session, and channel. /// - IModel CreateModel(); + IChannel CreateChannel(); } } diff --git a/projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs b/projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs index 444b46c70a..0457caa184 100644 --- a/projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs +++ b/projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs @@ -10,7 +10,7 @@ public static class IConnectionExtensions /// Close this connection and all its channels. /// /// - /// Note that all active channels, sessions, and models will be + /// Note that all active channels and sessions will be /// closed if this method is called. It will wait for the in-progress /// close operation to complete. This method will not return to the caller /// until the shutdown is complete. If the connection is already closed @@ -45,7 +45,7 @@ public static void Close(this IConnection connection, ushort reasonCode, string /// and wait with a timeout for all the in-progress close operations to complete. /// /// - /// Note that all active channels, sessions, and models will be + /// Note that all active channels and sessions will be /// closed if this method is called. It will wait for the in-progress /// close operation to complete with a timeout. If the connection is /// already closed (or closing), then this method will do nothing. @@ -86,7 +86,7 @@ public static void Close(this IConnection connection, ushort reasonCode, string /// Abort this connection and all its channels. /// /// - /// Note that all active channels, sessions, and models will be closed if this method is called. + /// Note that all active channels and sessions will be closed if this method is called. /// In comparison to normal method, will not throw /// during closing connection. ///This method waits infinitely for the in-progress close operation to complete. diff --git a/projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs b/projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs index cfc0c16d31..22919dc0a4 100644 --- a/projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs +++ b/projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs @@ -34,7 +34,7 @@ namespace RabbitMQ.Client { /// - /// Information about the reason why a particular model, session, or connection was destroyed. + /// Information about the reason why a particular channel, session, or connection was destroyed. /// /// /// The and properties should be used to determine the originator of the shutdown event. diff --git a/projects/RabbitMQ.Client/client/events/AsyncEventingBasicConsumer.cs b/projects/RabbitMQ.Client/client/events/AsyncEventingBasicConsumer.cs index ac83df6b25..2dc046badc 100644 --- a/projects/RabbitMQ.Client/client/events/AsyncEventingBasicConsumer.cs +++ b/projects/RabbitMQ.Client/client/events/AsyncEventingBasicConsumer.cs @@ -6,8 +6,8 @@ namespace RabbitMQ.Client.Events { public class AsyncEventingBasicConsumer : AsyncDefaultBasicConsumer { - ///Constructor which sets the Model property to the given value. - public AsyncEventingBasicConsumer(IModel model) : base(model) + ///Constructor which sets the Channel property to the given value. + public AsyncEventingBasicConsumer(IChannel channel) : base(channel) { } @@ -78,9 +78,9 @@ public override Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, b } ///Fires the Shutdown event. - public override async Task HandleModelShutdown(object model, ShutdownEventArgs reason) + public override async Task HandleChannelShutdown(object channel, ShutdownEventArgs reason) { - await base.HandleModelShutdown(model, reason).ConfigureAwait(false); + await base.HandleChannelShutdown(channel, reason).ConfigureAwait(false); if (!_shutdownWrapper.IsEmpty) { await _shutdownWrapper.InvokeAsync(this, reason).ConfigureAwait(false); diff --git a/projects/RabbitMQ.Client/client/events/BasicDeliverEventArgs.cs b/projects/RabbitMQ.Client/client/events/BasicDeliverEventArgs.cs index 96e90f4cdf..fbd497bb0f 100644 --- a/projects/RabbitMQ.Client/client/events/BasicDeliverEventArgs.cs +++ b/projects/RabbitMQ.Client/client/events/BasicDeliverEventArgs.cs @@ -72,7 +72,7 @@ public BasicDeliverEventArgs(string consumerTag, public string ConsumerTag { get; set; } ///The delivery tag for this delivery. See - ///IModel.BasicAck. + ///IChannel.BasicAck. public ulong DeliveryTag { get; set; } ///The exchange the message was originally published diff --git a/projects/RabbitMQ.Client/client/events/CallbackExceptionEventArgs.cs b/projects/RabbitMQ.Client/client/events/CallbackExceptionEventArgs.cs index 5b7d193d0c..61d47b8190 100644 --- a/projects/RabbitMQ.Client/client/events/CallbackExceptionEventArgs.cs +++ b/projects/RabbitMQ.Client/client/events/CallbackExceptionEventArgs.cs @@ -60,7 +60,7 @@ protected BaseExceptionEventArgs(IDictionary detail, Exception e /// When an exception is thrown from a callback registered with /// part of the RabbitMQ .NET client library, it is caught, /// packaged into a CallbackExceptionEventArgs, and passed through - /// the appropriate IModel's or IConnection's CallbackException + /// the appropriate IChannel's or IConnection's CallbackException /// event handlers. If an exception is thrown in a /// CallbackException handler, it is silently swallowed, as /// CallbackException is the last chance to handle these kinds of diff --git a/projects/RabbitMQ.Client/client/events/EventingBasicConsumer.cs b/projects/RabbitMQ.Client/client/events/EventingBasicConsumer.cs index 842ce37a11..681247ea56 100644 --- a/projects/RabbitMQ.Client/client/events/EventingBasicConsumer.cs +++ b/projects/RabbitMQ.Client/client/events/EventingBasicConsumer.cs @@ -37,9 +37,9 @@ namespace RabbitMQ.Client.Events ///methods as separate events. public class EventingBasicConsumer : DefaultBasicConsumer { - ///Constructor which sets the Model property to the + ///Constructor which sets the Channel property to the ///given value. - public EventingBasicConsumer(IModel model) : base(model) + public EventingBasicConsumer(IChannel channel) : base(channel) { } @@ -56,7 +56,7 @@ public EventingBasicConsumer(IModel model) : base(model) ///Fires when the server confirms successful consumer registration. public event EventHandler Registered; - ///Fires on model (channel) shutdown, both client and server initiated. + ///Fires on channel (channel) shutdown, both client and server initiated. public event EventHandler Shutdown; ///Fires when the server confirms successful consumer cancellation. @@ -93,9 +93,9 @@ public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, b } ///Fires the Shutdown event. - public override void HandleModelShutdown(object model, ShutdownEventArgs reason) + public override void HandleChannelShutdown(object channel, ShutdownEventArgs reason) { - base.HandleModelShutdown(model, reason); + base.HandleChannelShutdown(channel, reason); Shutdown?.Invoke(this, reason); } } diff --git a/projects/RabbitMQ.Client/client/exceptions/OperationInterruptedException.cs b/projects/RabbitMQ.Client/client/exceptions/OperationInterruptedException.cs index ad739931be..891ca1bec6 100644 --- a/projects/RabbitMQ.Client/client/exceptions/OperationInterruptedException.cs +++ b/projects/RabbitMQ.Client/client/exceptions/OperationInterruptedException.cs @@ -38,7 +38,7 @@ namespace RabbitMQ.Client.Exceptions /// broker. For example, if a TCP connection dropping causes the /// destruction of a session in the middle of a QueueDeclare /// operation, an OperationInterruptedException will be thrown to - /// the caller of IModel.QueueDeclare. + /// the caller of IChannel.QueueDeclare. /// [Serializable] public class OperationInterruptedException diff --git a/projects/RabbitMQ.Client/client/exceptions/UnexpectedMethodException.cs b/projects/RabbitMQ.Client/client/exceptions/UnexpectedMethodException.cs index 84c519d33a..6b397e1d0f 100644 --- a/projects/RabbitMQ.Client/client/exceptions/UnexpectedMethodException.cs +++ b/projects/RabbitMQ.Client/client/exceptions/UnexpectedMethodException.cs @@ -35,7 +35,7 @@ namespace RabbitMQ.Client.Exceptions { /// - /// Thrown when the model receives an RPC reply that it wasn't expecting. + /// Thrown when the channel receives an RPC reply that it wasn't expecting. /// [Serializable] public class UnexpectedMethodException : ProtocolViolationException diff --git a/projects/RabbitMQ.Client/client/framing/Model.cs b/projects/RabbitMQ.Client/client/framing/Channel.cs similarity index 79% rename from projects/RabbitMQ.Client/client/framing/Model.cs rename to projects/RabbitMQ.Client/client/framing/Channel.cs index e5659441be..442534f7d7 100644 --- a/projects/RabbitMQ.Client/client/framing/Model.cs +++ b/projects/RabbitMQ.Client/client/framing/Channel.cs @@ -31,60 +31,59 @@ using System.Collections.Generic; using RabbitMQ.Client.client.framing; -using RabbitMQ.Client.client.impl; using RabbitMQ.Client.Impl; namespace RabbitMQ.Client.Framing.Impl { - internal class Model : ModelBase + internal class Channel : ChannelBase { - public Model(ConnectionConfig config, ISession session) : base(config, session) + public Channel(ConnectionConfig config, ISession session) : base(config, session) { } public override void ConnectionTuneOk(ushort channelMax, uint frameMax, ushort heartbeat) { - ModelSend(new ConnectionTuneOk(channelMax, frameMax, heartbeat)); + ChannelSend(new ConnectionTuneOk(channelMax, frameMax, heartbeat)); } public override void _Private_BasicCancel(string consumerTag, bool nowait) { - ModelSend(new BasicCancel(consumerTag, nowait)); + ChannelSend(new BasicCancel(consumerTag, nowait)); } public override void _Private_BasicConsume(string queue, string consumerTag, bool noLocal, bool autoAck, bool exclusive, bool nowait, IDictionary arguments) { - ModelSend(new BasicConsume(queue, consumerTag, noLocal, autoAck, exclusive, nowait, arguments)); + ChannelSend(new BasicConsume(queue, consumerTag, noLocal, autoAck, exclusive, nowait, arguments)); } public override void _Private_BasicGet(string queue, bool autoAck) { - ModelSend(new BasicGet(queue, autoAck)); + ChannelSend(new BasicGet(queue, autoAck)); } public override void _Private_BasicRecover(bool requeue) { - ModelSend(new BasicRecover(requeue)); + ChannelSend(new BasicRecover(requeue)); } public override void _Private_ChannelClose(ushort replyCode, string replyText, ushort classId, ushort methodId) { - ModelSend(new ChannelClose(replyCode, replyText, classId, methodId)); + ChannelSend(new ChannelClose(replyCode, replyText, classId, methodId)); } public override void _Private_ChannelCloseOk() { - ModelSend(new ChannelCloseOk()); + ChannelSend(new ChannelCloseOk()); } public override void _Private_ChannelFlowOk(bool active) { - ModelSend(new ChannelFlowOk(active)); + ChannelSend(new ChannelFlowOk(active)); } public override void _Private_ChannelOpen() { - ModelRpc(new ChannelOpen(), ProtocolCommandId.ChannelOpenOk); + ChannelRpc(new ChannelOpen(), ProtocolCommandId.ChannelOpenOk); } public override void _Private_ConfirmSelect(bool nowait) @@ -92,37 +91,37 @@ public override void _Private_ConfirmSelect(bool nowait) var method = new ConfirmSelect(nowait); if (nowait) { - ModelSend(method); + ChannelSend(method); } else { - ModelRpc(method, ProtocolCommandId.ConfirmSelectOk); + ChannelRpc(method, ProtocolCommandId.ConfirmSelectOk); } } public override void _Private_ConnectionCloseOk() { - ModelSend(new ConnectionCloseOk()); + ChannelSend(new ConnectionCloseOk()); } public override void _Private_ConnectionOpen(string virtualHost) { - ModelSend(new ConnectionOpen(virtualHost)); + ChannelSend(new ConnectionOpen(virtualHost)); } public override void _Private_ConnectionSecureOk(byte[] response) { - ModelSend(new ConnectionSecureOk(response)); + ChannelSend(new ConnectionSecureOk(response)); } public override void _Private_ConnectionStartOk(IDictionary clientProperties, string mechanism, byte[] response, string locale) { - ModelSend(new ConnectionStartOk(clientProperties, mechanism, response, locale)); + ChannelSend(new ConnectionStartOk(clientProperties, mechanism, response, locale)); } public override void _Private_UpdateSecret(byte[] newSecret, string reason) { - ModelRpc(new ConnectionUpdateSecret(newSecret, reason), ProtocolCommandId.ConnectionUpdateSecretOk); + ChannelRpc(new ConnectionUpdateSecret(newSecret, reason), ProtocolCommandId.ConnectionUpdateSecretOk); } public override void _Private_ExchangeBind(string destination, string source, string routingKey, bool nowait, IDictionary arguments) @@ -130,11 +129,11 @@ public override void _Private_ExchangeBind(string destination, string source, st var method = new ExchangeBind(destination, source, routingKey, nowait, arguments); if (nowait) { - ModelSend(method); + ChannelSend(method); } else { - ModelRpc(method, ProtocolCommandId.ExchangeBindOk); + ChannelRpc(method, ProtocolCommandId.ExchangeBindOk); } } @@ -143,11 +142,11 @@ public override void _Private_ExchangeDeclare(string exchange, string type, bool var method = new ExchangeDeclare(exchange, type, passive, durable, autoDelete, @internal, nowait, arguments); if (nowait) { - ModelSend(method); + ChannelSend(method); } else { - ModelRpc(method, ProtocolCommandId.ExchangeDeclareOk); + ChannelRpc(method, ProtocolCommandId.ExchangeDeclareOk); } } @@ -156,11 +155,11 @@ public override void _Private_ExchangeDelete(string exchange, bool ifUnused, boo var method = new ExchangeDelete(exchange, ifUnused, nowait); if (nowait) { - ModelSend(method); + ChannelSend(method); } else { - ModelRpc(method, ProtocolCommandId.ExchangeDeleteOk); + ChannelRpc(method, ProtocolCommandId.ExchangeDeleteOk); } } @@ -169,11 +168,11 @@ public override void _Private_ExchangeUnbind(string destination, string source, var method = new ExchangeUnbind(destination, source, routingKey, nowait, arguments); if (nowait) { - ModelSend(method); + ChannelSend(method); } else { - ModelRpc(method, ProtocolCommandId.ExchangeUnbindOk); + ChannelRpc(method, ProtocolCommandId.ExchangeUnbindOk); } } @@ -182,11 +181,11 @@ public override void _Private_QueueBind(string queue, string exchange, string ro var method = new QueueBind(queue, exchange, routingKey, nowait, arguments); if (nowait) { - ModelSend(method); + ChannelSend(method); } else { - ModelRpc(method, ProtocolCommandId.QueueBindOk); + ChannelRpc(method, ProtocolCommandId.QueueBindOk); } } @@ -195,11 +194,11 @@ public override void _Private_QueueDeclare(string queue, bool passive, bool dura var method = new QueueDeclare(queue, passive, durable, exclusive, autoDelete, nowait, arguments); if (nowait) { - ModelSend(method); + ChannelSend(method); } else { - ModelSend(method); + ChannelSend(method); } } @@ -208,11 +207,11 @@ public override uint _Private_QueueDelete(string queue, bool ifUnused, bool ifEm var method = new QueueDelete(queue, ifUnused, ifEmpty, nowait); if (nowait) { - ModelSend(method); + ChannelSend(method); return 0xFFFFFFFF; } - return ModelRpc(method, ProtocolCommandId.QueueDeleteOk, memory => new QueueDeleteOk(memory.Span)._messageCount); + return ChannelRpc(method, ProtocolCommandId.QueueDeleteOk, memory => new QueueDeleteOk(memory.Span)._messageCount); } public override uint _Private_QueuePurge(string queue, bool nowait) @@ -220,56 +219,56 @@ public override uint _Private_QueuePurge(string queue, bool nowait) var method = new QueuePurge(queue, nowait); if (nowait) { - ModelSend(method); + ChannelSend(method); return 0xFFFFFFFF; } - return ModelRpc(method, ProtocolCommandId.QueuePurgeOk, memory => new QueuePurgeOk(memory.Span)._messageCount); + return ChannelRpc(method, ProtocolCommandId.QueuePurgeOk, memory => new QueuePurgeOk(memory.Span)._messageCount); } public override void BasicAck(ulong deliveryTag, bool multiple) { - ModelSend(new BasicAck(deliveryTag, multiple)); + ChannelSend(new BasicAck(deliveryTag, multiple)); } public override void BasicNack(ulong deliveryTag, bool multiple, bool requeue) { - ModelSend(new BasicNack(deliveryTag, multiple, requeue)); + ChannelSend(new BasicNack(deliveryTag, multiple, requeue)); } public override void BasicQos(uint prefetchSize, ushort prefetchCount, bool global) { - ModelRpc(new BasicQos(prefetchSize, prefetchCount, global), ProtocolCommandId.BasicQosOk); + ChannelRpc(new BasicQos(prefetchSize, prefetchCount, global), ProtocolCommandId.BasicQosOk); } public override void BasicRecoverAsync(bool requeue) { - ModelSend(new BasicRecoverAsync(requeue)); + ChannelSend(new BasicRecoverAsync(requeue)); } public override void BasicReject(ulong deliveryTag, bool requeue) { - ModelSend(new BasicReject(deliveryTag, requeue)); + ChannelSend(new BasicReject(deliveryTag, requeue)); } public override void QueueUnbind(string queue, string exchange, string routingKey, IDictionary arguments) { - ModelRpc(new QueueUnbind(queue, exchange, routingKey, arguments), ProtocolCommandId.QueueUnbindOk); + ChannelRpc(new QueueUnbind(queue, exchange, routingKey, arguments), ProtocolCommandId.QueueUnbindOk); } public override void TxCommit() { - ModelRpc(new TxCommit(), ProtocolCommandId.TxCommitOk); + ChannelRpc(new TxCommit(), ProtocolCommandId.TxCommitOk); } public override void TxRollback() { - ModelRpc(new TxRollback(), ProtocolCommandId.TxRollbackOk); + ChannelRpc(new TxRollback(), ProtocolCommandId.TxRollbackOk); } public override void TxSelect() { - ModelRpc(new TxSelect(), ProtocolCommandId.TxSelectOk); + ChannelRpc(new TxSelect(), ProtocolCommandId.TxSelectOk); } protected override bool DispatchAsynchronous(in IncomingCommand cmd) diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs similarity index 95% rename from projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs rename to projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs index 51f1a9686e..a1ba8b25c8 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs @@ -40,10 +40,10 @@ namespace RabbitMQ.Client.Impl { - internal sealed class AutorecoveringModel : IModel, IRecoverable + internal sealed class AutorecoveringChannel : IChannel, IRecoverable { private AutorecoveringConnection _connection; - private RecoveryAwareModel _innerChannel; + private RecoveryAwareChannel _innerChannel; private bool _disposed; private ushort _prefetchCountConsumer; @@ -53,7 +53,7 @@ internal sealed class AutorecoveringModel : IModel, IRecoverable internal IConsumerDispatcher ConsumerDispatcher => InnerChannel.ConsumerDispatcher; - internal RecoveryAwareModel InnerChannel + internal RecoveryAwareChannel InnerChannel { get { @@ -68,7 +68,7 @@ public TimeSpan ContinuationTimeout set => InnerChannel.ContinuationTimeout = value; } - public AutorecoveringModel(AutorecoveringConnection conn, RecoveryAwareModel innerChannel) + public AutorecoveringChannel(AutorecoveringConnection conn, RecoveryAwareChannel innerChannel) { _connection = conn; _innerChannel = innerChannel; @@ -110,10 +110,10 @@ public event EventHandler FlowControl remove { InnerChannel.FlowControl -= value; } } - public event EventHandler ModelShutdown + public event EventHandler ChannelShutdown { - add => InnerChannel.ModelShutdown += value; - remove => InnerChannel.ModelShutdown -= value; + add => InnerChannel.ChannelShutdown += value; + remove => InnerChannel.ChannelShutdown -= value; } public event EventHandler Recovery @@ -143,7 +143,7 @@ internal void AutomaticallyRecover(AutorecoveringConnection conn, bool recoverCo ThrowIfDisposed(); _connection = conn; - var newChannel = conn.CreateNonRecoveringModel(); + var newChannel = conn.CreateNonRecoveringChannel(); newChannel.TakeOver(_innerChannel); if (_prefetchCountConsumer != 0) @@ -169,7 +169,7 @@ internal void AutomaticallyRecover(AutorecoveringConnection conn, bool recoverCo /* * https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/1140 * If this assignment is not done before recovering consumers, there is a good - * chance that an invalid Model will be used to handle a basic.deliver frame, + * chance that an invalid Channel will be used to handle a basic.deliver frame, * with the resulting basic.ack never getting sent out. */ _innerChannel = newChannel; @@ -421,7 +421,7 @@ private void ThrowIfDisposed() ThrowDisposed(); } - static void ThrowDisposed() => throw new ObjectDisposedException(typeof(AutorecoveringModel).FullName); + static void ThrowDisposed() => throw new ObjectDisposedException(typeof(AutorecoveringChannel).FullName); } } } diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recording.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recording.cs index 609730aefa..c110660bc1 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recording.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recording.cs @@ -43,7 +43,7 @@ internal sealed partial class AutorecoveringConnection private readonly Dictionary _recordedQueues = new Dictionary(); private readonly HashSet _recordedBindings = new HashSet(); private readonly Dictionary _recordedConsumers = new Dictionary(); - private readonly List _models = new List(); + private readonly List _channels = new List(); internal int RecordedExchangesCount => _recordedExchanges.Count; @@ -238,19 +238,19 @@ private void UpdateConsumer(string oldTag, string newTag, in RecordedConsumer co } } - private void RecordChannel(AutorecoveringModel m) + private void RecordChannel(AutorecoveringChannel m) { - lock (_models) + lock (_channels) { - _models.Add(m); + _channels.Add(m); } } - internal void DeleteRecordedChannel(AutorecoveringModel model) + internal void DeleteRecordedChannel(AutorecoveringChannel channel) { - lock (_models) + lock (_channels) { - _models.Remove(model); + _channels.Remove(channel); } } } diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs index b4842f0a98..9cce9f45ef 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs @@ -143,7 +143,7 @@ private bool TryPerformAutomaticRecovery() // 2. Recover queues // 3. Recover bindings // 4. Recover consumers - using (var recoveryChannel = _innerConnection.CreateModel()) + using (var recoveryChannel = _innerConnection.CreateChannel()) { RecoverExchanges(recoveryChannel); RecoverQueues(recoveryChannel); @@ -151,7 +151,7 @@ private bool TryPerformAutomaticRecovery() } } - RecoverModelsAndItsConsumers(); + RecoverChannelsAndItsConsumers(); } ESLog.Info("Connection recovery completed"); @@ -211,7 +211,7 @@ private bool TryRecoverConnectionDelegate() return false; } - private void RecoverExchanges(IModel channel) + private void RecoverExchanges(IChannel channel) { foreach (var recordedExchange in _recordedExchanges.Values) { @@ -226,7 +226,7 @@ private void RecoverExchanges(IModel channel) } } - private void RecoverQueues(IModel channel) + private void RecoverQueues(IChannel channel) { foreach (var recordedQueue in _recordedQueues.Values.ToArray()) { @@ -264,7 +264,7 @@ private void RecoverQueues(IModel channel) } } - private void RecoverBindings(IModel channel) + private void RecoverBindings(IChannel channel) { foreach (var binding in _recordedBindings) { @@ -279,7 +279,7 @@ private void RecoverBindings(IModel channel) } } - internal void RecoverConsumers(AutorecoveringModel channelToRecover, IModel channelToUse) + internal void RecoverConsumers(AutorecoveringChannel channelToRecover, IChannel channelToUse) { foreach (var consumer in _recordedConsumers.Values.ToArray()) { @@ -308,11 +308,11 @@ internal void RecoverConsumers(AutorecoveringModel channelToRecover, IModel chan } } - private void RecoverModelsAndItsConsumers() + private void RecoverChannelsAndItsConsumers() { - lock (_models) + lock (_channels) { - foreach (AutorecoveringModel m in _models) + foreach (AutorecoveringChannel m in _channels) { m.AutomaticallyRecover(this, _config.TopologyRecoveryEnabled); } diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 88797f3e74..f767e12971 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -162,10 +162,10 @@ public event EventHandler RecoveringConsumer public IProtocol Protocol => Endpoint.Protocol; - public RecoveryAwareModel CreateNonRecoveringModel() + public RecoveryAwareChannel CreateNonRecoveringChannel() { ISession session = InnerConnection.CreateSession(); - var result = new RecoveryAwareModel(_config, session); + var result = new RecoveryAwareChannel(_config, session); result._Private_ChannelOpen(); return result; } @@ -197,10 +197,10 @@ public void Close(ushort reasonCode, string reasonText, TimeSpan timeout, bool a } } - public IModel CreateModel() + public IChannel CreateChannel() { EnsureIsOpen(); - AutorecoveringModel m = new AutorecoveringModel(this, CreateNonRecoveringModel()); + AutorecoveringChannel m = new AutorecoveringChannel(this, CreateNonRecoveringChannel()); RecordChannel(m); return m; } @@ -222,7 +222,7 @@ public void Dispose() } finally { - _models.Clear(); + _channels.Clear(); _innerConnection = null; _disposed = true; } diff --git a/projects/RabbitMQ.Client/client/impl/ModelBase.cs b/projects/RabbitMQ.Client/client/impl/ChannelBase.cs similarity index 96% rename from projects/RabbitMQ.Client/client/impl/ModelBase.cs rename to projects/RabbitMQ.Client/client/impl/ChannelBase.cs index 5620ff067c..dfd88782af 100644 --- a/projects/RabbitMQ.Client/client/impl/ModelBase.cs +++ b/projects/RabbitMQ.Client/client/impl/ChannelBase.cs @@ -46,7 +46,7 @@ namespace RabbitMQ.Client.Impl { - internal abstract class ModelBase : IModel, IRecoverable + internal abstract class ChannelBase : IChannel, IRecoverable { ///Only used to kick-start a connection open ///sequence. See @@ -66,7 +66,7 @@ internal abstract class ModelBase : IModel, IRecoverable internal IConsumerDispatcher ConsumerDispatcher { get; } - protected ModelBase(ConnectionConfig config, ISession session) + protected ChannelBase(ConnectionConfig config, ISession session) { ContinuationTimeout = config.ContinuationTimeout; ConsumerDispatcher = config.DispatchConsumersAsync ? @@ -80,8 +80,8 @@ protected ModelBase(ConnectionConfig config, ISession session) _basicReturnWrapper = new EventingWrapper("OnBasicReturn", onException); _callbackExceptionWrapper = new EventingWrapper(string.Empty, (exception, context) => { }); _flowControlWrapper = new EventingWrapper("OnFlowControl", onException); - _modelShutdownWrapper = new EventingWrapper("OnModelShutdown", onException); - _recoveryWrapper = new EventingWrapper("OnModelRecovery", onException); + _channelShutdownWrapper = new EventingWrapper("OnChannelShutdown", onException); + _recoveryWrapper = new EventingWrapper("OnChannelRecovery", onException); session.CommandReceived = HandleCommand; session.SessionShutdown += OnSessionShutdown; Session = session; @@ -132,22 +132,22 @@ public event EventHandler FlowControl } private EventingWrapper _flowControlWrapper; - public event EventHandler ModelShutdown + public event EventHandler ChannelShutdown { add { if (IsOpen) { - _modelShutdownWrapper.AddHandler(value); + _channelShutdownWrapper.AddHandler(value); } else { value(this, CloseReason); } } - remove => _modelShutdownWrapper.RemoveHandler(value); + remove => _channelShutdownWrapper.RemoveHandler(value); } - private EventingWrapper _modelShutdownWrapper; + private EventingWrapper _channelShutdownWrapper; public event EventHandler Recovery { @@ -177,7 +177,7 @@ public IBasicConsumer DefaultConsumer public ISession Session { get; private set; } - protected void TakeOver(ModelBase other) + protected void TakeOver(ChannelBase other) { _basicAcksWrapper.Takeover(other._basicAcksWrapper); _basicNacksWrapper.Takeover(other._basicNacksWrapper); @@ -185,7 +185,7 @@ protected void TakeOver(ModelBase other) _basicReturnWrapper.Takeover(other._basicReturnWrapper); _callbackExceptionWrapper.Takeover(other._callbackExceptionWrapper); _flowControlWrapper.Takeover(other._flowControlWrapper); - _modelShutdownWrapper.Takeover(other._modelShutdownWrapper); + _channelShutdownWrapper.Takeover(other._channelShutdownWrapper); _recoveryWrapper.Takeover(other._recoveryWrapper); } @@ -197,7 +197,7 @@ public void Close(ushort replyCode, string replyText, bool abort) private async Task CloseAsync(ShutdownEventArgs reason, bool abort) { var k = new ShutdownContinuation(); - ModelShutdown += k.OnConnectionShutdown; + ChannelShutdown += k.OnConnectionShutdown; try { @@ -233,7 +233,7 @@ private async Task CloseAsync(ShutdownEventArgs reason, bool abort) } finally { - ModelShutdown -= k.OnConnectionShutdown; + ChannelShutdown -= k.OnConnectionShutdown; } } @@ -310,7 +310,7 @@ protected void Enqueue(IRpcContinuation k) } else { - k.HandleModelShutdown(CloseReason); + k.HandleChannelShutdown(CloseReason); } } @@ -333,7 +333,7 @@ private void HandleCommand(in IncomingCommand cmd) } } - protected void ModelRpc(in TMethod method, ProtocolCommandId returnCommandId) + protected void ChannelRpc(in TMethod method, ProtocolCommandId returnCommandId) where TMethod : struct, IOutgoingAmqpMethod { var k = new SimpleBlockingRpcContinuation(); @@ -353,7 +353,7 @@ protected void ModelRpc(in TMethod method, ProtocolCommandId returnComm } } - protected TReturn ModelRpc(in TMethod method, ProtocolCommandId returnCommandId, Func, TReturn> createFunc) + protected TReturn ChannelRpc(in TMethod method, ProtocolCommandId returnCommandId, Func, TReturn> createFunc) where TMethod : struct, IOutgoingAmqpMethod { var k = new SimpleBlockingRpcContinuation(); @@ -378,13 +378,13 @@ protected TReturn ModelRpc(in TMethod method, ProtocolCommandI } [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected void ModelSend(in T method) where T : struct, IOutgoingAmqpMethod + protected void ChannelSend(in T method) where T : struct, IOutgoingAmqpMethod { Session.Transmit(in method); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected void ModelSend(in TMethod method, in THeader header, ReadOnlyMemory body) + protected void ChannelSend(in TMethod method, in THeader header, ReadOnlyMemory body) where TMethod : struct, IOutgoingAmqpMethod where THeader : IAmqpHeader { @@ -400,7 +400,7 @@ internal void OnCallbackException(CallbackExceptionEventArgs args) _callbackExceptionWrapper.Invoke(this, args); } - ///Broadcasts notification of the final shutdown of the model. + ///Broadcasts notification of the final shutdown of the channel. /// /// ///Do not call anywhere other than at the end of OnSessionShutdown. @@ -412,10 +412,10 @@ internal void OnCallbackException(CallbackExceptionEventArgs args) ///shutdown event. See the definition of Enqueue() above. /// /// - private void OnModelShutdown(ShutdownEventArgs reason) + private void OnChannelShutdown(ShutdownEventArgs reason) { - _continuationQueue.HandleModelShutdown(reason); - _modelShutdownWrapper.Invoke(this, reason); + _continuationQueue.HandleChannelShutdown(reason); + _channelShutdownWrapper.Invoke(this, reason); lock (_confirmLock) { if (_confirmsTaskCompletionSources?.Count > 0) @@ -435,7 +435,7 @@ private void OnSessionShutdown(object sender, ShutdownEventArgs reason) { ConsumerDispatcher.Quiesce(); SetCloseReason(reason); - OnModelShutdown(reason); + OnChannelShutdown(reason); ConsumerDispatcher.ShutdownAsync(reason).GetAwaiter().GetResult(); } @@ -910,7 +910,7 @@ public void BasicPublish(string exchange, string routingKey, in TPr } var cmd = new BasicPublish(exchange, routingKey, mandatory, default); - ModelSend(in cmd, in basicProperties, body); + ChannelSend(in cmd, in basicProperties, body); } public void BasicPublish(CachedString exchange, CachedString routingKey, in TProperties basicProperties, ReadOnlyMemory body, bool mandatory) @@ -925,7 +925,7 @@ public void BasicPublish(CachedString exchange, CachedString routin } var cmd = new BasicPublishMemory(exchange.Bytes, routingKey.Bytes, mandatory, default); - ModelSend(in cmd, in basicProperties, body); + ChannelSend(in cmd, in basicProperties, body); } public void UpdateSecret(string newSecret, string reason) diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs index 7c53fe579b..1766dc7d7a 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs @@ -45,7 +45,7 @@ internal sealed partial class Connection { public void UpdateSecret(string newSecret, string reason) { - _model0.UpdateSecret(newSecret, reason); + _channel0.UpdateSecret(newSecret, reason); } internal void NotifyReceivedCloseOk() @@ -74,14 +74,14 @@ private void Open() { RabbitMqClientEventSource.Log.ConnectionOpened(); StartAndTune(); - _model0.ConnectionOpen(_config.VirtualHost); + _channel0.ConnectionOpen(_config.VirtualHost); } private void StartAndTune() { var connectionStartCell = new BlockingCell(); - _model0.m_connectionStartCell = connectionStartCell; - _model0.HandshakeContinuationTimeout = _config.HandshakeContinuationTimeout; + _channel0.m_connectionStartCell = connectionStartCell; + _channel0.HandshakeContinuationTimeout = _config.HandshakeContinuationTimeout; _frameHandler.ReadTimeout = _config.HandshakeContinuationTimeout; _frameHandler.SendHeader(); @@ -117,14 +117,14 @@ private void StartAndTune() ConnectionSecureOrTune res; if (challenge is null) { - res = _model0.ConnectionStartOk(ClientProperties, + res = _channel0.ConnectionStartOk(ClientProperties, mechanismFactory.Name, response, "en_US"); } else { - res = _model0.ConnectionSecureOk(response); + res = _channel0.ConnectionSecureOk(response); } if (res.m_challenge is null) @@ -159,7 +159,7 @@ private void StartAndTune() uint heartbeatInSeconds = NegotiatedMaxValue((uint)_config.HeartbeatInterval.TotalSeconds, (uint)connectionTune.m_heartbeatInSeconds); Heartbeat = TimeSpan.FromSeconds(heartbeatInSeconds); - _model0.ConnectionTuneOk(channelMax, frameMax, (ushort)Heartbeat.TotalSeconds); + _channel0.ConnectionTuneOk(channelMax, frameMax, (ushort)Heartbeat.TotalSeconds); // now we can start heartbeat timers MaybeStartHeartbeatTimers(); diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs b/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs index 14d3a08feb..52bb68d2ec 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs @@ -200,7 +200,7 @@ await ReceiveLoop() } catch (EndOfStreamException eose) { - if (_model0.CloseReason is null) + if (_channel0.CloseReason is null) { LogCloseError("Connection didn't close cleanly. Socket closed unexpectedly", eose); } diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 5fa65cb0fb..f653cd6ee1 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -49,7 +49,7 @@ internal sealed partial class Connection : IConnection private volatile bool _closed; private readonly ConnectionConfig _config; - private readonly ModelBase _model0; + private readonly ChannelBase _channel0; private readonly MainSession _session0; private Guid _id = Guid.NewGuid(); @@ -71,7 +71,7 @@ public Connection(ConnectionConfig config, IFrameHandler frameHandler) _sessionManager = new SessionManager(this, 0); _session0 = new MainSession(this); - _model0 = new Model(_config, _session0); ; + _channel0 = new Channel(_config, _session0); ; ClientProperties = new Dictionary(_config.ClientProperties) { @@ -222,13 +222,13 @@ internal void TakeOver(Connection other) _connectionShutdownWrapper.Takeover(other._connectionShutdownWrapper); } - public IModel CreateModel() + public IChannel CreateChannel() { EnsureIsOpen(); ISession session = CreateSession(); - var model = new Model(_config, session); - model._Private_ChannelOpen(); - return model; + var channel = new Channel(_config, session); + channel._Private_ChannelOpen(); + return channel; } internal ISession CreateSession() @@ -310,7 +310,7 @@ internal void Close(ShutdownEventArgs reason, bool abort, TimeSpan timeout) #pragma warning restore 0168 catch (IOException ioe) { - if (_model0.CloseReason is null) + if (_channel0.CloseReason is null) { if (!abort) { @@ -365,8 +365,8 @@ private void FinishClose() MaybeStopHeartbeatTimers(); _frameHandler.Close(); - _model0.SetCloseReason(CloseReason); - _model0.FinishClose(); + _channel0.SetCloseReason(CloseReason); + _channel0.FinishClose(); RabbitMqClientEventSource.Log.ConnectionClosed(); } diff --git a/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/AsyncConsumerDispatcher.cs b/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/AsyncConsumerDispatcher.cs index d51177da06..b1f80582dc 100644 --- a/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/AsyncConsumerDispatcher.cs +++ b/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/AsyncConsumerDispatcher.cs @@ -9,8 +9,8 @@ namespace RabbitMQ.Client.ConsumerDispatching #nullable enable internal sealed class AsyncConsumerDispatcher : ConsumerDispatcherChannelBase { - public AsyncConsumerDispatcher(ModelBase model, int concurrency) - : base(model, concurrency) + public AsyncConsumerDispatcher(ChannelBase channel, int concurrency) + : base(channel, concurrency) { } @@ -28,14 +28,14 @@ protected override async Task ProcessChannelAsync() WorkType.Cancel => work.AsyncConsumer.HandleBasicCancel(work.ConsumerTag), WorkType.CancelOk => work.AsyncConsumer.HandleBasicCancelOk(work.ConsumerTag), WorkType.ConsumeOk => work.AsyncConsumer.HandleBasicConsumeOk(work.ConsumerTag), - WorkType.Shutdown => work.AsyncConsumer.HandleModelShutdown(_model, work.Reason), + WorkType.Shutdown => work.AsyncConsumer.HandleChannelShutdown(_channel, work.Reason), _ => Task.CompletedTask }; await task.ConfigureAwait(false); } catch (Exception e) { - _model.OnCallbackException(CallbackExceptionEventArgs.Build(e, work.WorkType.ToString(), work.Consumer)); + _channel.OnCallbackException(CallbackExceptionEventArgs.Build(e, work.WorkType.ToString(), work.Consumer)); } finally { diff --git a/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/ConsumerDispatcher.cs b/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/ConsumerDispatcher.cs index 37d0c69366..09aa5cc627 100644 --- a/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/ConsumerDispatcher.cs +++ b/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/ConsumerDispatcher.cs @@ -9,8 +9,8 @@ namespace RabbitMQ.Client.ConsumerDispatching #nullable enable internal sealed class ConsumerDispatcher : ConsumerDispatcherChannelBase { - public ConsumerDispatcher(ModelBase model, int concurrency) - : base(model, concurrency) + public ConsumerDispatcher(ChannelBase channel, int concurrency) + : base(channel, concurrency) { } @@ -39,13 +39,13 @@ protected override async Task ProcessChannelAsync() consumer.HandleBasicConsumeOk(consumerTag); break; case WorkType.Shutdown: - consumer.HandleModelShutdown(_model, work.Reason); + consumer.HandleChannelShutdown(_channel, work.Reason); break; } } catch (Exception e) { - _model.OnCallbackException(CallbackExceptionEventArgs.Build(e, work.WorkType.ToString(), work.Consumer)); + _channel.OnCallbackException(CallbackExceptionEventArgs.Build(e, work.WorkType.ToString(), work.Consumer)); } finally { diff --git a/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/ConsumerDispatcherChannelBase.cs b/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/ConsumerDispatcherChannelBase.cs index ff5d3535f4..f53218e6bd 100644 --- a/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/ConsumerDispatcherChannelBase.cs +++ b/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/ConsumerDispatcherChannelBase.cs @@ -9,24 +9,24 @@ namespace RabbitMQ.Client.ConsumerDispatching #nullable enable internal abstract class ConsumerDispatcherChannelBase : ConsumerDispatcherBase, IConsumerDispatcher { - protected readonly ModelBase _model; + protected readonly ChannelBase _channel; protected readonly ChannelReader _reader; private readonly ChannelWriter _writer; private readonly Task _worker; public bool IsShutdown { get; private set; } - protected ConsumerDispatcherChannelBase(ModelBase model, int concurrency) + protected ConsumerDispatcherChannelBase(ChannelBase channel, int concurrency) { - _model = model; - var channel = Channel.CreateUnbounded(new UnboundedChannelOptions + _channel = channel; + var workChannel = Channel.CreateUnbounded(new UnboundedChannelOptions { SingleReader = concurrency == 1, SingleWriter = false, AllowSynchronousContinuations = false }); - _reader = channel.Reader; - _writer = channel.Writer; + _reader = workChannel.Reader; + _writer = workChannel.Writer; Func loopStart = ProcessChannelAsync; if (concurrency == 1) diff --git a/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/FallbackConsumer.cs b/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/FallbackConsumer.cs index 866cba8069..3510be5e5d 100644 --- a/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/FallbackConsumer.cs +++ b/projects/RabbitMQ.Client/client/impl/ConsumerDispatching/FallbackConsumer.cs @@ -8,7 +8,7 @@ namespace RabbitMQ.Client.ConsumerDispatching #nullable enable internal sealed class FallbackConsumer : IBasicConsumer, IAsyncBasicConsumer { - public IModel? Model { get; } = null; + public IChannel? Channel { get; } = null; event AsyncEventHandler IAsyncBasicConsumer.ConsumerCancelled { @@ -43,9 +43,9 @@ void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bo ESLog.Info($"Unhandled {nameof(IBasicConsumer.HandleBasicDeliver)} for tag {consumerTag}"); } - void IBasicConsumer.HandleModelShutdown(object model, ShutdownEventArgs reason) + void IBasicConsumer.HandleChannelShutdown(object channel, ShutdownEventArgs reason) { - ESLog.Info($"Unhandled {nameof(IBasicConsumer.HandleModelShutdown)}"); + ESLog.Info($"Unhandled {nameof(IBasicConsumer.HandleChannelShutdown)}"); } Task IAsyncBasicConsumer.HandleBasicCancel(string consumerTag) @@ -73,9 +73,9 @@ Task IAsyncBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTa return Task.CompletedTask; } - Task IAsyncBasicConsumer.HandleModelShutdown(object model, ShutdownEventArgs reason) + Task IAsyncBasicConsumer.HandleChannelShutdown(object channel, ShutdownEventArgs reason) { - ((IBasicConsumer)this).HandleModelShutdown(model, reason); + ((IBasicConsumer)this).HandleChannelShutdown(channel, reason); return Task.CompletedTask; } } diff --git a/projects/RabbitMQ.Client/client/impl/IRpcContinuation.cs b/projects/RabbitMQ.Client/client/impl/IRpcContinuation.cs index 8cc84d66c0..3f4ee17eb7 100644 --- a/projects/RabbitMQ.Client/client/impl/IRpcContinuation.cs +++ b/projects/RabbitMQ.Client/client/impl/IRpcContinuation.cs @@ -34,6 +34,6 @@ namespace RabbitMQ.Client.Impl internal interface IRpcContinuation { void HandleCommand(in IncomingCommand cmd); - void HandleModelShutdown(ShutdownEventArgs reason); + void HandleChannelShutdown(ShutdownEventArgs reason); } } diff --git a/projects/RabbitMQ.Client/client/impl/RecordedBinding.cs b/projects/RabbitMQ.Client/client/impl/RecordedBinding.cs index e9889d9a0c..365d0e3633 100644 --- a/projects/RabbitMQ.Client/client/impl/RecordedBinding.cs +++ b/projects/RabbitMQ.Client/client/impl/RecordedBinding.cs @@ -64,7 +64,7 @@ public RecordedBinding(string destination, in RecordedBinding old) _arguments = old._arguments; } - public void Recover(IModel channel) + public void Recover(IChannel channel) { if (_isQueueBinding) { diff --git a/projects/RabbitMQ.Client/client/impl/RecordedConsumer.cs b/projects/RabbitMQ.Client/client/impl/RecordedConsumer.cs index 8ed3a7b40e..b6360358f7 100644 --- a/projects/RabbitMQ.Client/client/impl/RecordedConsumer.cs +++ b/projects/RabbitMQ.Client/client/impl/RecordedConsumer.cs @@ -36,7 +36,7 @@ namespace RabbitMQ.Client.Impl #nullable enable internal readonly struct RecordedConsumer { - public AutorecoveringModel Channel { get; } + public AutorecoveringChannel Channel { get; } public IBasicConsumer Consumer { get; } public string Queue { get; } public bool AutoAck { get; } @@ -44,7 +44,7 @@ internal readonly struct RecordedConsumer public bool Exclusive { get; } public IDictionary? Arguments { get; } - public RecordedConsumer(AutorecoveringModel channel, IBasicConsumer consumer, string queue, bool autoAck, string consumerTag, bool exclusive, IDictionary? arguments) + public RecordedConsumer(AutorecoveringChannel channel, IBasicConsumer consumer, string queue, bool autoAck, string consumerTag, bool exclusive, IDictionary? arguments) { Channel = channel; Consumer = consumer; @@ -65,7 +65,7 @@ public static RecordedConsumer WithNewQueueNameTag(string newQueueName, in Recor return new RecordedConsumer(old.Channel, old.Consumer, newQueueName, old.AutoAck, old.ConsumerTag, old.Exclusive, old.Arguments); } - public string Recover(IModel channel) + public string Recover(IChannel channel) { return channel.BasicConsume(Queue, AutoAck, ConsumerTag, false, Exclusive, Arguments, Consumer); } diff --git a/projects/RabbitMQ.Client/client/impl/RecordedExchange.cs b/projects/RabbitMQ.Client/client/impl/RecordedExchange.cs index e3afd6b253..6ca16c8a4f 100644 --- a/projects/RabbitMQ.Client/client/impl/RecordedExchange.cs +++ b/projects/RabbitMQ.Client/client/impl/RecordedExchange.cs @@ -54,9 +54,9 @@ public RecordedExchange(string name, string type, bool durable, bool isAutoDelet _arguments = arguments; } - public void Recover(IModel model) + public void Recover(IChannel channel) { - model.ExchangeDeclare(Name, _type, _durable, IsAutoDelete, _arguments); + channel.ExchangeDeclare(Name, _type, _durable, IsAutoDelete, _arguments); } public override string ToString() diff --git a/projects/RabbitMQ.Client/client/impl/RecordedQueue.cs b/projects/RabbitMQ.Client/client/impl/RecordedQueue.cs index cbcde46f4c..a3c6ef9af7 100644 --- a/projects/RabbitMQ.Client/client/impl/RecordedQueue.cs +++ b/projects/RabbitMQ.Client/client/impl/RecordedQueue.cs @@ -67,7 +67,7 @@ public RecordedQueue(string newName, in RecordedQueue old) _arguments = old._arguments; } - public string Recover(IModel channel) + public string Recover(IChannel channel) { var queueName = IsServerNamed ? string.Empty : Name; return channel.QueueDeclare(queueName, _durable, _exclusive, IsAutoDelete, _arguments).QueueName; diff --git a/projects/RabbitMQ.Client/client/impl/RecoveryAwareModel.cs b/projects/RabbitMQ.Client/client/impl/RecoveryAwareChannel.cs similarity index 92% rename from projects/RabbitMQ.Client/client/impl/RecoveryAwareModel.cs rename to projects/RabbitMQ.Client/client/impl/RecoveryAwareChannel.cs index 8a0d0105f3..e97415d713 100644 --- a/projects/RabbitMQ.Client/client/impl/RecoveryAwareModel.cs +++ b/projects/RabbitMQ.Client/client/impl/RecoveryAwareChannel.cs @@ -29,14 +29,13 @@ // Copyright (c) 2007-2020 VMware, Inc. All rights reserved. //--------------------------------------------------------------------------- -using RabbitMQ.Client.client.impl; using RabbitMQ.Client.Framing.Impl; namespace RabbitMQ.Client.Impl { - internal sealed class RecoveryAwareModel : Model + internal sealed class RecoveryAwareChannel : Channel { - public RecoveryAwareModel(ConnectionConfig config, ISession session) : base(config, session) + public RecoveryAwareChannel(ConnectionConfig config, ISession session) : base(config, session) { ActiveDeliveryTagOffset = 0; MaxSeenDeliveryTag = 0; @@ -45,7 +44,7 @@ public RecoveryAwareModel(ConnectionConfig config, ISession session) : base(conf public ulong ActiveDeliveryTagOffset { get; private set; } public ulong MaxSeenDeliveryTag { get; private set; } - internal void TakeOver(RecoveryAwareModel other) + internal void TakeOver(RecoveryAwareChannel other) { base.TakeOver(other); diff --git a/projects/RabbitMQ.Client/client/impl/RpcContinuationQueue.cs b/projects/RabbitMQ.Client/client/impl/RpcContinuationQueue.cs index 6c8e2ee194..43990d26ec 100644 --- a/projects/RabbitMQ.Client/client/impl/RpcContinuationQueue.cs +++ b/projects/RabbitMQ.Client/client/impl/RpcContinuationQueue.cs @@ -51,7 +51,7 @@ public void HandleCommand(in IncomingCommand cmd) { } - public void HandleModelShutdown(ShutdownEventArgs reason) + public void HandleChannelShutdown(ShutdownEventArgs reason) { } } @@ -87,9 +87,9 @@ public void Enqueue(IRpcContinuation k) /// implementation. /// /// - public void HandleModelShutdown(ShutdownEventArgs reason) + public void HandleChannelShutdown(ShutdownEventArgs reason) { - Next().HandleModelShutdown(reason); + Next().HandleChannelShutdown(reason); } ///Retrieve the next waiting continuation. diff --git a/projects/RabbitMQ.Client/client/impl/ShutdownContinuation.cs b/projects/RabbitMQ.Client/client/impl/ShutdownContinuation.cs index 443222789a..9992595ab3 100644 --- a/projects/RabbitMQ.Client/client/impl/ShutdownContinuation.cs +++ b/projects/RabbitMQ.Client/client/impl/ShutdownContinuation.cs @@ -49,7 +49,7 @@ internal class ShutdownContinuation // "match" IConnection, even though there's no context in // which the program could Go Wrong were it to accept the // code. The same problem appears for - // ModelShutdownEventHandler. The .NET 1.1 compiler complains + // ChannelShutdownEventHandler. The .NET 1.1 compiler complains // about these two cases, and the .NET 2.0 compiler does not - // presumably they improved the type checker with the new // release of the compiler. diff --git a/projects/RabbitMQ.Client/client/impl/SimpleBlockingRpcContinuation.cs b/projects/RabbitMQ.Client/client/impl/SimpleBlockingRpcContinuation.cs index c2c1b3fa5d..0f5da42c94 100644 --- a/projects/RabbitMQ.Client/client/impl/SimpleBlockingRpcContinuation.cs +++ b/projects/RabbitMQ.Client/client/impl/SimpleBlockingRpcContinuation.cs @@ -70,7 +70,7 @@ public void HandleCommand(in IncomingCommand cmd) m_cell.ContinueWithValue(Either.Left(cmd)); } - public void HandleModelShutdown(ShutdownEventArgs reason) + public void HandleChannelShutdown(ShutdownEventArgs reason) { m_cell.ContinueWithValue(Either.Right(reason)); } diff --git a/projects/TestApplications/CreateChannel/Program.cs b/projects/TestApplications/CreateChannel/Program.cs index e1f3196515..7365aca8b9 100644 --- a/projects/TestApplications/CreateChannel/Program.cs +++ b/projects/TestApplications/CreateChannel/Program.cs @@ -27,12 +27,12 @@ public static void Main() var watch = Stopwatch.StartNew(); _ = Task.Run(() => { - var channels = new IModel[ChannelsToOpen]; + var channels = new IChannel[ChannelsToOpen]; for (int i = 0; i < Repeats; i++) { for (int j = 0; j < channels.Length; j++) { - channels[j] = connection.CreateModel(); + channels[j] = connection.CreateChannel(); channelsOpened++; } diff --git a/projects/TestApplications/MassPublish/Program.cs b/projects/TestApplications/MassPublish/Program.cs index c6cd9ab06a..2503d80d74 100644 --- a/projects/TestApplications/MassPublish/Program.cs +++ b/projects/TestApplications/MassPublish/Program.cs @@ -24,8 +24,8 @@ public static void Main() var connectionFactory = new ConnectionFactory { DispatchConsumersAsync = true }; var connection = connectionFactory.CreateConnection(); - var publisher = connection.CreateModel(); - var subscriber = connection.CreateModel(); + var publisher = connection.CreateChannel(); + var subscriber = connection.CreateChannel(); publisher.ConfirmSelect(); publisher.ExchangeDeclare("test", ExchangeType.Topic, true, false); diff --git a/projects/Unit/APIApproval.Approve.verified.txt b/projects/Unit/APIApproval.Approve.verified.txt index f40d66989d..d5ebf2fbcc 100644 --- a/projects/Unit/APIApproval.Approve.verified.txt +++ b/projects/Unit/APIApproval.Approve.verified.txt @@ -40,17 +40,17 @@ namespace RabbitMQ.Client public class AsyncDefaultBasicConsumer : RabbitMQ.Client.IAsyncBasicConsumer, RabbitMQ.Client.IBasicConsumer { public AsyncDefaultBasicConsumer() { } - public AsyncDefaultBasicConsumer(RabbitMQ.Client.IModel model) { } + public AsyncDefaultBasicConsumer(RabbitMQ.Client.IChannel channel) { } + public RabbitMQ.Client.IChannel Channel { get; set; } public string[] ConsumerTags { get; } public bool IsRunning { get; set; } - public RabbitMQ.Client.IModel Model { get; set; } public RabbitMQ.Client.ShutdownEventArgs ShutdownReason { get; set; } public event RabbitMQ.Client.Events.AsyncEventHandler ConsumerCancelled; public virtual System.Threading.Tasks.Task HandleBasicCancel(string consumerTag) { } public virtual System.Threading.Tasks.Task HandleBasicCancelOk(string consumerTag) { } public virtual System.Threading.Tasks.Task HandleBasicConsumeOk(string consumerTag) { } public virtual System.Threading.Tasks.Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, in RabbitMQ.Client.ReadOnlyBasicProperties properties, System.ReadOnlyMemory body) { } - public virtual System.Threading.Tasks.Task HandleModelShutdown(object model, RabbitMQ.Client.ShutdownEventArgs reason) { } + public virtual System.Threading.Tasks.Task HandleChannelShutdown(object channel, RabbitMQ.Client.ShutdownEventArgs reason) { } public virtual System.Threading.Tasks.Task OnCancel(params string[] consumerTags) { } } public sealed class BasicGetResult : System.IDisposable @@ -234,17 +234,17 @@ namespace RabbitMQ.Client public class DefaultBasicConsumer : RabbitMQ.Client.IBasicConsumer { public DefaultBasicConsumer() { } - public DefaultBasicConsumer(RabbitMQ.Client.IModel model) { } + public DefaultBasicConsumer(RabbitMQ.Client.IChannel channel) { } + public RabbitMQ.Client.IChannel Channel { get; set; } public string[] ConsumerTags { get; } public bool IsRunning { get; set; } - public RabbitMQ.Client.IModel Model { get; set; } public RabbitMQ.Client.ShutdownEventArgs ShutdownReason { get; set; } public event System.EventHandler ConsumerCancelled; public virtual void HandleBasicCancel(string consumerTag) { } public virtual void HandleBasicCancelOk(string consumerTag) { } public virtual void HandleBasicConsumeOk(string consumerTag) { } public virtual void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, in RabbitMQ.Client.ReadOnlyBasicProperties properties, System.ReadOnlyMemory body) { } - public virtual void HandleModelShutdown(object model, RabbitMQ.Client.ShutdownEventArgs reason) { } + public virtual void HandleChannelShutdown(object channel, RabbitMQ.Client.ShutdownEventArgs reason) { } public virtual void OnCancel(params string[] consumerTags) { } } public class DefaultEndpointResolver : RabbitMQ.Client.IEndpointResolver @@ -311,13 +311,13 @@ namespace RabbitMQ.Client } public interface IAsyncBasicConsumer { - RabbitMQ.Client.IModel Model { get; } + RabbitMQ.Client.IChannel Channel { get; } event RabbitMQ.Client.Events.AsyncEventHandler ConsumerCancelled; System.Threading.Tasks.Task HandleBasicCancel(string consumerTag); System.Threading.Tasks.Task HandleBasicCancelOk(string consumerTag); System.Threading.Tasks.Task HandleBasicConsumeOk(string consumerTag); System.Threading.Tasks.Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, in RabbitMQ.Client.ReadOnlyBasicProperties properties, System.ReadOnlyMemory body); - System.Threading.Tasks.Task HandleModelShutdown(object model, RabbitMQ.Client.ShutdownEventArgs reason); + System.Threading.Tasks.Task HandleChannelShutdown(object channel, RabbitMQ.Client.ShutdownEventArgs reason); } public interface IAuthMechanism { @@ -330,13 +330,13 @@ namespace RabbitMQ.Client } public interface IBasicConsumer { - RabbitMQ.Client.IModel Model { get; } + RabbitMQ.Client.IChannel Channel { get; } event System.EventHandler ConsumerCancelled; void HandleBasicCancel(string consumerTag); void HandleBasicCancelOk(string consumerTag); void HandleBasicConsumeOk(string consumerTag); void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, in RabbitMQ.Client.ReadOnlyBasicProperties properties, System.ReadOnlyMemory body); - void HandleModelShutdown(object model, RabbitMQ.Client.ShutdownEventArgs reason); + void HandleChannelShutdown(object channel, RabbitMQ.Client.ShutdownEventArgs reason); } public interface IBasicProperties : RabbitMQ.Client.IReadOnlyBasicProperties { @@ -371,6 +371,91 @@ namespace RabbitMQ.Client void ClearType(); void ClearUserId(); } + public interface IChannel : System.IDisposable + { + int ChannelNumber { get; } + RabbitMQ.Client.ShutdownEventArgs CloseReason { get; } + System.TimeSpan ContinuationTimeout { get; set; } + RabbitMQ.Client.IBasicConsumer DefaultConsumer { get; set; } + bool IsClosed { get; } + bool IsOpen { get; } + ulong NextPublishSeqNo { get; } + event System.EventHandler BasicAcks; + event System.EventHandler BasicNacks; + event System.EventHandler BasicRecoverOk; + event System.EventHandler BasicReturn; + event System.EventHandler CallbackException; + event System.EventHandler ChannelShutdown; + event System.EventHandler FlowControl; + void BasicAck(ulong deliveryTag, bool multiple); + void BasicCancel(string consumerTag); + void BasicCancelNoWait(string consumerTag); + string BasicConsume(string queue, bool autoAck, string consumerTag, bool noLocal, bool exclusive, System.Collections.Generic.IDictionary arguments, RabbitMQ.Client.IBasicConsumer consumer); + RabbitMQ.Client.BasicGetResult BasicGet(string queue, bool autoAck); + void BasicNack(ulong deliveryTag, bool multiple, bool requeue); + void BasicPublish(RabbitMQ.Client.CachedString exchange, RabbitMQ.Client.CachedString routingKey, in TProperties basicProperties, System.ReadOnlyMemory body = default, bool mandatory = false) + where TProperties : RabbitMQ.Client.IReadOnlyBasicProperties, RabbitMQ.Client.IAmqpHeader; + void BasicPublish(string exchange, string routingKey, in TProperties basicProperties, System.ReadOnlyMemory body = default, bool mandatory = false) + where TProperties : RabbitMQ.Client.IReadOnlyBasicProperties, RabbitMQ.Client.IAmqpHeader; + void BasicQos(uint prefetchSize, ushort prefetchCount, bool global); + void BasicRecover(bool requeue); + void BasicRecoverAsync(bool requeue); + void BasicReject(ulong deliveryTag, bool requeue); + void Close(ushort replyCode, string replyText, bool abort); + void ConfirmSelect(); + uint ConsumerCount(string queue); + void ExchangeBind(string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments); + void ExchangeBindNoWait(string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments); + void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete, System.Collections.Generic.IDictionary arguments); + void ExchangeDeclareNoWait(string exchange, string type, bool durable, bool autoDelete, System.Collections.Generic.IDictionary arguments); + void ExchangeDeclarePassive(string exchange); + void ExchangeDelete(string exchange, bool ifUnused); + void ExchangeDeleteNoWait(string exchange, bool ifUnused); + void ExchangeUnbind(string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments); + void ExchangeUnbindNoWait(string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments); + uint MessageCount(string queue); + void QueueBind(string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments); + void QueueBindNoWait(string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments); + RabbitMQ.Client.QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, System.Collections.Generic.IDictionary arguments); + void QueueDeclareNoWait(string queue, bool durable, bool exclusive, bool autoDelete, System.Collections.Generic.IDictionary arguments); + RabbitMQ.Client.QueueDeclareOk QueueDeclarePassive(string queue); + uint QueueDelete(string queue, bool ifUnused, bool ifEmpty); + void QueueDeleteNoWait(string queue, bool ifUnused, bool ifEmpty); + uint QueuePurge(string queue); + void QueueUnbind(string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments); + void TxCommit(); + void TxRollback(); + void TxSelect(); + System.Threading.Tasks.Task WaitForConfirmsAsync(System.Threading.CancellationToken token = default); + System.Threading.Tasks.Task WaitForConfirmsOrDieAsync(System.Threading.CancellationToken token = default); + } + public static class IChannelExtensions + { + public static void Abort(this RabbitMQ.Client.IChannel channel) { } + public static void Abort(this RabbitMQ.Client.IChannel channel, ushort replyCode, string replyText) { } + public static string BasicConsume(this RabbitMQ.Client.IChannel channel, string queue, bool autoAck, RabbitMQ.Client.IBasicConsumer consumer) { } + public static string BasicConsume(this RabbitMQ.Client.IChannel channel, string queue, bool autoAck, string consumerTag, RabbitMQ.Client.IBasicConsumer consumer) { } + public static string BasicConsume(this RabbitMQ.Client.IChannel channel, string queue, bool autoAck, string consumerTag, System.Collections.Generic.IDictionary arguments, RabbitMQ.Client.IBasicConsumer consumer) { } + public static string BasicConsume(this RabbitMQ.Client.IChannel channel, RabbitMQ.Client.IBasicConsumer consumer, string queue, bool autoAck = false, string consumerTag = "", bool noLocal = false, bool exclusive = false, System.Collections.Generic.IDictionary arguments = null) { } + public static void BasicPublish(this RabbitMQ.Client.IChannel channel, RabbitMQ.Client.CachedString exchange, RabbitMQ.Client.CachedString routingKey, System.ReadOnlyMemory body = default, bool mandatory = false) { } + public static void BasicPublish(this RabbitMQ.Client.IChannel channel, string exchange, string routingKey, System.ReadOnlyMemory body = default, bool mandatory = false) { } + public static void BasicPublish(this RabbitMQ.Client.IChannel channel, RabbitMQ.Client.PublicationAddress addr, in T basicProperties, System.ReadOnlyMemory body) + where T : RabbitMQ.Client.IReadOnlyBasicProperties, RabbitMQ.Client.IAmqpHeader { } + public static void Close(this RabbitMQ.Client.IChannel channel) { } + public static void Close(this RabbitMQ.Client.IChannel channel, ushort replyCode, string replyText) { } + public static void ExchangeBind(this RabbitMQ.Client.IChannel channel, string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } + public static void ExchangeBindNoWait(this RabbitMQ.Client.IChannel channel, string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } + public static void ExchangeDeclare(this RabbitMQ.Client.IChannel channel, string exchange, string type, bool durable = false, bool autoDelete = false, System.Collections.Generic.IDictionary arguments = null) { } + public static void ExchangeDeclareNoWait(this RabbitMQ.Client.IChannel channel, string exchange, string type, bool durable = false, bool autoDelete = false, System.Collections.Generic.IDictionary arguments = null) { } + public static void ExchangeDelete(this RabbitMQ.Client.IChannel channel, string exchange, bool ifUnused = false) { } + public static void ExchangeDeleteNoWait(this RabbitMQ.Client.IChannel channel, string exchange, bool ifUnused = false) { } + public static void ExchangeUnbind(this RabbitMQ.Client.IChannel channel, string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } + public static void QueueBind(this RabbitMQ.Client.IChannel channel, string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } + public static RabbitMQ.Client.QueueDeclareOk QueueDeclare(this RabbitMQ.Client.IChannel channel, string queue = "", bool durable = false, bool exclusive = true, bool autoDelete = true, System.Collections.Generic.IDictionary arguments = null) { } + public static uint QueueDelete(this RabbitMQ.Client.IChannel channel, string queue, bool ifUnused = false, bool ifEmpty = false) { } + public static void QueueDeleteNoWait(this RabbitMQ.Client.IChannel channel, string queue, bool ifUnused = false, bool ifEmpty = false) { } + public static void QueueUnbind(this RabbitMQ.Client.IChannel channel, string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } + } public interface IConnection : RabbitMQ.Client.INetworkConnection, System.IDisposable { ushort ChannelMax { get; } @@ -394,7 +479,7 @@ namespace RabbitMQ.Client event System.EventHandler RecoveringConsumer; event System.EventHandler RecoverySucceeded; void Close(ushort reasonCode, string reasonText, System.TimeSpan timeout, bool abort); - RabbitMQ.Client.IModel CreateModel(); + RabbitMQ.Client.IChannel CreateChannel(); void UpdateSecret(string newSecret, string reason); } public static class IConnectionExtensions @@ -435,91 +520,6 @@ namespace RabbitMQ.Client { System.Collections.Generic.IEnumerable All(); } - public interface IModel : System.IDisposable - { - int ChannelNumber { get; } - RabbitMQ.Client.ShutdownEventArgs CloseReason { get; } - System.TimeSpan ContinuationTimeout { get; set; } - RabbitMQ.Client.IBasicConsumer DefaultConsumer { get; set; } - bool IsClosed { get; } - bool IsOpen { get; } - ulong NextPublishSeqNo { get; } - event System.EventHandler BasicAcks; - event System.EventHandler BasicNacks; - event System.EventHandler BasicRecoverOk; - event System.EventHandler BasicReturn; - event System.EventHandler CallbackException; - event System.EventHandler FlowControl; - event System.EventHandler ModelShutdown; - void BasicAck(ulong deliveryTag, bool multiple); - void BasicCancel(string consumerTag); - void BasicCancelNoWait(string consumerTag); - string BasicConsume(string queue, bool autoAck, string consumerTag, bool noLocal, bool exclusive, System.Collections.Generic.IDictionary arguments, RabbitMQ.Client.IBasicConsumer consumer); - RabbitMQ.Client.BasicGetResult BasicGet(string queue, bool autoAck); - void BasicNack(ulong deliveryTag, bool multiple, bool requeue); - void BasicPublish(RabbitMQ.Client.CachedString exchange, RabbitMQ.Client.CachedString routingKey, in TProperties basicProperties, System.ReadOnlyMemory body = default, bool mandatory = false) - where TProperties : RabbitMQ.Client.IReadOnlyBasicProperties, RabbitMQ.Client.IAmqpHeader; - void BasicPublish(string exchange, string routingKey, in TProperties basicProperties, System.ReadOnlyMemory body = default, bool mandatory = false) - where TProperties : RabbitMQ.Client.IReadOnlyBasicProperties, RabbitMQ.Client.IAmqpHeader; - void BasicQos(uint prefetchSize, ushort prefetchCount, bool global); - void BasicRecover(bool requeue); - void BasicRecoverAsync(bool requeue); - void BasicReject(ulong deliveryTag, bool requeue); - void Close(ushort replyCode, string replyText, bool abort); - void ConfirmSelect(); - uint ConsumerCount(string queue); - void ExchangeBind(string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments); - void ExchangeBindNoWait(string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments); - void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete, System.Collections.Generic.IDictionary arguments); - void ExchangeDeclareNoWait(string exchange, string type, bool durable, bool autoDelete, System.Collections.Generic.IDictionary arguments); - void ExchangeDeclarePassive(string exchange); - void ExchangeDelete(string exchange, bool ifUnused); - void ExchangeDeleteNoWait(string exchange, bool ifUnused); - void ExchangeUnbind(string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments); - void ExchangeUnbindNoWait(string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments); - uint MessageCount(string queue); - void QueueBind(string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments); - void QueueBindNoWait(string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments); - RabbitMQ.Client.QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, System.Collections.Generic.IDictionary arguments); - void QueueDeclareNoWait(string queue, bool durable, bool exclusive, bool autoDelete, System.Collections.Generic.IDictionary arguments); - RabbitMQ.Client.QueueDeclareOk QueueDeclarePassive(string queue); - uint QueueDelete(string queue, bool ifUnused, bool ifEmpty); - void QueueDeleteNoWait(string queue, bool ifUnused, bool ifEmpty); - uint QueuePurge(string queue); - void QueueUnbind(string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments); - void TxCommit(); - void TxRollback(); - void TxSelect(); - System.Threading.Tasks.Task WaitForConfirmsAsync(System.Threading.CancellationToken token = default); - System.Threading.Tasks.Task WaitForConfirmsOrDieAsync(System.Threading.CancellationToken token = default); - } - public static class IModelExtensions - { - public static void Abort(this RabbitMQ.Client.IModel model) { } - public static void Abort(this RabbitMQ.Client.IModel model, ushort replyCode, string replyText) { } - public static string BasicConsume(this RabbitMQ.Client.IModel model, string queue, bool autoAck, RabbitMQ.Client.IBasicConsumer consumer) { } - public static string BasicConsume(this RabbitMQ.Client.IModel model, string queue, bool autoAck, string consumerTag, RabbitMQ.Client.IBasicConsumer consumer) { } - public static string BasicConsume(this RabbitMQ.Client.IModel model, string queue, bool autoAck, string consumerTag, System.Collections.Generic.IDictionary arguments, RabbitMQ.Client.IBasicConsumer consumer) { } - public static string BasicConsume(this RabbitMQ.Client.IModel model, RabbitMQ.Client.IBasicConsumer consumer, string queue, bool autoAck = false, string consumerTag = "", bool noLocal = false, bool exclusive = false, System.Collections.Generic.IDictionary arguments = null) { } - public static void BasicPublish(this RabbitMQ.Client.IModel model, RabbitMQ.Client.CachedString exchange, RabbitMQ.Client.CachedString routingKey, System.ReadOnlyMemory body = default, bool mandatory = false) { } - public static void BasicPublish(this RabbitMQ.Client.IModel model, string exchange, string routingKey, System.ReadOnlyMemory body = default, bool mandatory = false) { } - public static void BasicPublish(this RabbitMQ.Client.IModel model, RabbitMQ.Client.PublicationAddress addr, in T basicProperties, System.ReadOnlyMemory body) - where T : RabbitMQ.Client.IReadOnlyBasicProperties, RabbitMQ.Client.IAmqpHeader { } - public static void Close(this RabbitMQ.Client.IModel model) { } - public static void Close(this RabbitMQ.Client.IModel model, ushort replyCode, string replyText) { } - public static void ExchangeBind(this RabbitMQ.Client.IModel model, string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } - public static void ExchangeBindNoWait(this RabbitMQ.Client.IModel model, string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } - public static void ExchangeDeclare(this RabbitMQ.Client.IModel model, string exchange, string type, bool durable = false, bool autoDelete = false, System.Collections.Generic.IDictionary arguments = null) { } - public static void ExchangeDeclareNoWait(this RabbitMQ.Client.IModel model, string exchange, string type, bool durable = false, bool autoDelete = false, System.Collections.Generic.IDictionary arguments = null) { } - public static void ExchangeDelete(this RabbitMQ.Client.IModel model, string exchange, bool ifUnused = false) { } - public static void ExchangeDeleteNoWait(this RabbitMQ.Client.IModel model, string exchange, bool ifUnused = false) { } - public static void ExchangeUnbind(this RabbitMQ.Client.IModel model, string destination, string source, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } - public static void QueueBind(this RabbitMQ.Client.IModel model, string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } - public static RabbitMQ.Client.QueueDeclareOk QueueDeclare(this RabbitMQ.Client.IModel model, string queue = "", bool durable = false, bool exclusive = true, bool autoDelete = true, System.Collections.Generic.IDictionary arguments = null) { } - public static uint QueueDelete(this RabbitMQ.Client.IModel model, string queue, bool ifUnused = false, bool ifEmpty = false) { } - public static void QueueDeleteNoWait(this RabbitMQ.Client.IModel model, string queue, bool ifUnused = false, bool ifEmpty = false) { } - public static void QueueUnbind(this RabbitMQ.Client.IModel model, string queue, string exchange, string routingKey, System.Collections.Generic.IDictionary arguments = null) { } - } public interface INetworkConnection { int LocalPort { get; } @@ -695,7 +695,7 @@ namespace RabbitMQ.Client.Events public delegate System.Threading.Tasks.Task AsyncEventHandler(object sender, TEvent @event); public class AsyncEventingBasicConsumer : RabbitMQ.Client.AsyncDefaultBasicConsumer { - public AsyncEventingBasicConsumer(RabbitMQ.Client.IModel model) { } + public AsyncEventingBasicConsumer(RabbitMQ.Client.IChannel channel) { } public event RabbitMQ.Client.Events.AsyncEventHandler Received; public event RabbitMQ.Client.Events.AsyncEventHandler Registered; public event RabbitMQ.Client.Events.AsyncEventHandler Shutdown; @@ -703,7 +703,7 @@ namespace RabbitMQ.Client.Events public override System.Threading.Tasks.Task HandleBasicCancelOk(string consumerTag) { } public override System.Threading.Tasks.Task HandleBasicConsumeOk(string consumerTag) { } public override System.Threading.Tasks.Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, in RabbitMQ.Client.ReadOnlyBasicProperties properties, System.ReadOnlyMemory body) { } - public override System.Threading.Tasks.Task HandleModelShutdown(object model, RabbitMQ.Client.ShutdownEventArgs reason) { } + public override System.Threading.Tasks.Task HandleChannelShutdown(object channel, RabbitMQ.Client.ShutdownEventArgs reason) { } } public abstract class BaseExceptionEventArgs : System.EventArgs { @@ -775,7 +775,7 @@ namespace RabbitMQ.Client.Events } public class EventingBasicConsumer : RabbitMQ.Client.DefaultBasicConsumer { - public EventingBasicConsumer(RabbitMQ.Client.IModel model) { } + public EventingBasicConsumer(RabbitMQ.Client.IChannel channel) { } public event System.EventHandler Received; public event System.EventHandler Registered; public event System.EventHandler Shutdown; @@ -783,7 +783,7 @@ namespace RabbitMQ.Client.Events public override void HandleBasicCancelOk(string consumerTag) { } public override void HandleBasicConsumeOk(string consumerTag) { } public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, in RabbitMQ.Client.ReadOnlyBasicProperties properties, System.ReadOnlyMemory body) { } - public override void HandleModelShutdown(object model, RabbitMQ.Client.ShutdownEventArgs reason) { } + public override void HandleChannelShutdown(object channel, RabbitMQ.Client.ShutdownEventArgs reason) { } } public class FlowControlEventArgs : System.EventArgs { diff --git a/projects/Unit/Fixtures.cs b/projects/Unit/Fixtures.cs index abeac208f0..9a886d4913 100644 --- a/projects/Unit/Fixtures.cs +++ b/projects/Unit/Fixtures.cs @@ -47,7 +47,7 @@ public class IntegrationFixture : IDisposable { internal IConnectionFactory _connFactory; internal IConnection _conn; - internal IModel _model; + internal IChannel _channel; internal Encoding _encoding = new UTF8Encoding(); public static TimeSpan RECOVERY_INTERVAL = TimeSpan.FromSeconds(2); @@ -79,14 +79,14 @@ protected virtual void SetUp() { _connFactory = new ConnectionFactory(); _conn = _connFactory.CreateConnection(); - _model = _conn.CreateModel(); + _channel = _conn.CreateChannel(); } public virtual void Dispose() { - if (_model.IsOpen) + if (_channel.IsOpen) { - _model.Close(); + _channel.Close(); } if (_conn.IsOpen) @@ -177,29 +177,29 @@ internal IConnection CreateConnectionWithContinuationTimeout(bool automaticRecov // Channels // - internal void WithTemporaryModel(Action action) + internal void WithTemporaryChannel(Action action) { - IModel model = _conn.CreateModel(); + IChannel channel = _conn.CreateChannel(); try { - action(model); + action(channel); } finally { - model.Abort(); + channel.Abort(); } } - internal void WithClosedModel(Action action) + internal void WithClosedChannel(Action action) { - IModel model = _conn.CreateModel(); - model.Close(); + IChannel channel = _conn.CreateChannel(); + channel.Close(); - action(model); + action(channel); } - internal bool WaitForConfirms(IModel m) + internal bool WaitForConfirms(IChannel m) { using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(4)); return m.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult(); @@ -219,13 +219,13 @@ internal byte[] RandomMessageBody() return _encoding.GetBytes(Guid.NewGuid().ToString()); } - internal string DeclareNonDurableExchange(IModel m, string x) + internal string DeclareNonDurableExchange(IChannel m, string x) { m.ExchangeDeclare(x, "fanout", false); return x; } - internal string DeclareNonDurableExchangeNoWait(IModel m, string x) + internal string DeclareNonDurableExchangeNoWait(IChannel m, string x) { m.ExchangeDeclareNoWait(x, "fanout", false, false, null); return x; @@ -240,53 +240,53 @@ internal string GenerateQueueName() return $"queue{Guid.NewGuid()}"; } - internal void WithTemporaryNonExclusiveQueue(Action action) + internal void WithTemporaryNonExclusiveQueue(Action action) { - WithTemporaryNonExclusiveQueue(_model, action); + WithTemporaryNonExclusiveQueue(_channel, action); } - internal void WithTemporaryNonExclusiveQueue(IModel model, Action action) + internal void WithTemporaryNonExclusiveQueue(IChannel channel, Action action) { - WithTemporaryNonExclusiveQueue(model, action, GenerateQueueName()); + WithTemporaryNonExclusiveQueue(channel, action, GenerateQueueName()); } - internal void WithTemporaryNonExclusiveQueue(IModel model, Action action, string queue) + internal void WithTemporaryNonExclusiveQueue(IChannel channel, Action action, string queue) { try { - model.QueueDeclare(queue, false, false, false, null); - action(model, queue); + channel.QueueDeclare(queue, false, false, false, null); + action(channel, queue); } finally { - WithTemporaryModel(tm => tm.QueueDelete(queue)); + WithTemporaryChannel(tm => tm.QueueDelete(queue)); } } - internal void WithTemporaryQueueNoWait(IModel model, Action action, string queue) + internal void WithTemporaryQueueNoWait(IChannel channel, Action action, string queue) { try { - model.QueueDeclareNoWait(queue, false, true, false, null); - action(model, queue); + channel.QueueDeclareNoWait(queue, false, true, false, null); + action(channel, queue); } finally { - WithTemporaryModel(x => x.QueueDelete(queue)); + WithTemporaryChannel(x => x.QueueDelete(queue)); } } internal void EnsureNotEmpty(string q, string body) { - WithTemporaryModel(x => x.BasicPublish("", q, _encoding.GetBytes(body))); + WithTemporaryChannel(x => x.BasicPublish("", q, _encoding.GetBytes(body))); } - internal void WithNonEmptyQueue(Action action) + internal void WithNonEmptyQueue(Action action) { WithNonEmptyQueue(action, "msg"); } - internal void WithNonEmptyQueue(Action action, string msg) + internal void WithNonEmptyQueue(Action action, string msg) { WithTemporaryNonExclusiveQueue((m, q) => { @@ -295,18 +295,18 @@ internal void WithNonEmptyQueue(Action action, string msg) }); } - internal void WithEmptyQueue(Action action) + internal void WithEmptyQueue(Action action) { - WithTemporaryNonExclusiveQueue((model, queue) => + WithTemporaryNonExclusiveQueue((channel, queue) => { - model.QueuePurge(queue); - action(model, queue); + channel.QueuePurge(queue); + action(channel, queue); }); } internal void AssertMessageCount(string q, uint count) { - WithTemporaryModel((m) => + WithTemporaryChannel((m) => { QueueDeclareOk ok = m.QueueDeclarePassive(q); Assert.Equal(count, ok.MessageCount); @@ -315,14 +315,14 @@ internal void AssertMessageCount(string q, uint count) internal void AssertConsumerCount(string q, int count) { - WithTemporaryModel((m) => + WithTemporaryChannel((m) => { QueueDeclareOk ok = m.QueueDeclarePassive(q); Assert.Equal((uint)count, ok.ConsumerCount); }); } - internal void AssertConsumerCount(IModel m, string q, uint count) + internal void AssertConsumerCount(IChannel m, string q, uint count) { QueueDeclareOk ok = m.QueueDeclarePassive(q); Assert.Equal(count, ok.ConsumerCount); diff --git a/projects/Unit/RabbitMQCtl.cs b/projects/Unit/RabbitMQCtl.cs index 3fcdf014cf..057f917c28 100644 --- a/projects/Unit/RabbitMQCtl.cs +++ b/projects/Unit/RabbitMQCtl.cs @@ -162,7 +162,7 @@ public static void Block(IConnection conn, Encoding encoding) public static void Publish(IConnection conn, Encoding encoding) { - IModel ch = conn.CreateModel(); + IChannel ch = conn.CreateChannel(); ch.BasicPublish("amq.fanout", "", encoding.GetBytes("message")); } diff --git a/projects/Unit/TestAsyncConsumer.cs b/projects/Unit/TestAsyncConsumer.cs index 7093993d12..962ff271ce 100644 --- a/projects/Unit/TestAsyncConsumer.cs +++ b/projects/Unit/TestAsyncConsumer.cs @@ -56,7 +56,7 @@ public void TestBasicRoundtrip() var cf = new ConnectionFactory { DispatchConsumersAsync = true }; using (IConnection c = cf.CreateConnection()) { - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); byte[] body = System.Text.Encoding.UTF8.GetBytes("async-hi"); @@ -87,7 +87,7 @@ public async Task TestBasicRoundtripConcurrent() var cf = new ConnectionFactory { DispatchConsumersAsync = true, ConsumerDispatchConcurrency = 2 }; using (IConnection c = cf.CreateConnection()) { - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); string publish1 = get_unique_string(1024); @@ -151,7 +151,7 @@ public async Task TestBasicRoundtripConcurrentManyMessages() using (IConnection c = cf.CreateConnection()) { - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(queue: queueName, exclusive: false, durable: true); Assert.Equal(q.QueueName, queueName); @@ -162,7 +162,7 @@ public async Task TestBasicRoundtripConcurrentManyMessages() { using (IConnection c = cf.CreateConnection()) { - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(queue: queueName, exclusive: false, durable: true); for (int i = 0; i < publish_total; i++) @@ -188,7 +188,7 @@ public async Task TestBasicRoundtripConcurrentManyMessages() using (IConnection c = cf.CreateConnection()) { - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { var consumer = new AsyncEventingBasicConsumer(m); @@ -236,7 +236,7 @@ public void TestBasicRoundtripNoWait() var cf = new ConnectionFactory { DispatchConsumersAsync = true }; using (IConnection c = cf.CreateConnection()) { - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); byte[] body = System.Text.Encoding.UTF8.GetBytes("async-hi"); @@ -272,7 +272,7 @@ public void ConcurrentEventingTestForReceived() var cf = new ConnectionFactory { DispatchConsumersAsync = true }; using (IConnection c = cf.CreateConnection()) { - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); var consumer = new AsyncEventingBasicConsumer(m); @@ -326,7 +326,7 @@ public void NonAsyncConsumerShouldThrowInvalidOperationException() var cf = new ConnectionFactory { DispatchConsumersAsync = true }; using (IConnection c = cf.CreateConnection()) { - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); byte[] body = System.Text.Encoding.UTF8.GetBytes("async-hi"); diff --git a/projects/Unit/TestAsyncConsumerExceptions.cs b/projects/Unit/TestAsyncConsumerExceptions.cs index ee11f8ea69..d4f1a35798 100644 --- a/projects/Unit/TestAsyncConsumerExceptions.cs +++ b/projects/Unit/TestAsyncConsumerExceptions.cs @@ -49,13 +49,13 @@ public TestAsyncConsumerExceptions(ITestOutputHelper output) : base(output) } protected void TestExceptionHandlingWith(IBasicConsumer consumer, - Action action) + Action action) { var resetEvent = new AutoResetEvent(false); bool notified = false; - string q = _model.QueueDeclare(); + string q = _channel.QueueDeclare(); - _model.CallbackException += (m, evt) => + _channel.CallbackException += (m, evt) => { if (evt.Exception != TestException) return; @@ -63,8 +63,8 @@ protected void TestExceptionHandlingWith(IBasicConsumer consumer, resetEvent.Set(); }; - string tag = _model.BasicConsume(q, true, consumer); - action(_model, q, consumer, tag); + string tag = _channel.BasicConsume(q, true, consumer); + action(_channel, q, consumer, tag); resetEvent.WaitOne(2000); Assert.True(notified); @@ -78,47 +78,47 @@ protected override void SetUp() }; _conn = _connFactory.CreateConnection(); - _model = _conn.CreateModel(); + _channel = _conn.CreateChannel(); } [Fact] public void TestCancelNotificationExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnCancel(_model); + IBasicConsumer consumer = new ConsumerFailingOnCancel(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => m.QueueDelete(q)); } [Fact] public void TestConsumerCancelOkExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnCancelOk(_model); + IBasicConsumer consumer = new ConsumerFailingOnCancelOk(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => m.BasicCancel(ct)); } [Fact] public void TestConsumerConsumeOkExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnConsumeOk(_model); + IBasicConsumer consumer = new ConsumerFailingOnConsumeOk(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => { }); } [Fact] public void TestConsumerShutdownExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnShutdown(_model); + IBasicConsumer consumer = new ConsumerFailingOnShutdown(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => m.Close()); } [Fact] public void TestDeliveryExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnDelivery(_model); + IBasicConsumer consumer = new ConsumerFailingOnDelivery(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => m.BasicPublish("", q, _encoding.GetBytes("msg"))); } private class ConsumerFailingOnDelivery : AsyncEventingBasicConsumer { - public ConsumerFailingOnDelivery(IModel model) : base(model) + public ConsumerFailingOnDelivery(IChannel channel) : base(channel) { } @@ -136,7 +136,7 @@ public override Task HandleBasicDeliver(string consumerTag, private class ConsumerFailingOnCancel : AsyncEventingBasicConsumer { - public ConsumerFailingOnCancel(IModel model) : base(model) + public ConsumerFailingOnCancel(IChannel channel) : base(channel) { } @@ -148,11 +148,11 @@ public override Task HandleBasicCancel(string consumerTag) private class ConsumerFailingOnShutdown : AsyncEventingBasicConsumer { - public ConsumerFailingOnShutdown(IModel model) : base(model) + public ConsumerFailingOnShutdown(IChannel channel) : base(channel) { } - public override Task HandleModelShutdown(object model, ShutdownEventArgs reason) + public override Task HandleChannelShutdown(object channel, ShutdownEventArgs reason) { return Task.FromException(TestException); } @@ -160,7 +160,7 @@ public override Task HandleModelShutdown(object model, ShutdownEventArgs reason) private class ConsumerFailingOnConsumeOk : AsyncEventingBasicConsumer { - public ConsumerFailingOnConsumeOk(IModel model) : base(model) + public ConsumerFailingOnConsumeOk(IChannel channel) : base(channel) { } @@ -172,7 +172,7 @@ public override Task HandleBasicConsumeOk(string consumerTag) private class ConsumerFailingOnCancelOk : AsyncEventingBasicConsumer { - public ConsumerFailingOnCancelOk(IModel model) : base(model) + public ConsumerFailingOnCancelOk(IChannel channel) : base(channel) { } diff --git a/projects/Unit/TestBasicGet.cs b/projects/Unit/TestBasicGet.cs index 9bf653e6fa..283644be36 100644 --- a/projects/Unit/TestBasicGet.cs +++ b/projects/Unit/TestBasicGet.cs @@ -47,7 +47,7 @@ public void TestBasicGetWithClosedChannel() { WithNonEmptyQueue((_, q) => { - WithClosedModel(cm => + WithClosedChannel(cm => { Assert.Throws(() => cm.BasicGet(q, true)); }); @@ -57,9 +57,9 @@ public void TestBasicGetWithClosedChannel() [Fact] public void TestBasicGetWithEmptyResponse() { - WithEmptyQueue((model, queue) => + WithEmptyQueue((channel, queue) => { - BasicGetResult res = model.BasicGet(queue, false); + BasicGetResult res = channel.BasicGet(queue, false); Assert.Null(res); }); } @@ -68,9 +68,9 @@ public void TestBasicGetWithEmptyResponse() public void TestBasicGetWithNonEmptyResponseAndAutoAckMode() { const string msg = "for basic.get"; - WithNonEmptyQueue((model, queue) => + WithNonEmptyQueue((channel, queue) => { - BasicGetResult res = model.BasicGet(queue, true); + BasicGetResult res = channel.BasicGet(queue, true); Assert.Equal(msg, _encoding.GetString(res.Body.ToArray())); AssertMessageCount(queue, 0); }, msg); diff --git a/projects/Unit/TestBasicProperties.cs b/projects/Unit/TestBasicProperties.cs index 71756afed8..e9c61de344 100644 --- a/projects/Unit/TestBasicProperties.cs +++ b/projects/Unit/TestBasicProperties.cs @@ -206,7 +206,7 @@ public void TestPropertiesRountrip_Headers() var cf = new ConnectionFactory(); using (IConnection c = cf.CreateConnection()) - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); var bp = new BasicProperties() { Headers = new Dictionary() }; diff --git a/projects/Unit/TestBasicPublish.cs b/projects/Unit/TestBasicPublish.cs index 5854aa094d..0be7ef679b 100644 --- a/projects/Unit/TestBasicPublish.cs +++ b/projects/Unit/TestBasicPublish.cs @@ -16,7 +16,7 @@ public void TestBasicRoundtripArray() { var cf = new ConnectionFactory(); using (IConnection c = cf.CreateConnection()) - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); var bp = new BasicProperties(); @@ -46,7 +46,7 @@ public void TestBasicRoundtripCachedString() { var cf = new ConnectionFactory(); using (IConnection c = cf.CreateConnection()) - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { CachedString exchangeName = new CachedString(string.Empty); CachedString queueName = new CachedString(m.QueueDeclare().QueueName); @@ -76,7 +76,7 @@ public void TestBasicRoundtripReadOnlyMemory() { var cf = new ConnectionFactory(); using (IConnection c = cf.CreateConnection()) - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); byte[] sendBody = System.Text.Encoding.UTF8.GetBytes("hi"); @@ -105,7 +105,7 @@ public void CanNotModifyPayloadAfterPublish() { var cf = new ConnectionFactory(); using (IConnection c = cf.CreateConnection()) - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); byte[] sendBody = new byte[1000]; @@ -151,7 +151,7 @@ public void TestMaxMessageSize() cf.MaxMessageSize = maxMsgSize; bool sawConnectionShutdown = false; - bool sawModelShutdown = false; + bool sawChannelShutdown = false; bool sawConsumerRegistered = false; bool sawConsumerCancelled = false; @@ -166,11 +166,11 @@ public void TestMaxMessageSize() Assert.Equal(maxMsgSize, cf.Endpoint.MaxMessageSize); Assert.Equal(maxMsgSize, c.Endpoint.MaxMessageSize); - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { - m.ModelShutdown += (o, a) => + m.ChannelShutdown += (o, a) => { - sawModelShutdown = true; + sawChannelShutdown = true; }; m.CallbackException += (o, a) => @@ -215,7 +215,7 @@ public void TestMaxMessageSize() Assert.Equal(1, count); Assert.True(sawConnectionShutdown); - Assert.True(sawModelShutdown); + Assert.True(sawChannelShutdown); Assert.True(sawConsumerRegistered); Assert.True(sawConsumerCancelled); } diff --git a/projects/Unit/TestChannelAllocation.cs b/projects/Unit/TestChannelAllocation.cs index ed1ca99ff4..e574a4b236 100644 --- a/projects/Unit/TestChannelAllocation.cs +++ b/projects/Unit/TestChannelAllocation.cs @@ -38,18 +38,18 @@ namespace RabbitMQ.Client.Unit { - public class TestIModelAllocation : IDisposable + public class TestIChannelAllocation : IDisposable { public const int CHANNEL_COUNT = 100; IConnection _c; - public int ModelNumber(IModel model) + public int ChannelNumber(IChannel channel) { - return ((AutorecoveringModel)model).ChannelNumber; + return ((AutorecoveringChannel)channel).ChannelNumber; } - public TestIModelAllocation() + public TestIChannelAllocation() { _c = new ConnectionFactory().CreateConnection(); @@ -62,51 +62,51 @@ public TestIModelAllocation() public void AllocateInOrder() { for (int i = 1; i <= CHANNEL_COUNT; i++) - Assert.Equal(i, ModelNumber(_c.CreateModel())); + Assert.Equal(i, ChannelNumber(_c.CreateChannel())); } [Fact] public void AllocateAfterFreeingLast() { - IModel ch = _c.CreateModel(); - Assert.Equal(1, ModelNumber(ch)); + IChannel ch = _c.CreateChannel(); + Assert.Equal(1, ChannelNumber(ch)); ch.Close(); - ch = _c.CreateModel(); - Assert.Equal(1, ModelNumber(ch)); + ch = _c.CreateChannel(); + Assert.Equal(1, ChannelNumber(ch)); } - public int CompareModels(IModel x, IModel y) + public int CompareChannels(IChannel x, IChannel y) { - int i = ModelNumber(x); - int j = ModelNumber(y); + int i = ChannelNumber(x); + int j = ChannelNumber(y); return (i < j) ? -1 : (i == j) ? 0 : 1; } [Fact] public void AllocateAfterFreeingMany() { - List channels = new List(); + List channels = new List(); for (int i = 1; i <= CHANNEL_COUNT; i++) - channels.Add(_c.CreateModel()); + channels.Add(_c.CreateChannel()); - foreach (IModel channel in channels) + foreach (IChannel channel in channels) { channel.Close(); } - channels = new List(); + channels = new List(); for (int j = 1; j <= CHANNEL_COUNT; j++) - channels.Add(_c.CreateModel()); + channels.Add(_c.CreateChannel()); // In the current implementation the list should actually // already be sorted, but we don't want to force that behaviour - channels.Sort(CompareModels); + channels.Sort(CompareChannels); int k = 1; - foreach (IModel channel in channels) - Assert.Equal(k++, ModelNumber(channel)); + foreach (IChannel channel in channels) + Assert.Equal(k++, ChannelNumber(channel)); } } diff --git a/projects/Unit/TestModelShutdown.cs b/projects/Unit/TestChannelShutdown.cs similarity index 87% rename from projects/Unit/TestModelShutdown.cs rename to projects/Unit/TestChannelShutdown.cs index 13a08a2094..6d256d95bd 100644 --- a/projects/Unit/TestModelShutdown.cs +++ b/projects/Unit/TestChannelShutdown.cs @@ -40,24 +40,24 @@ namespace RabbitMQ.Client.Unit { - public class TestModelShutdown : IntegrationFixture + public class TestChannelShutdown : IntegrationFixture { - public TestModelShutdown(ITestOutputHelper output) : base(output) + public TestChannelShutdown(ITestOutputHelper output) : base(output) { } [Fact] public void TestConsumerDispatcherShutdown() { - var m = (AutorecoveringModel)_model; + var m = (AutorecoveringChannel)_channel; var latch = new ManualResetEventSlim(false); - _model.ModelShutdown += (model, args) => + _channel.ChannelShutdown += (channel, args) => { latch.Set(); }; Assert.False(m.ConsumerDispatcher.IsShutdown, "dispatcher should NOT be shut down before Close"); - _model.Close(); + _channel.Close(); Wait(latch, TimeSpan.FromSeconds(3)); Assert.True(m.ConsumerDispatcher.IsShutdown, "dispatcher should be shut down after Close"); } diff --git a/projects/Unit/TestChannelSoftErrors.cs b/projects/Unit/TestChannelSoftErrors.cs index f57b64a108..57af1f273c 100644 --- a/projects/Unit/TestChannelSoftErrors.cs +++ b/projects/Unit/TestChannelSoftErrors.cs @@ -46,18 +46,18 @@ public TestChannelSoftErrors(ITestOutputHelper output) : base(output) [Fact] public void TestBindOnNonExistingQueue() { - OperationInterruptedException exception = Assert.Throws(() => _model.QueueBind("NonExistingQueue", "", string.Empty)); + OperationInterruptedException exception = Assert.Throws(() => _channel.QueueBind("NonExistingQueue", "", string.Empty)); Assert.True(exception.Message.Contains("403"), $"Message doesn't contain the expected 403 part: {exception.Message}"); - Assert.False(_model.IsOpen, "Channel should be closed due to the soft error"); + Assert.False(_channel.IsOpen, "Channel should be closed due to the soft error"); Assert.True(_conn.IsOpen, "Connection should still be open due to the soft error only closing the channel"); } [Fact] public void TestBindOnNonExistingExchange() { - OperationInterruptedException exception = Assert.Throws(() => _model.ExchangeBind("NonExistingQueue", "", string.Empty)); + OperationInterruptedException exception = Assert.Throws(() => _channel.ExchangeBind("NonExistingQueue", "", string.Empty)); Assert.True(exception.Message.Contains("403"), $"Message doesn't contain the expected 403 part: {exception.Message}"); - Assert.False(_model.IsOpen, "Channel should be closed due to the soft error"); + Assert.False(_channel.IsOpen, "Channel should be closed due to the soft error"); Assert.True(_conn.IsOpen, "Connection should still be open due to the soft error only closing the channel"); } @@ -66,11 +66,11 @@ public void TestConsumeOnNonExistingQueue() { OperationInterruptedException exception = Assert.Throws(() => { - var consumer = new EventingBasicConsumer(_model); _model.BasicConsume("NonExistingQueue", true, consumer); + var consumer = new EventingBasicConsumer(_channel); _channel.BasicConsume("NonExistingQueue", true, consumer); }); Assert.True(exception.Message.Contains("404"), $"Message doesn't contain the expected 404 part: {exception.Message}"); - Assert.False(_model.IsOpen, "Channel should be closed due to the soft error"); + Assert.False(_channel.IsOpen, "Channel should be closed due to the soft error"); Assert.True(_conn.IsOpen, "Connection should still be open due to the soft error only closing the channel"); } } diff --git a/projects/Unit/TestConcurrentAccessWithSharedConnection.cs b/projects/Unit/TestConcurrentAccessWithSharedConnection.cs index 9da72ecfd9..875a84fb49 100644 --- a/projects/Unit/TestConcurrentAccessWithSharedConnection.cs +++ b/projects/Unit/TestConcurrentAccessWithSharedConnection.cs @@ -92,7 +92,7 @@ public void TestConcurrentChannelOpenCloseLoop() { TestConcurrentChannelOperations((conn) => { - IModel ch = conn.CreateModel(); + IChannel ch = conn.CreateChannel(); ch.Close(); }, 50); } @@ -108,7 +108,7 @@ internal void TestConcurrentChannelOpenAndPublishingWithBody(byte[] body, int it { // publishing on a shared channel is not supported // and would missing the point of this test anyway - IModel ch = _conn.CreateModel(); + IChannel ch = _conn.CreateChannel(); ch.ConfirmSelect(); for (int j = 0; j < 200; j++) { diff --git a/projects/Unit/TestConfirmSelect.cs b/projects/Unit/TestConfirmSelect.cs index 639dca9993..102282f14f 100644 --- a/projects/Unit/TestConfirmSelect.cs +++ b/projects/Unit/TestConfirmSelect.cs @@ -43,25 +43,25 @@ public TestConfirmSelect(ITestOutputHelper output) : base(output) [Fact] public void TestConfirmSelectIdempotency() { - _model.ConfirmSelect(); - Assert.Equal(1ul, _model.NextPublishSeqNo); + _channel.ConfirmSelect(); + Assert.Equal(1ul, _channel.NextPublishSeqNo); Publish(); - Assert.Equal(2ul, _model.NextPublishSeqNo); + Assert.Equal(2ul, _channel.NextPublishSeqNo); Publish(); - Assert.Equal(3ul, _model.NextPublishSeqNo); + Assert.Equal(3ul, _channel.NextPublishSeqNo); - _model.ConfirmSelect(); + _channel.ConfirmSelect(); Publish(); - Assert.Equal(4ul, _model.NextPublishSeqNo); + Assert.Equal(4ul, _channel.NextPublishSeqNo); Publish(); - Assert.Equal(5ul, _model.NextPublishSeqNo); + Assert.Equal(5ul, _channel.NextPublishSeqNo); Publish(); - Assert.Equal(6ul, _model.NextPublishSeqNo); + Assert.Equal(6ul, _channel.NextPublishSeqNo); } protected void Publish() { - _model.BasicPublish("", "amq.fanout", _encoding.GetBytes("message")); + _channel.BasicPublish("", "amq.fanout", _encoding.GetBytes("message")); } } } diff --git a/projects/Unit/TestConnectionFactoryContinuationTimeout.cs b/projects/Unit/TestConnectionFactoryContinuationTimeout.cs index c2c4fb621f..5a24b301fd 100644 --- a/projects/Unit/TestConnectionFactoryContinuationTimeout.cs +++ b/projects/Unit/TestConnectionFactoryContinuationTimeout.cs @@ -48,7 +48,7 @@ public void TestConnectionFactoryContinuationTimeoutOnRecoveringConnection() var continuationTimeout = TimeSpan.FromSeconds(777); using (IConnection c = CreateConnectionWithContinuationTimeout(true, continuationTimeout)) { - Assert.Equal(continuationTimeout, c.CreateModel().ContinuationTimeout); + Assert.Equal(continuationTimeout, c.CreateChannel().ContinuationTimeout); } } @@ -58,7 +58,7 @@ public void TestConnectionFactoryContinuationTimeoutOnNonRecoveringConnection() var continuationTimeout = TimeSpan.FromSeconds(777); using (IConnection c = CreateConnectionWithContinuationTimeout(false, continuationTimeout)) { - Assert.Equal(continuationTimeout, c.CreateModel().ContinuationTimeout); + Assert.Equal(continuationTimeout, c.CreateChannel().ContinuationTimeout); } } } diff --git a/projects/Unit/TestConnectionRecovery.cs b/projects/Unit/TestConnectionRecovery.cs index 911173c365..94999a0623 100644 --- a/projects/Unit/TestConnectionRecovery.cs +++ b/projects/Unit/TestConnectionRecovery.cs @@ -63,16 +63,16 @@ protected override void SetUp() { _queueName = $"TestConnectionRecovery-queue-{Guid.NewGuid()}"; _conn = CreateAutorecoveringConnection(); - _model = _conn.CreateModel(); - _model.QueueDelete(_queueName); + _channel = _conn.CreateChannel(); + _channel.QueueDelete(_queueName); } protected override void ReleaseResources() { // TODO LRB not really necessary - if (_model.IsOpen) + if (_channel.IsOpen) { - _model.Close(); + _channel.Close(); } if (_conn.IsOpen) @@ -87,13 +87,13 @@ protected override void ReleaseResources() public void TestBasicAckAfterChannelRecovery() { var allMessagesSeenLatch = new ManualResetEventSlim(false); - var cons = new AckingBasicConsumer(_model, _totalMessageCount, allMessagesSeenLatch); + var cons = new AckingBasicConsumer(_channel, _totalMessageCount, allMessagesSeenLatch); - string queueName = _model.QueueDeclare(_queueName, false, false, false, null).QueueName; + string queueName = _channel.QueueDeclare(_queueName, false, false, false, null).QueueName; Assert.Equal(queueName, _queueName); - _model.BasicQos(0, 1, false); - string consumerTag = _model.BasicConsume(queueName, false, cons); + _channel.BasicQos(0, 1, false); + string consumerTag = _channel.BasicConsume(queueName, false, cons); ManualResetEventSlim sl = PrepareForShutdown(_conn); ManualResetEventSlim rl = PrepareForRecovery(_conn); @@ -109,13 +109,13 @@ public void TestBasicAckAfterChannelRecovery() public void TestBasicNackAfterChannelRecovery() { var allMessagesSeenLatch = new ManualResetEventSlim(false); - var cons = new NackingBasicConsumer(_model, _totalMessageCount, allMessagesSeenLatch); + var cons = new NackingBasicConsumer(_channel, _totalMessageCount, allMessagesSeenLatch); - string queueName = _model.QueueDeclare(_queueName, false, false, false, null).QueueName; + string queueName = _channel.QueueDeclare(_queueName, false, false, false, null).QueueName; Assert.Equal(queueName, _queueName); - _model.BasicQos(0, 1, false); - string consumerTag = _model.BasicConsume(queueName, false, cons); + _channel.BasicQos(0, 1, false); + string consumerTag = _channel.BasicConsume(queueName, false, cons); ManualResetEventSlim sl = PrepareForShutdown(_conn); ManualResetEventSlim rl = PrepareForRecovery(_conn); @@ -131,13 +131,13 @@ public void TestBasicNackAfterChannelRecovery() public void TestBasicRejectAfterChannelRecovery() { var allMessagesSeenLatch = new ManualResetEventSlim(false); - var cons = new RejectingBasicConsumer(_model, _totalMessageCount, allMessagesSeenLatch); + var cons = new RejectingBasicConsumer(_channel, _totalMessageCount, allMessagesSeenLatch); - string queueName = _model.QueueDeclare(_queueName, false, false, false, null).QueueName; + string queueName = _channel.QueueDeclare(_queueName, false, false, false, null).QueueName; Assert.Equal(queueName, _queueName); - _model.BasicQos(0, 1, false); - string consumerTag = _model.BasicConsume(queueName, false, cons); + _channel.BasicQos(0, 1, false); + string consumerTag = _channel.BasicConsume(queueName, false, cons); ManualResetEventSlim sl = PrepareForShutdown(_conn); ManualResetEventSlim rl = PrepareForRecovery(_conn); @@ -153,33 +153,33 @@ public void TestBasicRejectAfterChannelRecovery() public void TestBasicAckAfterBasicGetAndChannelRecovery() { string q = GenerateQueueName(); - _model.QueueDeclare(q, false, false, false, null); + _channel.QueueDeclare(q, false, false, false, null); // create an offset - _model.BasicPublish("", q, _messageBody); + _channel.BasicPublish("", q, _messageBody); Thread.Sleep(50); - BasicGetResult g = _model.BasicGet(q, false); + BasicGetResult g = _channel.BasicGet(q, false); CloseAndWaitForRecovery(); Assert.True(_conn.IsOpen); - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); // ack the message after recovery - this should be out of range and ignored - _model.BasicAck(g.DeliveryTag, false); + _channel.BasicAck(g.DeliveryTag, false); // do a sync operation to 'check' there is no channel exception - _model.BasicGet(q, false); + _channel.BasicGet(q, false); } [Fact] public void TestBasicAckEventHandlerRecovery() { - _model.ConfirmSelect(); + _channel.ConfirmSelect(); var latch = new ManualResetEventSlim(false); - ((AutorecoveringModel)_model).BasicAcks += (m, args) => latch.Set(); - ((AutorecoveringModel)_model).BasicNacks += (m, args) => latch.Set(); + ((AutorecoveringChannel)_channel).BasicAcks += (m, args) => latch.Set(); + ((AutorecoveringChannel)_channel).BasicNacks += (m, args) => latch.Set(); CloseAndWaitForRecovery(); CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); - WithTemporaryNonExclusiveQueue(_model, (m, q) => m.BasicPublish("", q, _messageBody)); + WithTemporaryNonExclusiveQueue(_channel, (m, q) => m.BasicPublish("", q, _messageBody)); Wait(latch); } @@ -280,19 +280,19 @@ public void TestBasicConnectionRecoveryOnBrokerRestart() } [Fact] - public void TestBasicModelRecovery() + public void TestBasicChannelRecovery() { - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); } [Fact] - public void TestBasicModelRecoveryOnServerRestart() + public void TestBasicChannelRecoveryOnServerRestart() { - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); RestartServerAndWaitForRecovery(); - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); } [Fact] @@ -313,11 +313,11 @@ public void TestBlockedListenersRecovery() public void TestClientNamedQueueRecovery() { string s = "dotnet-client.test.recovery.q1"; - WithTemporaryNonExclusiveQueue(_model, (m, q) => + WithTemporaryNonExclusiveQueue(_channel, (m, q) => { CloseAndWaitForRecovery(); AssertQueueRecovery(m, q, false); - _model.QueueDelete(q); + _channel.QueueDelete(q); }, s); } @@ -325,7 +325,7 @@ public void TestClientNamedQueueRecovery() public void TestClientNamedQueueRecoveryNoWait() { string s = "dotnet-client.test.recovery.q1-nowait"; - WithTemporaryQueueNoWait(_model, (m, q) => + WithTemporaryQueueNoWait(_channel, (m, q) => { CloseAndWaitForRecovery(); AssertQueueRecovery(m, q); @@ -336,11 +336,11 @@ public void TestClientNamedQueueRecoveryNoWait() public void TestClientNamedQueueRecoveryOnServerRestart() { string s = "dotnet-client.test.recovery.q1"; - WithTemporaryNonExclusiveQueue(_model, (m, q) => + WithTemporaryNonExclusiveQueue(_channel, (m, q) => { RestartServerAndWaitForRecovery(); AssertQueueRecovery(m, q, false); - _model.QueueDelete(q); + _channel.QueueDelete(q); }, s); } @@ -349,7 +349,7 @@ public void TestConsumerWorkServiceRecovery() { using (AutorecoveringConnection c = CreateAutorecoveringConnection()) { - IModel m = c.CreateModel(); + IChannel m = c.CreateChannel(); string q = m.QueueDeclare("dotnet-client.recovery.consumer_work_pool1", false, false, false, null).QueueName; var cons = new EventingBasicConsumer(m); @@ -375,7 +375,7 @@ public void TestConsumerRecoveryOnClientNamedQueueWithOneRecovery() string q0 = "dotnet-client.recovery.queue1"; using (AutorecoveringConnection c = CreateAutorecoveringConnection()) { - IModel m = c.CreateModel(); + IChannel m = c.CreateChannel(); string q1 = m.QueueDeclare(q0, false, false, false, null).QueueName; Assert.Equal(q0, q1); @@ -412,13 +412,13 @@ public void TestConsumerRecoveryOnClientNamedQueueWithOneRecovery() [Fact] public void TestConsumerRecoveryWithManyConsumers() { - string q = _model.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName; + string q = _channel.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName; int n = 1024; for (int i = 0; i < n; i++) { - var cons = new EventingBasicConsumer(_model); - _model.BasicConsume(q, true, cons); + var cons = new EventingBasicConsumer(_channel); + _channel.BasicConsume(q, true, cons); } var latch = new ManualResetEventSlim(false); @@ -426,12 +426,12 @@ public void TestConsumerRecoveryWithManyConsumers() CloseAndWaitForRecovery(); Wait(latch); - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); AssertConsumerCount(q, n); } [Fact] - public void TestCreateModelOnClosedAutorecoveringConnectionDoesNotHang() + public void TestCreateChannelOnClosedAutorecoveringConnectionDoesNotHang() { // we don't want this to recover quickly in this test AutorecoveringConnection c = CreateAutorecoveringConnection(TimeSpan.FromSeconds(20)); @@ -441,7 +441,7 @@ public void TestCreateModelOnClosedAutorecoveringConnectionDoesNotHang() c.Close(); WaitForShutdown(c); Assert.False(c.IsOpen); - c.CreateModel(); + c.CreateChannel(); Assert.True(false, "Expected an exception"); } catch (AlreadyClosedException) @@ -465,11 +465,11 @@ public void TestDeclarationOfManyAutoDeleteExchangesWithTransientExchangesThatAr for (int i = 0; i < 3; i++) { string x1 = $"source-{Guid.NewGuid()}"; - _model.ExchangeDeclare(x1, "fanout", false, true, null); + _channel.ExchangeDeclare(x1, "fanout", false, true, null); string x2 = $"destination-{Guid.NewGuid()}"; - _model.ExchangeDeclare(x2, "fanout", false, false, null); - _model.ExchangeBind(x2, x1, ""); - _model.ExchangeDelete(x2); + _channel.ExchangeDeclare(x2, "fanout", false, false, null); + _channel.ExchangeBind(x2, x1, ""); + _channel.ExchangeDelete(x2); } AssertRecordedExchanges((AutorecoveringConnection)_conn, 0); } @@ -481,12 +481,12 @@ public void TestDeclarationOfManyAutoDeleteExchangesWithTransientExchangesThatAr for (int i = 0; i < 1000; i++) { string x1 = $"source-{Guid.NewGuid()}"; - _model.ExchangeDeclare(x1, "fanout", false, true, null); + _channel.ExchangeDeclare(x1, "fanout", false, true, null); string x2 = $"destination-{Guid.NewGuid()}"; - _model.ExchangeDeclare(x2, "fanout", false, false, null); - _model.ExchangeBind(x2, x1, ""); - _model.ExchangeUnbind(x2, x1, ""); - _model.ExchangeDelete(x2); + _channel.ExchangeDeclare(x2, "fanout", false, false, null); + _channel.ExchangeBind(x2, x1, ""); + _channel.ExchangeUnbind(x2, x1, ""); + _channel.ExchangeDelete(x2); } AssertRecordedExchanges((AutorecoveringConnection)_conn, 0); } @@ -498,10 +498,10 @@ public void TestDeclarationOfManyAutoDeleteExchangesWithTransientQueuesThatAreDe for (int i = 0; i < 1000; i++) { string x = Guid.NewGuid().ToString(); - _model.ExchangeDeclare(x, "fanout", false, true, null); - QueueDeclareOk q = _model.QueueDeclare(); - _model.QueueBind(q, x, ""); - _model.QueueDelete(q); + _channel.ExchangeDeclare(x, "fanout", false, true, null); + QueueDeclareOk q = _channel.QueueDeclare(); + _channel.QueueBind(q, x, ""); + _channel.QueueDelete(q); } AssertRecordedExchanges((AutorecoveringConnection)_conn, 0); } @@ -513,10 +513,10 @@ public void TestDeclarationOfManyAutoDeleteExchangesWithTransientQueuesThatAreUn for (int i = 0; i < 1000; i++) { string x = Guid.NewGuid().ToString(); - _model.ExchangeDeclare(x, "fanout", false, true, null); - QueueDeclareOk q = _model.QueueDeclare(); - _model.QueueBind(q, x, ""); - _model.QueueUnbind(q, x, "", null); + _channel.ExchangeDeclare(x, "fanout", false, true, null); + QueueDeclareOk q = _channel.QueueDeclare(); + _channel.QueueBind(q, x, ""); + _channel.QueueUnbind(q, x, "", null); } AssertRecordedExchanges((AutorecoveringConnection)_conn, 0); } @@ -528,10 +528,10 @@ public void TestDeclarationOfManyAutoDeleteQueuesWithTransientConsumer() for (int i = 0; i < 1000; i++) { string q = Guid.NewGuid().ToString(); - _model.QueueDeclare(q, false, false, true, null); - var dummy = new EventingBasicConsumer(_model); - string tag = _model.BasicConsume(q, true, dummy); - _model.BasicCancel(tag); + _channel.QueueDeclare(q, false, false, true, null); + var dummy = new EventingBasicConsumer(_channel); + string tag = _channel.BasicConsume(q, true, dummy); + _channel.BasicCancel(tag); } AssertRecordedQueues((AutorecoveringConnection)_conn, 0); } @@ -540,43 +540,43 @@ public void TestDeclarationOfManyAutoDeleteQueuesWithTransientConsumer() public void TestExchangeRecovery() { string x = "dotnet-client.test.recovery.x1"; - DeclareNonDurableExchange(_model, x); + DeclareNonDurableExchange(_channel, x); CloseAndWaitForRecovery(); - AssertExchangeRecovery(_model, x); - _model.ExchangeDelete(x); + AssertExchangeRecovery(_channel, x); + _channel.ExchangeDelete(x); } [Fact] public void TestExchangeRecoveryWithNoWait() { string x = "dotnet-client.test.recovery.x1-nowait"; - DeclareNonDurableExchangeNoWait(_model, x); + DeclareNonDurableExchangeNoWait(_channel, x); CloseAndWaitForRecovery(); - AssertExchangeRecovery(_model, x); - _model.ExchangeDelete(x); + AssertExchangeRecovery(_channel, x); + _channel.ExchangeDelete(x); } [Fact] public void TestExchangeToExchangeBindingRecovery() { - string q = _model.QueueDeclare("", false, false, false, null).QueueName; + string q = _channel.QueueDeclare("", false, false, false, null).QueueName; string x1 = "amq.fanout"; string x2 = GenerateExchangeName(); - _model.ExchangeDeclare(x2, "fanout"); - _model.ExchangeBind(x1, x2, ""); - _model.QueueBind(q, x1, ""); + _channel.ExchangeDeclare(x2, "fanout"); + _channel.ExchangeBind(x1, x2, ""); + _channel.QueueBind(q, x1, ""); try { CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); - _model.BasicPublish(x2, "", _encoding.GetBytes("msg")); + Assert.True(_channel.IsOpen); + _channel.BasicPublish(x2, "", _encoding.GetBytes("msg")); AssertMessageCount(q, 1); } finally { - WithTemporaryModel(m => + WithTemporaryChannel(m => { m.ExchangeDelete(x2); m.QueueDelete(q); @@ -591,14 +591,14 @@ public void TestQueueRecoveryWithManyQueues() int n = 1024; for (int i = 0; i < n; i++) { - qs.Add(_model.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName); + qs.Add(_channel.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName); } CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); foreach (string q in qs) { - AssertQueueRecovery(_model, q, false); - _model.QueueDelete(q); + AssertQueueRecovery(_channel, q, false); + _channel.QueueDelete(q); } } @@ -608,7 +608,7 @@ public void TestClientNamedTransientAutoDeleteQueueAndBindingRecovery() { string q = Guid.NewGuid().ToString(); string x = "tmp-fanout"; - IModel ch = _conn.CreateModel(); + IChannel ch = _conn.CreateChannel(); ch.QueueDelete(q); ch.ExchangeDelete(x); ch.ExchangeDeclare(exchange: x, type: "fanout"); @@ -632,7 +632,7 @@ public void TestClientNamedTransientAutoDeleteQueueAndBindingRecovery() public void TestServerNamedTransientAutoDeleteQueueAndBindingRecovery() { string x = "tmp-fanout"; - IModel ch = _conn.CreateModel(); + IChannel ch = _conn.CreateChannel(); ch.ExchangeDelete(x); ch.ExchangeDeclare(exchange: x, type: "fanout"); string q = ch.QueueDeclare(queue: "", durable: false, exclusive: false, autoDelete: true, arguments: null).QueueName; @@ -660,19 +660,6 @@ public void TestServerNamedTransientAutoDeleteQueueAndBindingRecovery() ch.ExchangeDelete(x); } - [Fact] - public void TestRecoveryEventHandlersOnChannel() - { - int counter = 0; - ((AutorecoveringModel)_model).Recovery += (source, ea) => Interlocked.Increment(ref counter); - - CloseAndWaitForRecovery(); - CloseAndWaitForRecovery(); - Assert.True(_conn.IsOpen); - - Assert.True(counter >= 1); - } - [Fact] public void TestRecoveryEventHandlersOnConnection() { @@ -684,22 +671,20 @@ public void TestRecoveryEventHandlersOnConnection() CloseAndWaitForRecovery(); CloseAndWaitForRecovery(); Assert.True(_conn.IsOpen); - Assert.True(counter >= 3); } [Fact] - public void TestRecoveryEventHandlersOnModel() + public void TestRecoveryEventHandlersOnChannel() { int counter = 0; - ((AutorecoveringModel)_model).Recovery += (source, ea) => Interlocked.Increment(ref counter); + ((AutorecoveringChannel)_channel).Recovery += (source, ea) => Interlocked.Increment(ref counter); CloseAndWaitForRecovery(); CloseAndWaitForRecovery(); CloseAndWaitForRecovery(); CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); - + Assert.True(_channel.IsOpen); Assert.True(counter >= 3); } @@ -708,9 +693,9 @@ public void TestRecoveryEventHandlersOnModel() [InlineData(3)] public void TestRecoveringConsumerHandlerOnConnection(int iterations) { - string q = _model.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName; - var cons = new EventingBasicConsumer(_model); - _model.BasicConsume(q, true, cons); + string q = _channel.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName; + var cons = new EventingBasicConsumer(_channel); + _channel.BasicConsume(q, true, cons); int counter = 0; ((AutorecoveringConnection)_conn).RecoveringConsumer += (sender, args) => Interlocked.Increment(ref counter); @@ -727,9 +712,9 @@ public void TestRecoveringConsumerHandlerOnConnection(int iterations) public void TestRecoveringConsumerHandlerOnConnection_EventArgumentsArePassedDown() { var myArgs = new Dictionary { { "first-argument", "some-value" } }; - string q = _model.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName; - var cons = new EventingBasicConsumer(_model); - string expectedCTag = _model.BasicConsume(cons, q, arguments: myArgs); + string q = _channel.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName; + var cons = new EventingBasicConsumer(_channel); + string expectedCTag = _channel.BasicConsume(cons, q, arguments: myArgs); bool ctagMatches = false; bool consumerArgumentMatches = false; @@ -754,7 +739,7 @@ public void TestRecoveringConsumerHandlerOnConnection_EventArgumentsArePassedDow public void TestRecoveryWithTopologyDisabled() { AutorecoveringConnection conn = CreateAutorecoveringConnectionWithTopologyRecoveryDisabled(); - IModel ch = conn.CreateModel(); + IChannel ch = conn.CreateChannel(); string s = "dotnet-client.test.recovery.q2"; ch.QueueDelete(s); ch.QueueDeclare(s, false, true, false, null); @@ -781,9 +766,9 @@ public void TestRecoveryWithTopologyDisabled() [Fact] public void TestServerNamedQueueRecovery() { - string q = _model.QueueDeclare("", false, false, false, null).QueueName; + string q = _channel.QueueDeclare("", false, false, false, null).QueueName; string x = "amq.fanout"; - _model.QueueBind(q, x, ""); + _channel.QueueBind(q, x, ""); string nameBefore = q; string nameAfter = null; @@ -801,7 +786,7 @@ public void TestServerNamedQueueRecovery() Assert.StartsWith("amq.", nameAfter); Assert.NotEqual(nameBefore, nameAfter); - _model.QueueDeclarePassive(nameAfter); + _channel.QueueDeclarePassive(nameAfter); } [Fact] @@ -848,17 +833,17 @@ public void TestShutdownEventHandlersRecoveryOnConnectionAfterDelayedServerResta } [Fact] - public void TestShutdownEventHandlersRecoveryOnModel() + public void TestShutdownEventHandlersRecoveryOnChannel() { int counter = 0; - _model.ModelShutdown += (c, args) => Interlocked.Increment(ref counter); + _channel.ChannelShutdown += (c, args) => Interlocked.Increment(ref counter); - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); CloseAndWaitForRecovery(); CloseAndWaitForRecovery(); CloseAndWaitForRecovery(); CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); Assert.True(counter >= 3); } @@ -870,38 +855,38 @@ public void TestRecoverTopologyOnDisposedChannel() string q = GenerateQueueName(); const string rk = "routing-key"; - using (IModel m = _conn.CreateModel()) + using (IChannel m = _conn.CreateChannel()) { m.ExchangeDeclare(exchange: x, type: "fanout"); m.QueueDeclare(q, false, false, false, null); m.QueueBind(q, x, rk); } - var cons = new EventingBasicConsumer(_model); - _model.BasicConsume(q, true, cons); - AssertConsumerCount(_model, q, 1); + var cons = new EventingBasicConsumer(_channel); + _channel.BasicConsume(q, true, cons); + AssertConsumerCount(_channel, q, 1); CloseAndWaitForRecovery(); - AssertConsumerCount(_model, q, 1); + AssertConsumerCount(_channel, q, 1); var latch = new ManualResetEventSlim(false); cons.Received += (s, args) => latch.Set(); - _model.BasicPublish("", q, _messageBody); + _channel.BasicPublish("", q, _messageBody); Wait(latch); - _model.QueueUnbind(q, x, rk); - _model.ExchangeDelete(x); - _model.QueueDelete(q); + _channel.QueueUnbind(q, x, rk); + _channel.ExchangeDelete(x); + _channel.QueueDelete(q); } [Fact(Skip = "TODO-FLAKY")] public void TestPublishRpcRightAfterReconnect() { string testQueueName = $"dotnet-client.test.{nameof(TestPublishRpcRightAfterReconnect)}"; - _model.QueueDeclare(testQueueName, false, false, false, null); - var replyConsumer = new EventingBasicConsumer(_model); - _model.BasicConsume("amq.rabbitmq.reply-to", true, replyConsumer); + _channel.QueueDeclare(testQueueName, false, false, false, null); + var replyConsumer = new EventingBasicConsumer(_channel); + _channel.BasicConsume("amq.rabbitmq.reply-to", true, replyConsumer); var properties = new BasicProperties(); properties.ReplyTo = "amq.rabbitmq.reply-to"; @@ -924,7 +909,7 @@ public void TestPublishRpcRightAfterReconnect() { try { - _model.BasicPublish(string.Empty, testQueueName, properties, _messageBody); + _channel.BasicPublish(string.Empty, testQueueName, properties, _messageBody); } catch (Exception e) { @@ -941,42 +926,42 @@ public void TestPublishRpcRightAfterReconnect() [Fact] public void TestThatCancelledConsumerDoesNotReappearOnRecovery() { - string q = _model.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName; + string q = _channel.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName; int n = 1024; for (int i = 0; i < n; i++) { - var cons = new EventingBasicConsumer(_model); - string tag = _model.BasicConsume(q, true, cons); - _model.BasicCancel(tag); + var cons = new EventingBasicConsumer(_channel); + string tag = _channel.BasicConsume(q, true, cons); + _channel.BasicCancel(tag); } CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); + Assert.True(_channel.IsOpen); AssertConsumerCount(q, 0); } [Fact] public void TestThatDeletedExchangeBindingsDontReappearOnRecovery() { - string q = _model.QueueDeclare("", false, false, false, null).QueueName; + string q = _channel.QueueDeclare("", false, false, false, null).QueueName; string x1 = "amq.fanout"; string x2 = GenerateExchangeName(); - _model.ExchangeDeclare(x2, "fanout"); - _model.ExchangeBind(x1, x2, ""); - _model.QueueBind(q, x1, ""); - _model.ExchangeUnbind(x1, x2, "", null); + _channel.ExchangeDeclare(x2, "fanout"); + _channel.ExchangeBind(x1, x2, ""); + _channel.QueueBind(q, x1, ""); + _channel.ExchangeUnbind(x1, x2, "", null); try { CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); - _model.BasicPublish(x2, "", _encoding.GetBytes("msg")); + Assert.True(_channel.IsOpen); + _channel.BasicPublish(x2, "", _encoding.GetBytes("msg")); AssertMessageCount(q, 0); } finally { - WithTemporaryModel(m => + WithTemporaryChannel(m => { m.ExchangeDelete(x2); m.QueueDelete(q); @@ -988,14 +973,14 @@ public void TestThatDeletedExchangeBindingsDontReappearOnRecovery() public void TestThatDeletedExchangesDontReappearOnRecovery() { string x = GenerateExchangeName(); - _model.ExchangeDeclare(x, "fanout"); - _model.ExchangeDelete(x); + _channel.ExchangeDeclare(x, "fanout"); + _channel.ExchangeDelete(x); try { CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); - _model.ExchangeDeclarePassive(x); + Assert.True(_channel.IsOpen); + _channel.ExchangeDeclarePassive(x); Assert.True(false, "Expected an exception"); } catch (OperationInterruptedException e) @@ -1008,25 +993,25 @@ public void TestThatDeletedExchangesDontReappearOnRecovery() [Fact] public void TestThatDeletedQueueBindingsDontReappearOnRecovery() { - string q = _model.QueueDeclare("", false, false, false, null).QueueName; + string q = _channel.QueueDeclare("", false, false, false, null).QueueName; string x1 = "amq.fanout"; string x2 = GenerateExchangeName(); - _model.ExchangeDeclare(x2, "fanout"); - _model.ExchangeBind(x1, x2, ""); - _model.QueueBind(q, x1, ""); - _model.QueueUnbind(q, x1, "", null); + _channel.ExchangeDeclare(x2, "fanout"); + _channel.ExchangeBind(x1, x2, ""); + _channel.QueueBind(q, x1, ""); + _channel.QueueUnbind(q, x1, "", null); try { CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); - _model.BasicPublish(x2, "", _encoding.GetBytes("msg")); + Assert.True(_channel.IsOpen); + _channel.BasicPublish(x2, "", _encoding.GetBytes("msg")); AssertMessageCount(q, 0); } finally { - WithTemporaryModel(m => + WithTemporaryChannel(m => { m.ExchangeDelete(x2); m.QueueDelete(q); @@ -1038,14 +1023,14 @@ public void TestThatDeletedQueueBindingsDontReappearOnRecovery() public void TestThatDeletedQueuesDontReappearOnRecovery() { string q = "dotnet-client.recovery.q1"; - _model.QueueDeclare(q, false, false, false, null); - _model.QueueDelete(q); + _channel.QueueDeclare(q, false, false, false, null); + _channel.QueueDelete(q); try { CloseAndWaitForRecovery(); - Assert.True(_model.IsOpen); - _model.QueueDeclarePassive(q); + Assert.True(_channel.IsOpen); + _channel.QueueDeclarePassive(q); Assert.True(false, "Expected an exception"); } catch (OperationInterruptedException e) @@ -1068,7 +1053,7 @@ public void TestUnblockedListenersRecovery() Wait(latch); } - internal void AssertExchangeRecovery(IModel m, string x) + internal void AssertExchangeRecovery(IChannel m, string x) { m.ConfirmSelect(); WithTemporaryNonExclusiveQueue(m, (_, q) => @@ -1082,12 +1067,12 @@ internal void AssertExchangeRecovery(IModel m, string x) }); } - internal void AssertQueueRecovery(IModel m, string q) + internal void AssertQueueRecovery(IChannel m, string q) { AssertQueueRecovery(m, q, true); } - internal void AssertQueueRecovery(IModel m, string q, bool exclusive) + internal void AssertQueueRecovery(IChannel m, string q, bool exclusive) { m.ConfirmSelect(); m.QueueDeclarePassive(q); @@ -1188,7 +1173,7 @@ internal void PublishMessagesWhileClosingConn(string queueName) { using (AutorecoveringConnection publishingConn = CreateAutorecoveringConnection()) { - using (IModel publishingModel = publishingConn.CreateModel()) + using (IChannel publishingChannel = publishingConn.CreateChannel()) { for (ushort i = 0; i < _totalMessageCount; i++) { @@ -1196,7 +1181,7 @@ internal void PublishMessagesWhileClosingConn(string queueName) { CloseConnection(_conn); } - publishingModel.BasicPublish(string.Empty, queueName, _messageBody); + publishingChannel.BasicPublish(string.Empty, queueName, _messageBody); } } } @@ -1204,40 +1189,40 @@ internal void PublishMessagesWhileClosingConn(string queueName) public class AckingBasicConsumer : TestBasicConsumer { - public AckingBasicConsumer(IModel model, ushort totalMessageCount, ManualResetEventSlim allMessagesSeenLatch) - : base(model, totalMessageCount, allMessagesSeenLatch) + public AckingBasicConsumer(IChannel channel, ushort totalMessageCount, ManualResetEventSlim allMessagesSeenLatch) + : base(channel, totalMessageCount, allMessagesSeenLatch) { } public override void PostHandleDelivery(ulong deliveryTag) { - Model.BasicAck(deliveryTag, false); + Channel.BasicAck(deliveryTag, false); } } public class NackingBasicConsumer : TestBasicConsumer { - public NackingBasicConsumer(IModel model, ushort totalMessageCount, ManualResetEventSlim allMessagesSeenLatch) - : base(model, totalMessageCount, allMessagesSeenLatch) + public NackingBasicConsumer(IChannel channel, ushort totalMessageCount, ManualResetEventSlim allMessagesSeenLatch) + : base(channel, totalMessageCount, allMessagesSeenLatch) { } public override void PostHandleDelivery(ulong deliveryTag) { - Model.BasicNack(deliveryTag, false, false); + Channel.BasicNack(deliveryTag, false, false); } } public class RejectingBasicConsumer : TestBasicConsumer { - public RejectingBasicConsumer(IModel model, ushort totalMessageCount, ManualResetEventSlim allMessagesSeenLatch) - : base(model, totalMessageCount, allMessagesSeenLatch) + public RejectingBasicConsumer(IChannel channel, ushort totalMessageCount, ManualResetEventSlim allMessagesSeenLatch) + : base(channel, totalMessageCount, allMessagesSeenLatch) { } public override void PostHandleDelivery(ulong deliveryTag) { - Model.BasicReject(deliveryTag, false); + Channel.BasicReject(deliveryTag, false); } } @@ -1247,8 +1232,8 @@ public class TestBasicConsumer : DefaultBasicConsumer private readonly ushort _totalMessageCount; private ushort _counter = 0; - public TestBasicConsumer(IModel model, ushort totalMessageCount, ManualResetEventSlim allMessagesSeenLatch) - : base(model) + public TestBasicConsumer(IChannel channel, ushort totalMessageCount, ManualResetEventSlim allMessagesSeenLatch) + : base(channel) { _totalMessageCount = totalMessageCount; _allMessagesSeenLatch = allMessagesSeenLatch; diff --git a/projects/Unit/TestConnectionShutdown.cs b/projects/Unit/TestConnectionShutdown.cs index 8fe475be96..d497b6ed93 100644 --- a/projects/Unit/TestConnectionShutdown.cs +++ b/projects/Unit/TestConnectionShutdown.cs @@ -49,10 +49,10 @@ public TestConnectionShutdown(ITestOutputHelper output) : base(output) public void TestCleanClosureWithSocketClosedOutOfBand() { _conn = CreateAutorecoveringConnection(); - _model = _conn.CreateModel(); + _channel = _conn.CreateChannel(); var latch = new ManualResetEventSlim(false); - _model.ModelShutdown += (model, args) => + _channel.ChannelShutdown += (channel, args) => { latch.Set(); }; @@ -68,10 +68,10 @@ public void TestCleanClosureWithSocketClosedOutOfBand() public void TestAbortWithSocketClosedOutOfBand() { _conn = CreateAutorecoveringConnection(); - _model = _conn.CreateModel(); + _channel = _conn.CreateChannel(); var latch = new ManualResetEventSlim(false); - _model.ModelShutdown += (model, args) => + _channel.ChannelShutdown += (channel, args) => { latch.Set(); }; @@ -88,10 +88,10 @@ public void TestAbortWithSocketClosedOutOfBand() public void TestDisposedWithSocketClosedOutOfBand() { _conn = CreateAutorecoveringConnection(); - _model = _conn.CreateModel(); + _channel = _conn.CreateChannel(); var latch = new ManualResetEventSlim(false); - _model.ModelShutdown += (model, args) => + _channel.ChannelShutdown += (channel, args) => { latch.Set(); }; @@ -108,7 +108,7 @@ public void TestShutdownSignalPropagationToChannels() { var latch = new ManualResetEventSlim(false); - _model.ModelShutdown += (model, args) => + _channel.ChannelShutdown += (channel, args) => { latch.Set(); }; @@ -120,10 +120,10 @@ public void TestShutdownSignalPropagationToChannels() [Fact] public void TestConsumerDispatcherShutdown() { - var m = (AutorecoveringModel)_model; + var m = (AutorecoveringChannel)_channel; var latch = new ManualResetEventSlim(false); - _model.ModelShutdown += (model, args) => + _channel.ChannelShutdown += (channel, args) => { latch.Set(); }; diff --git a/projects/Unit/TestConsumer.cs b/projects/Unit/TestConsumer.cs index a8af5c8c24..875d83f5e1 100644 --- a/projects/Unit/TestConsumer.cs +++ b/projects/Unit/TestConsumer.cs @@ -17,7 +17,7 @@ public async Task TestBasicRoundtripConcurrent() { var cf = new ConnectionFactory { ConsumerDispatchConcurrency = 2 }; using (IConnection c = cf.CreateConnection()) - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); const string publish1 = "sync-hi-1"; diff --git a/projects/Unit/TestConsumerCancelNotify.cs b/projects/Unit/TestConsumerCancelNotify.cs index 75dbfddcf8..5b45393a13 100644 --- a/projects/Unit/TestConsumerCancelNotify.cs +++ b/projects/Unit/TestConsumerCancelNotify.cs @@ -69,12 +69,12 @@ public void TestCorrectConsumerTag() string q1 = GenerateQueueName(); string q2 = GenerateQueueName(); - _model.QueueDeclare(q1, false, false, false, null); - _model.QueueDeclare(q2, false, false, false, null); + _channel.QueueDeclare(q1, false, false, false, null); + _channel.QueueDeclare(q2, false, false, false, null); - EventingBasicConsumer consumer = new EventingBasicConsumer(_model); - string consumerTag1 = _model.BasicConsume(q1, true, consumer); - string consumerTag2 = _model.BasicConsume(q2, true, consumer); + EventingBasicConsumer consumer = new EventingBasicConsumer(_channel); + string consumerTag1 = _channel.BasicConsume(q1, true, consumer); + string consumerTag2 = _channel.BasicConsume(q2, true, consumer); string notifiedConsumerTag = null; consumer.ConsumerCancelled += (sender, args) => @@ -86,20 +86,20 @@ public void TestCorrectConsumerTag() } }; - _model.QueueDelete(q1); + _channel.QueueDelete(q1); WaitOn(lockObject); Assert.Equal(consumerTag1, notifiedConsumerTag); - _model.QueueDelete(q2); + _channel.QueueDelete(q2); } private void TestConsumerCancel(string queue, bool EventMode, ref bool notified) { - _model.QueueDeclare(queue, false, true, false, null); - IBasicConsumer consumer = new CancelNotificationConsumer(_model, this, EventMode); - string actualConsumerTag = _model.BasicConsume(queue, false, consumer); + _channel.QueueDeclare(queue, false, true, false, null); + IBasicConsumer consumer = new CancelNotificationConsumer(_channel, this, EventMode); + string actualConsumerTag = _channel.BasicConsume(queue, false, consumer); - _model.QueueDelete(queue); + _channel.QueueDelete(queue); WaitOn(lockObject); Assert.True(notified); Assert.Equal(actualConsumerTag, consumerTag); @@ -110,8 +110,8 @@ private class CancelNotificationConsumer : DefaultBasicConsumer private readonly TestConsumerCancelNotify _testClass; private readonly bool _eventMode; - public CancelNotificationConsumer(IModel model, TestConsumerCancelNotify tc, bool EventMode) - : base(model) + public CancelNotificationConsumer(IChannel channel, TestConsumerCancelNotify tc, bool EventMode) + : base(channel) { _testClass = tc; _eventMode = EventMode; diff --git a/projects/Unit/TestConsumerCount.cs b/projects/Unit/TestConsumerCount.cs index 5c8fff2840..4b53cbfb33 100644 --- a/projects/Unit/TestConsumerCount.cs +++ b/projects/Unit/TestConsumerCount.cs @@ -46,14 +46,14 @@ public TestConsumerCount(ITestOutputHelper output) : base(output) public void TestConsumerCountMethod() { string q = GenerateQueueName(); - _model.QueueDeclare(queue: q, durable: false, exclusive: true, autoDelete: false, arguments: null); - Assert.Equal(0u, _model.ConsumerCount(q)); + _channel.QueueDeclare(queue: q, durable: false, exclusive: true, autoDelete: false, arguments: null); + Assert.Equal(0u, _channel.ConsumerCount(q)); - string tag = _model.BasicConsume(q, true, new EventingBasicConsumer(_model)); - Assert.Equal(1u, _model.ConsumerCount(q)); + string tag = _channel.BasicConsume(q, true, new EventingBasicConsumer(_channel)); + Assert.Equal(1u, _channel.ConsumerCount(q)); - _model.BasicCancel(tag); - Assert.Equal(0u, _model.ConsumerCount(q)); + _channel.BasicCancel(tag); + Assert.Equal(0u, _channel.ConsumerCount(q)); } } } diff --git a/projects/Unit/TestConsumerExceptions.cs b/projects/Unit/TestConsumerExceptions.cs index 63b91a8408..efd19bc237 100644 --- a/projects/Unit/TestConsumerExceptions.cs +++ b/projects/Unit/TestConsumerExceptions.cs @@ -42,7 +42,7 @@ public class TestConsumerExceptions : IntegrationFixture { private class ConsumerFailingOnDelivery : DefaultBasicConsumer { - public ConsumerFailingOnDelivery(IModel model) : base(model) + public ConsumerFailingOnDelivery(IChannel channel) : base(channel) { } @@ -60,7 +60,7 @@ public override void HandleBasicDeliver(string consumerTag, private class ConsumerFailingOnCancel : DefaultBasicConsumer { - public ConsumerFailingOnCancel(IModel model) : base(model) + public ConsumerFailingOnCancel(IChannel channel) : base(channel) { } @@ -72,11 +72,11 @@ public override void HandleBasicCancel(string consumerTag) private class ConsumerFailingOnShutdown : DefaultBasicConsumer { - public ConsumerFailingOnShutdown(IModel model) : base(model) + public ConsumerFailingOnShutdown(IChannel channel) : base(channel) { } - public override void HandleModelShutdown(object model, ShutdownEventArgs reason) + public override void HandleChannelShutdown(object channel, ShutdownEventArgs reason) { throw new Exception("oops"); } @@ -84,7 +84,7 @@ public override void HandleModelShutdown(object model, ShutdownEventArgs reason) private class ConsumerFailingOnConsumeOk : DefaultBasicConsumer { - public ConsumerFailingOnConsumeOk(IModel model) : base(model) + public ConsumerFailingOnConsumeOk(IChannel channel) : base(channel) { } @@ -96,7 +96,7 @@ public override void HandleBasicConsumeOk(string consumerTag) private class ConsumerFailingOnCancelOk : DefaultBasicConsumer { - public ConsumerFailingOnCancelOk(IModel model) : base(model) + public ConsumerFailingOnCancelOk(IChannel channel) : base(channel) { } @@ -107,21 +107,21 @@ public override void HandleBasicCancelOk(string consumerTag) } protected void TestExceptionHandlingWith(IBasicConsumer consumer, - Action action) + Action action) { object o = new object(); bool notified = false; - string q = _model.QueueDeclare(); + string q = _channel.QueueDeclare(); - _model.CallbackException += (m, evt) => + _channel.CallbackException += (m, evt) => { notified = true; Monitor.PulseAll(o); }; - string tag = _model.BasicConsume(q, true, consumer); - action(_model, q, consumer, tag); + string tag = _channel.BasicConsume(q, true, consumer); + action(_channel, q, consumer, tag); WaitOn(o); Assert.True(notified); @@ -134,35 +134,35 @@ public TestConsumerExceptions(ITestOutputHelper output) : base(output) [Fact] public void TestCancelNotificationExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnCancel(_model); + IBasicConsumer consumer = new ConsumerFailingOnCancel(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => m.QueueDelete(q)); } [Fact] public void TestConsumerCancelOkExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnCancelOk(_model); + IBasicConsumer consumer = new ConsumerFailingOnCancelOk(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => m.BasicCancel(ct)); } [Fact] public void TestConsumerConsumeOkExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnConsumeOk(_model); + IBasicConsumer consumer = new ConsumerFailingOnConsumeOk(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => { }); } [Fact] public void TestConsumerShutdownExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnShutdown(_model); + IBasicConsumer consumer = new ConsumerFailingOnShutdown(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => m.Close()); } [Fact] public void TestDeliveryExceptionHandling() { - IBasicConsumer consumer = new ConsumerFailingOnDelivery(_model); + IBasicConsumer consumer = new ConsumerFailingOnDelivery(_channel); TestExceptionHandlingWith(consumer, (m, q, c, ct) => m.BasicPublish("", q, _encoding.GetBytes("msg"))); } } diff --git a/projects/Unit/TestConsumerOperationDispatch.cs b/projects/Unit/TestConsumerOperationDispatch.cs index b48e9615a8..d8f75a1c76 100644 --- a/projects/Unit/TestConsumerOperationDispatch.cs +++ b/projects/Unit/TestConsumerOperationDispatch.cs @@ -48,7 +48,7 @@ public TestConsumerOperationDispatch(ITestOutputHelper output) : base(output) } private readonly string _x = "dotnet.tests.consumer-operation-dispatch.fanout"; - private readonly List _channels = new List(); + private readonly List _channels = new List(); private readonly List _queues = new List(); private readonly List _consumers = new List(); @@ -62,7 +62,7 @@ public TestConsumerOperationDispatch(ITestOutputHelper output) : base(output) public override void Dispose() { - foreach (IModel ch in _channels) + foreach (IChannel ch in _channels) { if (ch.IsOpen) { @@ -80,8 +80,8 @@ private class CollectingConsumer : DefaultBasicConsumer { public List DeliveryTags { get; } - public CollectingConsumer(IModel model) - : base(model) + public CollectingConsumer(IChannel channel) + : base(channel) { DeliveryTags = new List(); } @@ -100,19 +100,19 @@ public override void HandleBasicDeliver(string consumerTag, counter.Signal(); } - Model.BasicAck(deliveryTag: deliveryTag, multiple: false); + Channel.BasicAck(deliveryTag: deliveryTag, multiple: false); } } [Fact] public void TestDeliveryOrderingWithSingleChannel() { - IModel Ch = _conn.CreateModel(); + IChannel Ch = _conn.CreateChannel(); Ch.ExchangeDeclare(_x, "fanout", durable: false); for (int i = 0; i < Y; i++) { - IModel ch = _conn.CreateModel(); + IChannel ch = _conn.CreateChannel(); QueueDeclareOk q = ch.QueueDeclare("", durable: false, exclusive: true, autoDelete: true, arguments: null); ch.QueueBind(queue: q, exchange: _x, routingKey: ""); _channels.Add(ch); @@ -148,9 +148,9 @@ public void TestDeliveryOrderingWithSingleChannel() [Fact] public void TestChannelShutdownDoesNotShutDownDispatcher() { - IModel ch1 = _conn.CreateModel(); - IModel ch2 = _conn.CreateModel(); - _model.ExchangeDeclare(_x, "fanout", durable: false); + IChannel ch1 = _conn.CreateChannel(); + IChannel ch2 = _conn.CreateChannel(); + _channel.ExchangeDeclare(_x, "fanout", durable: false); string q1 = ch1.QueueDeclare().QueueName; string q2 = ch2.QueueDeclare().QueueName; @@ -182,7 +182,7 @@ public ShutdownLatchConsumer(ManualResetEventSlim latch, ManualResetEventSlim du DuplicateLatch = duplicateLatch; } - public override void HandleModelShutdown(object model, ShutdownEventArgs reason) + public override void HandleChannelShutdown(object channel, ShutdownEventArgs reason) { // keep track of duplicates if (Latch.Wait(0)) @@ -197,15 +197,15 @@ public override void HandleModelShutdown(object model, ShutdownEventArgs reason) } [Fact] - public void TestModelShutdownHandler() + public void TestChannelShutdownHandler() { var latch = new ManualResetEventSlim(false); var duplicateLatch = new ManualResetEventSlim(false); - string q = _model.QueueDeclare().QueueName; + string q = _channel.QueueDeclare().QueueName; var c = new ShutdownLatchConsumer(latch, duplicateLatch); - _model.BasicConsume(queue: q, autoAck: true, consumer: c); - _model.Close(); + _channel.BasicConsume(queue: q, autoAck: true, consumer: c); + _channel.Close(); Wait(latch, TimeSpan.FromSeconds(5)); Assert.False(duplicateLatch.Wait(TimeSpan.FromSeconds(5)), "event handler fired more than once"); diff --git a/projects/Unit/TestEventingConsumer.cs b/projects/Unit/TestEventingConsumer.cs index 601421225f..ba62b94037 100644 --- a/projects/Unit/TestEventingConsumer.cs +++ b/projects/Unit/TestEventingConsumer.cs @@ -47,14 +47,14 @@ public TestEventingConsumer(ITestOutputHelper output) : base(output) [Fact] public void TestEventingConsumerRegistrationEvents() { - string q = _model.QueueDeclare(); + string q = _channel.QueueDeclare(); var registeredLatch = new ManualResetEventSlim(false); object registeredSender = null; var unregisteredLatch = new ManualResetEventSlim(false); object unregisteredSender = null; - EventingBasicConsumer ec = new EventingBasicConsumer(_model); + EventingBasicConsumer ec = new EventingBasicConsumer(_channel); ec.Registered += (s, args) => { registeredSender = s; @@ -67,30 +67,30 @@ public void TestEventingConsumerRegistrationEvents() unregisteredLatch.Set(); }; - string tag = _model.BasicConsume(q, false, ec); + string tag = _channel.BasicConsume(q, false, ec); Wait(registeredLatch); Assert.NotNull(registeredSender); Assert.Equal(ec, registeredSender); - Assert.Equal(_model, ((EventingBasicConsumer)registeredSender).Model); + Assert.Equal(_channel, ((EventingBasicConsumer)registeredSender).Channel); - _model.BasicCancel(tag); + _channel.BasicCancel(tag); Wait(unregisteredLatch); Assert.NotNull(unregisteredSender); Assert.Equal(ec, unregisteredSender); - Assert.Equal(_model, ((EventingBasicConsumer)unregisteredSender).Model); + Assert.Equal(_channel, ((EventingBasicConsumer)unregisteredSender).Channel); } [Fact] public void TestEventingConsumerDeliveryEvents() { - string q = _model.QueueDeclare(); + string q = _channel.QueueDeclare(); object o = new object(); bool receivedInvoked = false; object receivedSender = null; - EventingBasicConsumer ec = new EventingBasicConsumer(_model); + EventingBasicConsumer ec = new EventingBasicConsumer(_channel); ec.Received += (s, args) => { receivedInvoked = true; @@ -99,14 +99,14 @@ public void TestEventingConsumerDeliveryEvents() Monitor.PulseAll(o); }; - _model.BasicConsume(q, true, ec); - _model.BasicPublish("", q, _encoding.GetBytes("msg")); + _channel.BasicConsume(q, true, ec); + _channel.BasicPublish("", q, _encoding.GetBytes("msg")); WaitOn(o); Assert.True(receivedInvoked); Assert.NotNull(receivedSender); Assert.Equal(ec, receivedSender); - Assert.Equal(_model, ((EventingBasicConsumer)receivedSender).Model); + Assert.Equal(_channel, ((EventingBasicConsumer)receivedSender).Channel); bool shutdownInvoked = false; object shutdownSender = null; @@ -119,13 +119,13 @@ public void TestEventingConsumerDeliveryEvents() Monitor.PulseAll(o); }; - _model.Close(); + _channel.Close(); WaitOn(o); Assert.True(shutdownInvoked); Assert.NotNull(shutdownSender); Assert.Equal(ec, shutdownSender); - Assert.Equal(_model, ((EventingBasicConsumer)shutdownSender).Model); + Assert.Equal(_channel, ((EventingBasicConsumer)shutdownSender).Channel); } } } diff --git a/projects/Unit/TestExceptionMessages.cs b/projects/Unit/TestExceptionMessages.cs index 66f8b4dd12..554b3d9207 100644 --- a/projects/Unit/TestExceptionMessages.cs +++ b/projects/Unit/TestExceptionMessages.cs @@ -51,18 +51,18 @@ public void TestAlreadyClosedExceptionMessage() string uuid = System.Guid.NewGuid().ToString(); try { - _model.QueueDeclarePassive(uuid); + _channel.QueueDeclarePassive(uuid); } catch (Exception e) { Assert.IsType(e); } - Assert.False(_model.IsOpen); + Assert.False(_channel.IsOpen); try { - _model.QueueDeclarePassive(uuid); + _channel.QueueDeclarePassive(uuid); } catch (AlreadyClosedException e) { diff --git a/projects/Unit/TestExchangeDeclare.cs b/projects/Unit/TestExchangeDeclare.cs index 6c561b67de..02739660f8 100644 --- a/projects/Unit/TestExchangeDeclare.cs +++ b/projects/Unit/TestExchangeDeclare.cs @@ -62,7 +62,7 @@ public void TestConcurrentExchangeDeclare() // sleep for a random amount of time to increase the chances // of thread interleaving. MK. Thread.Sleep(rnd.Next(5, 500)); - _model.ExchangeDeclare(x, "fanout", false, false, null); + _channel.ExchangeDeclare(x, "fanout", false, false, null); } catch (NotSupportedException e) { @@ -79,7 +79,7 @@ public void TestConcurrentExchangeDeclare() } Assert.Null(nse); - _model.ExchangeDelete(x); + _channel.ExchangeDelete(x); } } } diff --git a/projects/Unit/TestExtensions.cs b/projects/Unit/TestExtensions.cs index 6fa9160f47..2f4dddab3f 100644 --- a/projects/Unit/TestExtensions.cs +++ b/projects/Unit/TestExtensions.cs @@ -47,44 +47,44 @@ public TestExtensions(ITestOutputHelper output) : base(output) [Fact] public async Task TestConfirmBarrier() { - _model.ConfirmSelect(); + _channel.ConfirmSelect(); for (int i = 0; i < 10; i++) { - _model.BasicPublish("", string.Empty); + _channel.BasicPublish("", string.Empty); } - Assert.True(await _model.WaitForConfirmsAsync().ConfigureAwait(false)); + Assert.True(await _channel.WaitForConfirmsAsync().ConfigureAwait(false)); } [Fact] public async Task TestConfirmBeforeWait() { - await Assert.ThrowsAsync(async () => await _model.WaitForConfirmsAsync()); + await Assert.ThrowsAsync(async () => await _channel.WaitForConfirmsAsync()); } [Fact] public async Task TestExchangeBinding() { - _model.ConfirmSelect(); + _channel.ConfirmSelect(); - _model.ExchangeDeclare("src", ExchangeType.Direct, false, false, null); - _model.ExchangeDeclare("dest", ExchangeType.Direct, false, false, null); - string queue = _model.QueueDeclare(); + _channel.ExchangeDeclare("src", ExchangeType.Direct, false, false, null); + _channel.ExchangeDeclare("dest", ExchangeType.Direct, false, false, null); + string queue = _channel.QueueDeclare(); - _model.ExchangeBind("dest", "src", string.Empty); - _model.ExchangeBind("dest", "src", string.Empty); - _model.QueueBind(queue, "dest", string.Empty); + _channel.ExchangeBind("dest", "src", string.Empty); + _channel.ExchangeBind("dest", "src", string.Empty); + _channel.QueueBind(queue, "dest", string.Empty); - _model.BasicPublish("src", string.Empty); - await _model.WaitForConfirmsAsync().ConfigureAwait(false); - Assert.NotNull(_model.BasicGet(queue, true)); + _channel.BasicPublish("src", string.Empty); + await _channel.WaitForConfirmsAsync().ConfigureAwait(false); + Assert.NotNull(_channel.BasicGet(queue, true)); - _model.ExchangeUnbind("dest", "src", string.Empty); - _model.BasicPublish("src", string.Empty); - await _model.WaitForConfirmsAsync().ConfigureAwait(false); - Assert.Null(_model.BasicGet(queue, true)); + _channel.ExchangeUnbind("dest", "src", string.Empty); + _channel.BasicPublish("src", string.Empty); + await _channel.WaitForConfirmsAsync().ConfigureAwait(false); + Assert.Null(_channel.BasicGet(queue, true)); - _model.ExchangeDelete("src"); - _model.ExchangeDelete("dest"); + _channel.ExchangeDelete("src"); + _channel.ExchangeDelete("dest"); } } } diff --git a/projects/Unit/TestFloodPublishing.cs b/projects/Unit/TestFloodPublishing.cs index b1e4f3edd3..ebe0a26be4 100644 --- a/projects/Unit/TestFloodPublishing.cs +++ b/projects/Unit/TestFloodPublishing.cs @@ -66,7 +66,7 @@ public void TestUnthrottledFloodPublishing() var closeWatch = new Stopwatch(); using (IConnection conn = connFactory.CreateConnection()) { - using (IModel model = conn.CreateModel()) + using (IChannel channel = conn.CreateChannel()) { conn.ConnectionShutdown += (_, args) => { @@ -90,7 +90,7 @@ public void TestUnthrottledFloodPublishing() } } - model.BasicPublish(CachedString.Empty, CachedString.Empty, _body); + channel.BasicPublish(CachedString.Empty, CachedString.Empty, _body); } } finally @@ -125,26 +125,26 @@ public void TestMultithreadFloodPublishing() using (IConnection c = cf.CreateConnection()) { string queueName = null; - using (IModel m = c.CreateModel()) + using (IChannel m = c.CreateChannel()) { QueueDeclareOk q = m.QueueDeclare(); queueName = q.QueueName; } - Task pub = Task.Run(() => + Task pub = Task.Run((Action)(() => { - using (IModel m = c.CreateModel()) + using (IChannel pubCh = c.CreateChannel()) { for (int i = 0; i < publishCount; i++) { - m.BasicPublish(string.Empty, queueName, sendBody); + pubCh.BasicPublish(string.Empty, queueName, sendBody); } } - }); + })); - using (IModel consumerModel = c.CreateModel()) + using (IChannel consumeCh = c.CreateChannel()) { - var consumer = new EventingBasicConsumer(consumerModel); + var consumer = new EventingBasicConsumer(consumeCh); consumer.Received += (o, a) => { string receivedMessage = Encoding.UTF8.GetString(a.Body.ToArray()); @@ -155,7 +155,7 @@ public void TestMultithreadFloodPublishing() autoResetEvent.Set(); } }; - consumerModel.BasicConsume(queueName, true, consumer); + consumeCh.BasicConsume(queueName, true, consumer); Assert.True(pub.Wait(_tenSeconds)); Assert.True(autoResetEvent.WaitOne(_tenSeconds)); } diff --git a/projects/Unit/TestHeartbeats.cs b/projects/Unit/TestHeartbeats.cs index 5258f3e633..d2e214c117 100644 --- a/projects/Unit/TestHeartbeats.cs +++ b/projects/Unit/TestHeartbeats.cs @@ -104,7 +104,7 @@ public void TestHundredsOfConnectionsWithRandomHeartbeatInterval() }; IConnection conn = cf.CreateConnection(); xs.Add(conn); - IModel ch = conn.CreateModel(); + IChannel ch = conn.CreateChannel(); conn.ConnectionShutdown += (sender, evt) => { @@ -123,7 +123,7 @@ public void TestHundredsOfConnectionsWithRandomHeartbeatInterval() protected void RunSingleConnectionTest(ConnectionFactory cf) { IConnection conn = cf.CreateConnection(); - IModel ch = conn.CreateModel(); + IChannel ch = conn.CreateChannel(); bool wasShutdown = false; conn.ConnectionShutdown += (sender, evt) => diff --git a/projects/Unit/TestInvalidAck.cs b/projects/Unit/TestInvalidAck.cs index f006bfed69..aeff2d17a7 100644 --- a/projects/Unit/TestInvalidAck.cs +++ b/projects/Unit/TestInvalidAck.cs @@ -49,14 +49,14 @@ public void TestAckWithUnknownConsumerTagAndMultipleFalse() object o = new object(); bool shutdownFired = false; ShutdownEventArgs shutdownArgs = null; - _model.ModelShutdown += (s, args) => + _channel.ChannelShutdown += (s, args) => { shutdownFired = true; shutdownArgs = args; Monitor.PulseAll(o); }; - _model.BasicAck(123456, false); + _channel.BasicAck(123456, false); WaitOn(o); Assert.True(shutdownFired); AssertPreconditionFailed(shutdownArgs); diff --git a/projects/Unit/TestMainLoop.cs b/projects/Unit/TestMainLoop.cs index 23f9edee9b..a2fa183a6f 100644 --- a/projects/Unit/TestMainLoop.cs +++ b/projects/Unit/TestMainLoop.cs @@ -48,7 +48,7 @@ public TestMainLoop(ITestOutputHelper output) : base(output) private sealed class FaultyConsumer : DefaultBasicConsumer { - public FaultyConsumer(IModel model) : base(model) { } + public FaultyConsumer(IChannel channel) : base(channel) { } public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, @@ -67,7 +67,7 @@ public void TestCloseWithFaultyConsumer() { ConnectionFactory connFactory = new ConnectionFactory(); IConnection c = connFactory.CreateConnection(); - IModel m = _conn.CreateModel(); + IChannel m = _conn.CreateChannel(); object o = new object(); string q = GenerateQueueName(); m.QueueDeclare(q, false, false, false, null); @@ -79,7 +79,7 @@ public void TestCloseWithFaultyConsumer() c.Close(); Monitor.PulseAll(o); }; - m.BasicConsume(q, true, new FaultyConsumer(_model)); + m.BasicConsume(q, true, new FaultyConsumer(_channel)); m.BasicPublish("", q, _encoding.GetBytes("message")); WaitOn(o); diff --git a/projects/Unit/TestMessageCount.cs b/projects/Unit/TestMessageCount.cs index c84d60c20c..332dc01866 100644 --- a/projects/Unit/TestMessageCount.cs +++ b/projects/Unit/TestMessageCount.cs @@ -45,14 +45,14 @@ public TestMessageCount(ITestOutputHelper output) : base(output) [Fact] public async Task TestMessageCountMethod() { - _model.ConfirmSelect(); + _channel.ConfirmSelect(); string q = GenerateQueueName(); - _model.QueueDeclare(queue: q, durable: false, exclusive: true, autoDelete: false, arguments: null); - Assert.Equal(0u, _model.MessageCount(q)); + _channel.QueueDeclare(queue: q, durable: false, exclusive: true, autoDelete: false, arguments: null); + Assert.Equal(0u, _channel.MessageCount(q)); - _model.BasicPublish("", q, _encoding.GetBytes("msg")); - await _model.WaitForConfirmsAsync().ConfigureAwait(false); - Assert.Equal(1u, _model.MessageCount(q)); + _channel.BasicPublish("", q, _encoding.GetBytes("msg")); + await _channel.WaitForConfirmsAsync().ConfigureAwait(false); + Assert.Equal(1u, _channel.MessageCount(q)); } } } diff --git a/projects/Unit/TestNowait.cs b/projects/Unit/TestNowait.cs index 4c936ac647..9546cad537 100644 --- a/projects/Unit/TestNowait.cs +++ b/projects/Unit/TestNowait.cs @@ -45,24 +45,24 @@ public TestNoWait(ITestOutputHelper output) : base(output) public void TestQueueDeclareNoWait() { string q = GenerateQueueName(); - _model.QueueDeclareNoWait(q, false, true, false, null); - _model.QueueDeclarePassive(q); + _channel.QueueDeclareNoWait(q, false, true, false, null); + _channel.QueueDeclarePassive(q); } [Fact] public void TestQueueBindNoWait() { string q = GenerateQueueName(); - _model.QueueDeclareNoWait(q, false, true, false, null); - _model.QueueBindNoWait(q, "amq.fanout", "", null); + _channel.QueueDeclareNoWait(q, false, true, false, null); + _channel.QueueBindNoWait(q, "amq.fanout", "", null); } [Fact] public void TestQueueDeleteNoWait() { string q = GenerateQueueName(); - _model.QueueDeclareNoWait(q, false, true, false, null); - _model.QueueDeleteNoWait(q, false, false); + _channel.QueueDeclareNoWait(q, false, true, false, null); + _channel.QueueDeleteNoWait(q, false, false); } [Fact] @@ -71,12 +71,12 @@ public void TestExchangeDeclareNoWait() string x = GenerateExchangeName(); try { - _model.ExchangeDeclareNoWait(x, "fanout", false, true, null); - _model.ExchangeDeclarePassive(x); + _channel.ExchangeDeclareNoWait(x, "fanout", false, true, null); + _channel.ExchangeDeclarePassive(x); } finally { - _model.ExchangeDelete(x); + _channel.ExchangeDelete(x); } } @@ -86,12 +86,12 @@ public void TestExchangeBindNoWait() string x = GenerateExchangeName(); try { - _model.ExchangeDeclareNoWait(x, "fanout", false, true, null); - _model.ExchangeBindNoWait(x, "amq.fanout", "", null); + _channel.ExchangeDeclareNoWait(x, "fanout", false, true, null); + _channel.ExchangeBindNoWait(x, "amq.fanout", "", null); } finally { - _model.ExchangeDelete(x); + _channel.ExchangeDelete(x); } } @@ -101,13 +101,13 @@ public void TestExchangeUnbindNoWait() string x = GenerateExchangeName(); try { - _model.ExchangeDeclare(x, "fanout", false, true, null); - _model.ExchangeBind(x, "amq.fanout", "", null); - _model.ExchangeUnbindNoWait(x, "amq.fanout", "", null); + _channel.ExchangeDeclare(x, "fanout", false, true, null); + _channel.ExchangeBind(x, "amq.fanout", "", null); + _channel.ExchangeUnbindNoWait(x, "amq.fanout", "", null); } finally { - _model.ExchangeDelete(x); + _channel.ExchangeDelete(x); } } @@ -115,8 +115,8 @@ public void TestExchangeUnbindNoWait() public void TestExchangeDeleteNoWait() { string x = GenerateExchangeName(); - _model.ExchangeDeclareNoWait(x, "fanout", false, true, null); - _model.ExchangeDeleteNoWait(x, false); + _channel.ExchangeDeclareNoWait(x, "fanout", false, true, null); + _channel.ExchangeDeleteNoWait(x, false); } } } diff --git a/projects/Unit/TestPassiveDeclare.cs b/projects/Unit/TestPassiveDeclare.cs index 819e8a91e4..db9b167752 100644 --- a/projects/Unit/TestPassiveDeclare.cs +++ b/projects/Unit/TestPassiveDeclare.cs @@ -48,13 +48,13 @@ public TestPassiveDeclare(ITestOutputHelper output) : base(output) [Fact] public void TestPassiveExchangeDeclareWhenExchangeDoesNotExist() { - Assert.Throws(() => _model.ExchangeDeclarePassive(Guid.NewGuid().ToString())); + Assert.Throws(() => _channel.ExchangeDeclarePassive(Guid.NewGuid().ToString())); } [Fact] public void TestPassiveQueueDeclareWhenQueueDoesNotExist() { - Assert.Throws(() => _model.QueueDeclarePassive(Guid.NewGuid().ToString())); + Assert.Throws(() => _channel.QueueDeclarePassive(Guid.NewGuid().ToString())); } } } diff --git a/projects/Unit/TestPublishSharedModel.cs b/projects/Unit/TestPublishSharedChannel.cs similarity index 77% rename from projects/Unit/TestPublishSharedModel.cs rename to projects/Unit/TestPublishSharedChannel.cs index 1fcf6ad017..7042498626 100644 --- a/projects/Unit/TestPublishSharedModel.cs +++ b/projects/Unit/TestPublishSharedChannel.cs @@ -38,11 +38,11 @@ namespace RabbitMQ.Client.Unit { - public class TestPublishSharedModel + public class TestPublishSharedChannel { - private const string QueueName = "TestPublishSharedModel_Queue"; - private static readonly CachedString ExchangeName = new CachedString("TestPublishSharedModel_Ex"); - private static readonly CachedString PublishKey = new CachedString("TestPublishSharedModel_RoutePub"); + private const string QueueName = "TestPublishSharedChannel_Queue"; + private static readonly CachedString ExchangeName = new CachedString("TestPublishSharedChannel_Ex"); + private static readonly CachedString PublishKey = new CachedString("TestPublishSharedChannel_RoutePub"); private const int Loops = 20; private const int Repeats = 1000; @@ -51,7 +51,7 @@ public class TestPublishSharedModel private Exception _raisedException; [Fact] - public async Task MultiThreadPublishOnSharedModel() + public async Task MultiThreadPublishOnSharedChannel() { // Arrange var connFactory = new ConnectionFactory @@ -70,15 +70,15 @@ public async Task MultiThreadPublishOnSharedModel() } }; - using (IModel model = conn.CreateModel()) + using (IChannel channel = conn.CreateChannel()) { - model.ExchangeDeclare(ExchangeName.Value, "topic", durable: false, autoDelete: true); - model.QueueDeclare(QueueName, false, false, true, null); - model.QueueBind(QueueName, ExchangeName.Value, PublishKey.Value, null); + channel.ExchangeDeclare(ExchangeName.Value, "topic", durable: false, autoDelete: true); + channel.QueueDeclare(QueueName, false, false, true, null); + channel.QueueBind(QueueName, ExchangeName.Value, PublishKey.Value, null); // Act - var pubTask = Task.Run(() => NewFunction(model)); - var pubTask2 = Task.Run(() => NewFunction(model)); + var pubTask = Task.Run(() => NewFunction(channel)); + var pubTask2 = Task.Run(() => NewFunction(channel)); await Task.WhenAll(pubTask, pubTask2); } @@ -87,7 +87,7 @@ public async Task MultiThreadPublishOnSharedModel() // Assert Assert.Null(_raisedException); - void NewFunction(IModel model) + void NewFunction(IChannel channel) { try { @@ -95,7 +95,7 @@ void NewFunction(IModel model) { for (int j = 0; j < Repeats; j++) { - model.BasicPublish(ExchangeName, PublishKey, _body, false); + channel.BasicPublish(ExchangeName, PublishKey, _body, false); } Thread.Sleep(1); diff --git a/projects/Unit/TestPublisherConfirms.cs b/projects/Unit/TestPublisherConfirms.cs index a731ae2fae..c844a38706 100644 --- a/projects/Unit/TestPublisherConfirms.cs +++ b/projects/Unit/TestPublisherConfirms.cs @@ -93,11 +93,11 @@ public void TestWaitForConfirmsWithTimeout_MessageNacked_WaitingHasTimedout_Retu { TestWaitForConfirms(2000, (ch) => { - IModel actualModel = ((AutorecoveringModel)ch).InnerChannel; - actualModel + IChannel actualChannel = ((AutorecoveringChannel)ch).InnerChannel; + actualChannel .GetType() .GetMethod("HandleAckNack", BindingFlags.Instance | BindingFlags.NonPublic) - .Invoke(actualModel, new object[] { 10UL, false, true }); + .Invoke(actualChannel, new object[] { 10UL, false, true }); using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(4))) { @@ -109,7 +109,7 @@ public void TestWaitForConfirmsWithTimeout_MessageNacked_WaitingHasTimedout_Retu [Fact] public async Task TestWaitForConfirmsWithEvents() { - using (IModel ch = _conn.CreateModel()) + using (IChannel ch = _conn.CreateChannel()) { ch.ConfirmSelect(); @@ -143,9 +143,9 @@ public async Task TestWaitForConfirmsWithEvents() } } - protected void TestWaitForConfirms(int numberOfMessagesToPublish, Action fn) + protected void TestWaitForConfirms(int numberOfMessagesToPublish, Action fn) { - using (IModel ch = _conn.CreateModel()) + using (IChannel ch = _conn.CreateChannel()) { ch.ConfirmSelect(); ch.QueueDeclare(QueueName); diff --git a/projects/Unit/TestQueueDeclare.cs b/projects/Unit/TestQueueDeclare.cs index 32fd5050bc..02ea7516a9 100644 --- a/projects/Unit/TestQueueDeclare.cs +++ b/projects/Unit/TestQueueDeclare.cs @@ -62,7 +62,7 @@ public void TestConcurrentQueueDeclare() // sleep for a random amount of time to increase the chances // of thread interleaving. MK. Thread.Sleep(rnd.Next(5, 50)); - _model.QueueDeclare(q, false, false, false, null); + _channel.QueueDeclare(q, false, false, false, null); } catch (NotSupportedException e) { @@ -79,7 +79,7 @@ public void TestConcurrentQueueDeclare() } Assert.Null(nse); - _model.QueueDelete(q); + _channel.QueueDelete(q); } } } diff --git a/projects/Unit/TestRecoverAfterCancel.cs b/projects/Unit/TestRecoverAfterCancel.cs index 3734ebad28..894d00a779 100644 --- a/projects/Unit/TestRecoverAfterCancel.cs +++ b/projects/Unit/TestRecoverAfterCancel.cs @@ -46,20 +46,20 @@ namespace RabbitMQ.Client.Unit public class TestRecoverAfterCancel : IDisposable { IConnection _connection; - IModel _channel; + IChannel _channel; string _queue; int _callbackCount; public TestRecoverAfterCancel() { _connection = new ConnectionFactory().CreateConnection(); - _channel = _connection.CreateModel(); + _channel = _connection.CreateChannel(); _queue = _channel.QueueDeclare("", false, true, false, null); } - public int ModelNumber(IModel model) + public int ChannelNumber(IChannel channel) { - return ((ModelBase)model).Session.ChannelNumber; + return ((ChannelBase)channel).Session.ChannelNumber; } public void Dispose() diff --git a/projects/Unit/TestSsl.cs b/projects/Unit/TestSsl.cs index f48718a8b3..992b9d7342 100644 --- a/projects/Unit/TestSsl.cs +++ b/projects/Unit/TestSsl.cs @@ -129,7 +129,7 @@ private void SendReceive(ConnectionFactory cf) { using (IConnection conn = cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}")) { - using (IModel ch = conn.CreateModel()) + using (IChannel ch = conn.CreateChannel()) { ch.ExchangeDeclare("Exchange_TestSslEndPoint", ExchangeType.Direct); string qName = ch.QueueDeclare();