diff --git a/.editorconfig b/.editorconfig index 1c14c205..1f9aebf3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,6 +6,44 @@ trim_trailing_whitespace = true insert_final_newline = true indent_style = space indent_size = 4 +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion +dotnet_style_namespace_match_folder = true:suggestion +dotnet_style_readonly_field = true:suggestion +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent +dotnet_style_allow_multiple_blank_lines_experimental = false:error +dotnet_style_allow_statement_immediately_after_block_experimental = true:silent +dotnet_code_quality_unused_parameters = non_public:suggestion +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion +dotnet_diagnostic.RS0016.severity = error +dotnet_diagnostic.RS0017.severity = error +dotnet_diagnostic.RS0024.severity = error +dotnet_diagnostic.RS0025.severity = error +dotnet_diagnostic.RS0036.severity = warning [*.cs] # New line preferences @@ -45,7 +83,7 @@ dotnet_style_predefined_type_for_member_access = true:suggestion # name all constant fields using PascalCase dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields -dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style dotnet_naming_symbols.constant_fields.applicable_kinds = field dotnet_naming_symbols.constant_fields.required_modifiers = const dotnet_naming_style.pascal_case_style.capitalization = pascal_case @@ -53,7 +91,7 @@ dotnet_naming_style.pascal_case_style.capitalization = pascal_case # static fields should have s_ prefix dotnet_naming_rule.static_fields_should_have_prefix.severity = warning dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields -dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style dotnet_naming_symbols.static_fields.applicable_kinds = field dotnet_naming_symbols.static_fields.required_modifiers = static dotnet_naming_symbols.static_fields.applicable_accessibilities = internal, private, private_protected, protected @@ -63,7 +101,7 @@ dotnet_naming_style.static_prefix_style.capitalization = camel_case # internal and private fields should be _camelCase dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style dotnet_naming_symbols.private_internal_fields.applicable_kinds = field dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = internal, private, private_protected, protected dotnet_naming_style.camel_case_underscore_style.required_prefix = _ @@ -98,14 +136,14 @@ dotnet_style_prefer_conditional_expression_over_return = true:refactoring csharp_prefer_simple_default_expression = true:suggestion # Expression-bodied members -csharp_style_expression_bodied_methods = true:refactoring -csharp_style_expression_bodied_constructors = true:refactoring -csharp_style_expression_bodied_operators = true:refactoring -csharp_style_expression_bodied_properties = true:refactoring -csharp_style_expression_bodied_indexers = true:refactoring -csharp_style_expression_bodied_accessors = true:refactoring -csharp_style_expression_bodied_lambdas = true:refactoring -csharp_style_expression_bodied_local_functions = true:refactoring +csharp_style_expression_bodied_methods = true:silent +csharp_style_expression_bodied_constructors = true:silent +csharp_style_expression_bodied_operators = true:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = true:silent # Pattern matching csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion @@ -171,6 +209,28 @@ dotnet_diagnostic.RS0041.severity = none dotnet_diagnostic.RS0051.severity = error dotnet_diagnostic.CA2007.severity = error +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_style_prefer_null_check_over_type_check = true:suggestion +csharp_style_prefer_local_over_anonymous_function = true:suggestion +csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion +csharp_style_prefer_tuple_swap = true:suggestion +csharp_style_prefer_utf8_string_literals = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +csharp_prefer_static_anonymous_function = true:suggestion +csharp_style_prefer_readonly_struct = true:suggestion +csharp_style_prefer_readonly_struct_member = true:suggestion +csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent +csharp_style_prefer_pattern_matching = true:silent +csharp_style_prefer_not_pattern = true:suggestion +csharp_style_prefer_extended_property_pattern = true:suggestion # C++ Files [*.{cpp,h,in}] diff --git a/RabbitMQ.AMQP.Client/ByteCapacity.cs b/RabbitMQ.AMQP.Client/ByteCapacity.cs index dbb5c62d..7bca9cd8 100644 --- a/RabbitMQ.AMQP.Client/ByteCapacity.cs +++ b/RabbitMQ.AMQP.Client/ByteCapacity.cs @@ -27,7 +27,6 @@ private ByteCapacity(long bytes) : this(bytes, bytes.ToString()) private const int GigabytesMultiplier = 1000 * 1000 * 1000; private const long TerabytesMultiplier = 1000L * 1000L * 1000L * 1000L; - public static ByteCapacity B(long bytes) { return new ByteCapacity(bytes); @@ -53,7 +52,6 @@ public static ByteCapacity Tb(long terabytes) return new ByteCapacity(terabytes * TerabytesMultiplier); } - private static readonly Regex s_sizeRegex = new Regex(@"^(\d+)([kKmMgGtTpP]?[bB]?)$", RegexOptions.Compiled); public static ByteCapacity From(string value) @@ -82,7 +80,6 @@ public long ToBytes() return _bytes; } - public bool Equals(ByteCapacity? other) { if (ReferenceEquals(null, other)) diff --git a/RabbitMQ.AMQP.Client/IConsumerBuilder.cs b/RabbitMQ.AMQP.Client/IConsumerBuilder.cs index db6c42fd..d8cba377 100644 --- a/RabbitMQ.AMQP.Client/IConsumerBuilder.cs +++ b/RabbitMQ.AMQP.Client/IConsumerBuilder.cs @@ -40,7 +40,6 @@ public interface IConsumerBuilder Task BuildAndStartAsync(CancellationToken cancellationToken = default); - public interface IStreamOptions { IStreamOptions Offset(long offset); @@ -50,7 +49,6 @@ public interface IStreamOptions IConsumerBuilder Builder(); } - /// /// ListenerContext is a helper class that holds the contexts for the listener /// diff --git a/RabbitMQ.AMQP.Client/IEntities.cs b/RabbitMQ.AMQP.Client/IEntities.cs index 6366fe9c..8b8969cf 100644 --- a/RabbitMQ.AMQP.Client/IEntities.cs +++ b/RabbitMQ.AMQP.Client/IEntities.cs @@ -81,6 +81,8 @@ public interface IQueueSpecification : IEntityInfoSpecification IQuorumQueueSpecification Quorum(); IClassicQueueSpecification Classic(); + + Task PurgeAsync(); } public interface IStreamSpecification diff --git a/RabbitMQ.AMQP.Client/IEntitiesInfo.cs b/RabbitMQ.AMQP.Client/IEntitiesInfo.cs index 005e1fba..a3107611 100644 --- a/RabbitMQ.AMQP.Client/IEntitiesInfo.cs +++ b/RabbitMQ.AMQP.Client/IEntitiesInfo.cs @@ -39,7 +39,6 @@ public interface IQueueInfo : IEntityInfo uint ConsumerCount(); } - public enum ExchangeType { DIRECT, diff --git a/RabbitMQ.AMQP.Client/IManagement.cs b/RabbitMQ.AMQP.Client/IManagement.cs index 937c5642..afbd7ef4 100644 --- a/RabbitMQ.AMQP.Client/IManagement.cs +++ b/RabbitMQ.AMQP.Client/IManagement.cs @@ -22,6 +22,13 @@ public PreconditionFailedException(string message) : base(message) } } + public class BadRequestException : Exception + { + public BadRequestException(string message) : base(message) + { + } + } + /// /// IManagement interface and is responsible for managing the AMQP resources. /// RabbitMQ uses AMQP end point: "/management" to manage the resources like queues, exchanges, and bindings. diff --git a/RabbitMQ.AMQP.Client/IMessage.cs b/RabbitMQ.AMQP.Client/IMessage.cs index b18e4dc3..a9b567a0 100644 --- a/RabbitMQ.AMQP.Client/IMessage.cs +++ b/RabbitMQ.AMQP.Client/IMessage.cs @@ -24,7 +24,6 @@ public interface IMessage string Subject(); IMessage Subject(string subject); - public IMessage Annotation(string key, object value); public object Annotation(string key); diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpBindingSpecification.cs b/RabbitMQ.AMQP.Client/Impl/AmqpBindingSpecification.cs index d5ccdffd..03d71bd3 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpBindingSpecification.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpBindingSpecification.cs @@ -41,13 +41,7 @@ public AmqpBindingSpecification(AmqpManagement management) _topologyListener = ((IManagementTopology)_management).TopologyListener(); } - public string BindingPath - { - get - { - return BindingsTarget(); - } - } + public string BindingPath => BindingsTarget(); public async Task BindAsync() { @@ -115,13 +109,7 @@ public IBindingSpecification SourceExchange(string exchangeName) return this; } - public string SourceExchangeName - { - get - { - return _sourceName; - } - } + public string SourceExchangeName => _sourceName; public IBindingSpecification DestinationQueue(IQueueSpecification queueSpec) { @@ -135,13 +123,7 @@ public IBindingSpecification DestinationQueue(string queueName) return this; } - public string DestinationQueueName - { - get - { - return _destinationName; - } - } + public string DestinationQueueName => _destinationName; public IBindingSpecification DestinationExchange(IExchangeSpecification exchangeSpec) { @@ -154,13 +136,7 @@ public IBindingSpecification DestinationExchange(string exchangeName) return this; } - public string DestinationExchangeName - { - get - { - return _destinationName; - } - } + public string DestinationExchangeName => _destinationName; public IBindingSpecification Key(string bindingKey) { @@ -168,13 +144,7 @@ public IBindingSpecification Key(string bindingKey) return this; } - public string BindingKey - { - get - { - return _routingKey; - } - } + public string BindingKey => _routingKey; public IBindingSpecification Argument(string key, object value) { @@ -188,13 +158,7 @@ public IBindingSpecification Arguments(Dictionary arguments) return this; } - public Dictionary BindingArguments - { - get - { - return _arguments; - } - } + public Dictionary BindingArguments => _arguments; private string BindingsTarget() { diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs b/RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs index c8ef8abb..adf4332f 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs @@ -50,7 +50,6 @@ public class AmqpConnection : AbstractLifeCycle, IConnection private readonly TaskCompletionSource _connectionClosedTcs = new(TaskCreationOptions.RunContinuationsAsynchronously); - /// /// Read-only collection of publishers. /// See @@ -61,7 +60,6 @@ public ReadOnlyCollection GetPublishers() return Publishers.Values.ToList().AsReadOnly(); } - /// /// Read-only collection of consumers. /// See @@ -89,7 +87,6 @@ await connection.OpenAsync() return connection; } - public IManagement Management() { return _management; @@ -165,13 +162,7 @@ public override string ToString() return info; } - internal Connection? NativeConnection - { - get - { - return _nativeConnection; - } - } + internal Connection? NativeConnection => _nativeConnection; protected override void Dispose(bool disposing) { diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpConsumer.cs b/RabbitMQ.AMQP.Client/Impl/AmqpConsumer.cs index abc768ba..2fa310d4 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpConsumer.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpConsumer.cs @@ -53,7 +53,6 @@ public override async Task OpenAsync() _configuration.ListenerContext?.Invoke( new IConsumerBuilder.ListenerContext(new ListenerStreamOptions(_configuration.Filters))); - Attach attach = Utils.CreateAttach(_configuration.Address, DeliveryMode.AtLeastOnce, _id, _configuration.Filters); @@ -203,10 +202,7 @@ ref Unsafe.As(ref _pauseStatus), } } - public long UnsettledMessageCount - { - get { return _unsettledMessageCounter.Get(); } - } + public long UnsettledMessageCount => _unsettledMessageCounter.Get(); public void Unpause() { diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpConsumerBuilder.cs b/RabbitMQ.AMQP.Client/Impl/AmqpConsumerBuilder.cs index e315bf65..5b9b720b 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpConsumerBuilder.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpConsumerBuilder.cs @@ -66,13 +66,11 @@ public IConsumerBuilder SubscriptionListener(Action BuildAndStartAsync(CancellationToken cancellationToken = default) { if (_configuration.Handler is null) @@ -80,7 +78,6 @@ public async Task BuildAndStartAsync(CancellationToken cancellationTo throw new ConsumerException("Message handler is not set"); } - AmqpConsumer consumer = new(_configuration); // TODO pass cancellationToken @@ -91,7 +88,6 @@ await consumer.OpenAsync() } } - /// /// The base class for the stream options. /// The class set the right filters used to create the consumer @@ -144,7 +140,6 @@ public IConsumerBuilder.IStreamOptions FilterMatchUnfiltered(bool matchUnfiltere public abstract IConsumerBuilder Builder(); } - /// /// The stream options for the Subscribe Listener event. /// For the user perspective, it is used to set the stream options for the listener @@ -177,7 +172,6 @@ public ConsumerBuilderStreamOptions(IConsumerBuilder consumerBuilder, Map filter _consumerBuilder = consumerBuilder; } - public override IConsumerBuilder Builder() { return _consumerBuilder; diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpExchangeSpecification.cs b/RabbitMQ.AMQP.Client/Impl/AmqpExchangeSpecification.cs index e92c943a..68f18301 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpExchangeSpecification.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpExchangeSpecification.cs @@ -65,13 +65,7 @@ public IExchangeSpecification Name(string name) return this; } - public string ExchangeName - { - get - { - return _name; - } - } + public string ExchangeName => _name; public IExchangeSpecification AutoDelete(bool autoDelete) { @@ -79,13 +73,7 @@ public IExchangeSpecification AutoDelete(bool autoDelete) return this; } - public bool IsAutoDelete - { - get - { - return _autoDelete; - } - } + public bool IsAutoDelete => _autoDelete; public IExchangeSpecification Type(ExchangeType type) { @@ -93,13 +81,7 @@ public IExchangeSpecification Type(ExchangeType type) return this; } - public ExchangeType ExchangeType - { - get - { - return _type; - } - } + public ExchangeType ExchangeType => _type; public IExchangeSpecification Argument(string key, object value) { diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpManagement.cs b/RabbitMQ.AMQP.Client/Impl/AmqpManagement.cs index 1b64e59e..e68c9b27 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpManagement.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpManagement.cs @@ -40,6 +40,7 @@ public class AmqpManagement : AbstractLifeCycle, IManagement, IManagementTopolog internal const int Code201 = 201; internal const int Code204 = 204; internal const int Code409 = 409; + internal const int Code400 = 400; internal const string Put = "PUT"; internal const string Get = "GET"; internal const string Post = "POST"; @@ -75,7 +76,6 @@ public IQueueSpecification Queue(string name) return Queue().Name(name); } - /// /// Get the queue info for the given queue specification /// See for more information @@ -87,7 +87,6 @@ public Task GetQueueInfoAsync(IQueueSpecification queueSpec, return GetQueueInfoAsync(queueSpec.QueueName, cancellationToken); } - /// /// Get the queue info for the given queue name /// See for more information @@ -107,7 +106,6 @@ public async Task GetQueueInfoAsync(string queueName, return new DefaultQueueInfo((Map)response.Body); } - internal IQueueSpecification Queue(QueueSpec spec) { return Queue().Name(spec.QueueName) @@ -116,7 +114,6 @@ internal IQueueSpecification Queue(QueueSpec spec) .Arguments(spec.QueueArguments); } - /// /// Create a new AMQPExchange specification /// See for more information @@ -128,7 +125,6 @@ public IExchangeSpecification Exchange() return new AmqpExchangeSpecification(this); } - /// /// /// Create a new AMQPExchange specification with the given name @@ -474,6 +470,8 @@ internal void CheckResponse(Message sentMessage, int[] expectedResponseCodes, Me { case Code409: throw new PreconditionFailedException($"{receivedMessage.Body}, response code: {responseCode}"); + case Code400: + throw new BadRequestException($"{receivedMessage.Body}, response code: {responseCode}"); } // Check if the correlationId is the same as the messageId diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpManagementParameters.cs b/RabbitMQ.AMQP.Client/Impl/AmqpManagementParameters.cs index 849abb94..1bf32847 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpManagementParameters.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpManagementParameters.cs @@ -23,21 +23,9 @@ internal AmqpManagementParameters TopologyListener(RecordingTopologyListener top return this; } - internal AmqpConnection Connection - { - get - { - return _amqpConnection; - } - } + internal AmqpConnection Connection => _amqpConnection; - internal Amqp.Connection? NativeConnection - { - get - { - return _amqpConnection.NativeConnection; - } - } + internal Amqp.Connection? NativeConnection => _amqpConnection.NativeConnection; internal bool IsNativeConnectionClosed { diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpMessage.cs b/RabbitMQ.AMQP.Client/Impl/AmqpMessage.cs index 020d4646..51455bf9 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpMessage.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpMessage.cs @@ -22,7 +22,6 @@ public AmqpMessage() NativeMessage = new Message(); } - public AmqpMessage(object body) { NativeMessage = new Message(body); @@ -46,7 +45,6 @@ private void EnsureProperties() NativeMessage.Properties ??= new Properties(); } - private void ThrowIfAnnotationsNotSet() { if (NativeMessage.MessageAnnotations == null) diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpPublisher.cs b/RabbitMQ.AMQP.Client/Impl/AmqpPublisher.cs index 8b2cc2aa..f16014f3 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpPublisher.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpPublisher.cs @@ -99,7 +99,6 @@ await base.OpenAsync() } } - /// /// Publishes a message to the broker in an asynchronous manner. /// The PublishResult is synchronous. In order to increase the performance diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpPublisherBuilder.cs b/RabbitMQ.AMQP.Client/Impl/AmqpPublisherBuilder.cs index b4bffb8a..8de206bf 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpPublisherBuilder.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpPublisherBuilder.cs @@ -132,7 +132,6 @@ public IPublisherBuilder PublishTimeout(TimeSpan timeout) return this; } - public async Task BuildAsync(CancellationToken cancellationToken = default) { string address = new AddressBuilder().Exchange(_exchange).Queue(_queue).Key(_key).Address(); diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpQueueSpecification.cs b/RabbitMQ.AMQP.Client/Impl/AmqpQueueSpecification.cs index 2483982c..7c2335e2 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpQueueSpecification.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpQueueSpecification.cs @@ -25,7 +25,6 @@ public class DefaultQueueInfo : IQueueInfo private readonly ulong _messageCount; private readonly uint _consumerCount; - internal DefaultQueueInfo(string queueName) { _name = queueName; @@ -139,13 +138,7 @@ public IQueueSpecification Name(string queueName) return this; } - public string QueueName - { - get - { - return _queueName ?? string.Empty; - } - } + public string QueueName => _queueName ?? string.Empty; public IQueueSpecification Exclusive(bool isExclusive) { @@ -153,13 +146,7 @@ public IQueueSpecification Exclusive(bool isExclusive) return this; } - public bool IsExclusive - { - get - { - return _isExclusive; - } - } + public bool IsExclusive => _isExclusive; public IQueueSpecification AutoDelete(bool isAutoDelete) { @@ -167,13 +154,7 @@ public IQueueSpecification AutoDelete(bool isAutoDelete) return this; } - public bool IsAutoDelete - { - get - { - return _isAutoDelete; - } - } + public bool IsAutoDelete => _isAutoDelete; public IQueueSpecification Arguments(Dictionary queueArguments) { @@ -186,13 +167,7 @@ public IQueueSpecification Arguments(Dictionary queueArguments) return this; } - public Dictionary QueueArguments - { - get - { - return _queueArguments; - } - } + public Dictionary QueueArguments => _queueArguments; public IQueueSpecification Type(QueueType queueType) { @@ -208,6 +183,7 @@ public QueueType QueueType { return QueueType.CLASSIC; } + string type = (string)_queueArguments["x-queue-type"]; return (QueueType)Enum.Parse(typeof(QueueType), type.ToUpperInvariant()); } @@ -275,6 +251,24 @@ public IClassicQueueSpecification Classic() return new AmqpClassicSpecification(this); } + public async Task PurgeAsync() + { + if (_queueName is null) + { + // TODO create "internal bug" exception type? + throw new InvalidOperationException( + "_name is null, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues"); + } + + string path = $"/{Consts.Queues}/{Utils.EncodePathSegment(_queueName)}/{Consts.Messages}"; + string method = AmqpManagement.Delete; + int[] expectedResponseCodes = { AmqpManagement.Code200 }; + Message result = await _management.RequestAsync(null, path, method, expectedResponseCodes) + .ConfigureAwait(false); + Map kv = (Map)result.Body; + return (ulong)kv["message_count"]; + } + public IQueueSpecification MaxLength(long maxLength) { Utils.ValidatePositive("Max length", maxLength); @@ -318,12 +312,14 @@ public async Task DeclareAsync() if (_queueName is null) { // TODO create "internal bug" exception type? - throw new InvalidOperationException("_name is null, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues"); + throw new InvalidOperationException( + "_name is null, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues"); } string path = $"/{Consts.Queues}/{Utils.EncodePathSegment(_queueName)}"; string method = AmqpManagement.Put; - int[] expectedResponseCodes = new int[] { AmqpManagement.Code200, AmqpManagement.Code201, AmqpManagement.Code409 }; + int[] expectedResponseCodes = + new int[] { AmqpManagement.Code200, AmqpManagement.Code201, AmqpManagement.Code409 }; Message response = await _management.RequestAsync(kv, path, method, expectedResponseCodes) .ConfigureAwait(false); @@ -337,13 +333,15 @@ public async Task DeleteAsync() if (_queueName is null) { // TODO create "internal bug" exception type? - throw new InvalidOperationException("_name is null or empty, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues"); + throw new InvalidOperationException( + "_name is null or empty, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues"); } if (string.IsNullOrEmpty(_queueName)) { // TODO create "internal bug" exception type? - throw new InvalidOperationException("_name is null or empty, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues"); + throw new InvalidOperationException( + "_name is null or empty, report via https://github.com/rabbitmq/rabbitmq-amqp-dotnet-client/issues"); } string path = $"/{Consts.Queues}/{Utils.EncodePathSegment(_queueName)}"; diff --git a/RabbitMQ.AMQP.Client/Impl/ConnectionSettings.cs b/RabbitMQ.AMQP.Client/Impl/ConnectionSettings.cs index 030c9d1f..3c9ff708 100644 --- a/RabbitMQ.AMQP.Client/Impl/ConnectionSettings.cs +++ b/RabbitMQ.AMQP.Client/Impl/ConnectionSettings.cs @@ -348,7 +348,6 @@ private BackOffDelayPolicy(int maxAttempt) private int _attempt = 1; private readonly int _maxAttempt = 12; - private void ResetAfterMaxAttempt() { if (_attempt > 5) @@ -378,7 +377,6 @@ public bool IsActive() public int CurrentAttempt { get; private set; } = 0; - public override string ToString() { return $"BackOffDelayPolicy{{ Attempt={_attempt}, TotalAttempt={CurrentAttempt}, IsActive={IsActive()} }}"; diff --git a/RabbitMQ.AMQP.Client/Impl/Consts.cs b/RabbitMQ.AMQP.Client/Impl/Consts.cs index 81492669..463719e5 100644 --- a/RabbitMQ.AMQP.Client/Impl/Consts.cs +++ b/RabbitMQ.AMQP.Client/Impl/Consts.cs @@ -10,6 +10,7 @@ public class Consts public const string Key = "key"; public const string Queues = "queues"; public const string Bindings = "bindings"; + public const string Messages = "messages"; /// /// uint.MinValue means "no limit" diff --git a/RabbitMQ.AMQP.Client/Impl/RecordingTopologyListener.cs b/RabbitMQ.AMQP.Client/Impl/RecordingTopologyListener.cs index e9623811..17eb6ca2 100644 --- a/RabbitMQ.AMQP.Client/Impl/RecordingTopologyListener.cs +++ b/RabbitMQ.AMQP.Client/Impl/RecordingTopologyListener.cs @@ -122,37 +122,13 @@ internal QueueSpec(IQueueSpecification queueSpecification) _queueSpecification = queueSpecification; } - internal string QueueName - { - get - { - return _queueSpecification.QueueName; - } - } + internal string QueueName => _queueSpecification.QueueName; - internal bool IsExclusive - { - get - { - return _queueSpecification.IsExclusive; - } - } + internal bool IsExclusive => _queueSpecification.IsExclusive; - internal bool IsAutoDelete - { - get - { - return _queueSpecification.IsAutoDelete; - } - } + internal bool IsAutoDelete => _queueSpecification.IsAutoDelete; - internal Dictionary QueueArguments - { - get - { - return _queueSpecification.QueueArguments; - } - } + internal Dictionary QueueArguments => _queueSpecification.QueueArguments; } internal class ExchangeSpec @@ -164,37 +140,13 @@ internal ExchangeSpec(IExchangeSpecification exchangeSpecification) _exchangeSpecification = exchangeSpecification; } - internal string ExchangeName - { - get - { - return _exchangeSpecification.ExchangeName; - } - } + internal string ExchangeName => _exchangeSpecification.ExchangeName; - internal ExchangeType ExchangeType - { - get - { - return _exchangeSpecification.ExchangeType; - } - } + internal ExchangeType ExchangeType => _exchangeSpecification.ExchangeType; - internal bool IsAutoDelete - { - get - { - return _exchangeSpecification.IsAutoDelete; - } - } + internal bool IsAutoDelete => _exchangeSpecification.IsAutoDelete; - internal Dictionary ExchangeArguments - { - get - { - return _exchangeSpecification.ExchangeArguments; - } - } + internal Dictionary ExchangeArguments => _exchangeSpecification.ExchangeArguments; } internal class BindingSpec @@ -206,52 +158,16 @@ internal BindingSpec(IBindingSpecification bindingSpecification) _bindingSpecification = bindingSpecification; } - internal string SourceExchangeName - { - get - { - return _bindingSpecification.SourceExchangeName; - } - } + internal string SourceExchangeName => _bindingSpecification.SourceExchangeName; - internal string DestinationExchangeName - { - get - { - return _bindingSpecification.DestinationExchangeName; - } - } + internal string DestinationExchangeName => _bindingSpecification.DestinationExchangeName; - internal string DestinationQueueName - { - get - { - return _bindingSpecification.DestinationQueueName; - } - } + internal string DestinationQueueName => _bindingSpecification.DestinationQueueName; - internal string BindingKey - { - get - { - return _bindingSpecification.BindingKey; - } - } + internal string BindingKey => _bindingSpecification.BindingKey; - internal Dictionary BindingArguments - { - get - { - return _bindingSpecification.BindingArguments; - } - } + internal Dictionary BindingArguments => _bindingSpecification.BindingArguments; - internal string BindingPath - { - get - { - return _bindingSpecification.BindingPath; - } - } + internal string BindingPath => _bindingSpecification.BindingPath; } } diff --git a/RabbitMQ.AMQP.Client/PublicAPI.Unshipped.txt b/RabbitMQ.AMQP.Client/PublicAPI.Unshipped.txt index 46998d31..7b1dc1a5 100644 --- a/RabbitMQ.AMQP.Client/PublicAPI.Unshipped.txt +++ b/RabbitMQ.AMQP.Client/PublicAPI.Unshipped.txt @@ -5,6 +5,7 @@ const RabbitMQ.AMQP.Client.Impl.Consts.Bindings = "bindings" -> string! const RabbitMQ.AMQP.Client.Impl.Consts.DefaultMaxFrameSize = 0 -> uint const RabbitMQ.AMQP.Client.Impl.Consts.Exchanges = "exchanges" -> string! const RabbitMQ.AMQP.Client.Impl.Consts.Key = "key" -> string! +const RabbitMQ.AMQP.Client.Impl.Consts.Messages = "messages" -> string! const RabbitMQ.AMQP.Client.Impl.Consts.Queues = "queues" -> string! override RabbitMQ.AMQP.Client.Error.ToString() -> string! override RabbitMQ.AMQP.Client.Impl.AmqpConnection.CloseAsync() -> System.Threading.Tasks.Task! @@ -28,6 +29,8 @@ override RabbitMQ.AMQP.Client.Impl.ListenerStreamOptions.Builder() -> RabbitMQ.A override RabbitMQ.AMQP.Client.Impl.RecoveryConfiguration.ToString() -> string! override RabbitMQ.AMQP.Client.SaslMechanism.Equals(object? obj) -> bool override RabbitMQ.AMQP.Client.SaslMechanism.GetHashCode() -> int +RabbitMQ.AMQP.Client.BadRequestException +RabbitMQ.AMQP.Client.BadRequestException.BadRequestException(string! message) -> void RabbitMQ.AMQP.Client.ByteCapacity RabbitMQ.AMQP.Client.ByteCapacity.Equals(RabbitMQ.AMQP.Client.ByteCapacity? other) -> bool RabbitMQ.AMQP.Client.ByteCapacity.ToBytes() -> long @@ -319,6 +322,7 @@ RabbitMQ.AMQP.Client.Impl.AmqpQueueSpecification.MaxLengthBytes(RabbitMQ.AMQP.Cl RabbitMQ.AMQP.Client.Impl.AmqpQueueSpecification.MessageTtl(System.TimeSpan ttl) -> RabbitMQ.AMQP.Client.IQueueSpecification! RabbitMQ.AMQP.Client.Impl.AmqpQueueSpecification.Name(string! queueName) -> RabbitMQ.AMQP.Client.IQueueSpecification! RabbitMQ.AMQP.Client.Impl.AmqpQueueSpecification.OverflowStrategy(RabbitMQ.AMQP.Client.OverFlowStrategy overflow) -> RabbitMQ.AMQP.Client.IQueueSpecification! +RabbitMQ.AMQP.Client.Impl.AmqpQueueSpecification.PurgeAsync() -> System.Threading.Tasks.Task! RabbitMQ.AMQP.Client.Impl.AmqpQueueSpecification.QueueArguments.get -> System.Collections.Generic.Dictionary! RabbitMQ.AMQP.Client.Impl.AmqpQueueSpecification.QueueName.get -> string! RabbitMQ.AMQP.Client.Impl.AmqpQueueSpecification.QueueType.get -> RabbitMQ.AMQP.Client.QueueType @@ -476,6 +480,7 @@ RabbitMQ.AMQP.Client.IQueueSpecification.MaxLengthBytes(RabbitMQ.AMQP.Client.Byt RabbitMQ.AMQP.Client.IQueueSpecification.MessageTtl(System.TimeSpan ttl) -> RabbitMQ.AMQP.Client.IQueueSpecification! RabbitMQ.AMQP.Client.IQueueSpecification.Name(string! queueName) -> RabbitMQ.AMQP.Client.IQueueSpecification! RabbitMQ.AMQP.Client.IQueueSpecification.OverflowStrategy(RabbitMQ.AMQP.Client.OverFlowStrategy overflow) -> RabbitMQ.AMQP.Client.IQueueSpecification! +RabbitMQ.AMQP.Client.IQueueSpecification.PurgeAsync() -> System.Threading.Tasks.Task! RabbitMQ.AMQP.Client.IQueueSpecification.QueueArguments.get -> System.Collections.Generic.Dictionary! RabbitMQ.AMQP.Client.IQueueSpecification.QueueName.get -> string! RabbitMQ.AMQP.Client.IQueueSpecification.QueueType.get -> RabbitMQ.AMQP.Client.QueueType diff --git a/Tests/ConnectionRecoveryTests.cs b/Tests/ConnectionRecoveryTests.cs index a9cfd71a..5b30a8cd 100644 --- a/Tests/ConnectionRecoveryTests.cs +++ b/Tests/ConnectionRecoveryTests.cs @@ -303,7 +303,6 @@ public async Task RecoveryTopologyShouldNotRecoverTheTempQueues() await management.Queue().Name(queueName).AutoDelete(true).Exclusive(true).DeclareAsync(); Assert.Equal(1, topologyListener.QueueCount()); - await SystemUtils.WaitUntilConnectionIsKilled(containerId); await oneRecoveryEventSeenTcs.Task.WaitAsync(TimeSpan.FromSeconds(10)); @@ -494,7 +493,6 @@ await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync("e-remove-a await SystemUtils.WaitUntilBindingsBetweenExchangeAndQueueExistAsync("e-remove-a-should-remove-binding", "q-remove-a-should-remove-binding-wont-delete"); - Assert.Equal(20, topologyListener.BindingCount()); await queueSpec.DeleteAsync(); diff --git a/Tests/Consumer/BasicConsumerTests.cs b/Tests/Consumer/BasicConsumerTests.cs index 40528b14..e4d88d1e 100644 --- a/Tests/Consumer/BasicConsumerTests.cs +++ b/Tests/Consumer/BasicConsumerTests.cs @@ -212,7 +212,6 @@ public async Task ConsumerForStreamQueueWithOffset(StreamOffsetSpecification off consumer.Dispose(); } - /// /// Test for stream filtering /// There are two consumers: diff --git a/Tests/Consumer/ConsumerOutcomeTests.cs b/Tests/Consumer/ConsumerOutcomeTests.cs index 06df52be..9ebe0a5e 100644 --- a/Tests/Consumer/ConsumerOutcomeTests.cs +++ b/Tests/Consumer/ConsumerOutcomeTests.cs @@ -30,7 +30,6 @@ public void ValidateAnnotations() Utils.ValidateMessageAnnotations(new Dictionary { { correctAnnotationKey, annotationValue } }); } - /// /// The test verifies that a requeued message with annotations will contain the annotations on redelivery. /// The delivered message should contain the custom annotations and x-delivery-count @@ -51,7 +50,6 @@ public async Task RequeuedMessageWithAnnotationShouldContainAnnotationsOnRedeliv int requeueCount = 0; - await _management.Queue().Type(QueueType.QUORUM).Name(_queueName).DeclareAsync(); List messages = []; IPublisher publisher = await _connection.PublisherBuilder().Queue(_queueName).BuildAsync(); @@ -142,12 +140,9 @@ public async Task DiscardedMessageWithAnnotationsShouldBeDeadLeadLetteredAndCont Queue q1 = await client.GetQueueAsync(dlqQueueName); Assert.Equal(0, q1.Messages); - - await dlConsumer.CloseAsync(); } - private async Task DeclareDeadLetterTopology(string queueName, string dlxQueueName) { string dlx = $"{queueName}.dlx"; diff --git a/Tests/Consumer/StreamConsumerTests.cs b/Tests/Consumer/StreamConsumerTests.cs index d61d2da8..a8fbe7d7 100644 --- a/Tests/Consumer/StreamConsumerTests.cs +++ b/Tests/Consumer/StreamConsumerTests.cs @@ -53,7 +53,6 @@ public async Task StreamConsumerBuilderShouldRestartFromTheBeginning() await consumer.CloseAsync(); } - /// /// This is a standard case for the stream consumer with SubscriptionListener /// The consumer should start from the offset 5 and consume 5 messages diff --git a/Tests/EnvironmentTests.cs b/Tests/EnvironmentTests.cs index 902eae51..cd06d5f6 100644 --- a/Tests/EnvironmentTests.cs +++ b/Tests/EnvironmentTests.cs @@ -62,7 +62,6 @@ public async Task CloseConnectionsIndividually() Assert.Single(env.GetConnections()); Assert.Equal(1, env.GetConnections()[0].Id); - string envConnectionName2 = "EnvironmentConnection2_" + Guid.NewGuid().ToString(); IConnection connection2 = await env.CreateConnectionAsync( ConnectionSettingBuilder.Create().ContainerId(envConnectionName2).Build()); @@ -88,12 +87,10 @@ public async Task CloseConnectionsIndividually() Assert.Single(env.GetConnections()); await SystemUtils.WaitUntilConnectionIsClosed(envConnectionName2); - await connection3.CloseAsync(); Assert.Equal(State.Closed, connection3.State); await SystemUtils.WaitUntilConnectionIsClosed(envConnectionName3); - Assert.Empty(env.GetConnections()); await env.CloseAsync(); } diff --git a/Tests/Management/ManagementTests.cs b/Tests/Management/ManagementTests.cs index 42b4df57..05ab87f1 100644 --- a/Tests/Management/ManagementTests.cs +++ b/Tests/Management/ManagementTests.cs @@ -215,18 +215,21 @@ public async Task DeclareQueueWithUnsupportedArgument() IQueueSpecification queueSpecification0 = _management.Queue(_queueName).Type(QueueType.CLASSIC); Dictionary queueSpec0Args = queueSpecification0.QueueArguments; queueSpec0Args.Add("x-max-age", "1000s"); - PreconditionFailedException pex0 = await Assert.ThrowsAsync(queueSpecification0.DeclareAsync); + PreconditionFailedException pex0 = + await Assert.ThrowsAsync(queueSpecification0.DeclareAsync); Assert.Contains("409", pex0.Message); IQueueSpecification queueSpecification1 = _management.Queue(_queueName).Type(QueueType.QUORUM); Dictionary queueSpec1Args = queueSpecification1.QueueArguments; queueSpec1Args.Add("x-max-age", "1000s"); - PreconditionFailedException pex1 = await Assert.ThrowsAsync(queueSpecification1.DeclareAsync); + PreconditionFailedException pex1 = + await Assert.ThrowsAsync(queueSpecification1.DeclareAsync); Assert.Contains("409", pex1.Message); IQueueSpecification queueSpecification2 = _management.Queue(_queueName).Type(QueueType.STREAM); queueSpecification2.DeadLetterRoutingKey("not-supported"); - PreconditionFailedException pex2 = await Assert.ThrowsAsync(queueSpecification2.DeclareAsync); + PreconditionFailedException pex2 = + await Assert.ThrowsAsync(queueSpecification2.DeclareAsync); Assert.Contains("409", pex2.Message); } @@ -298,7 +301,8 @@ public async Task ExchangeWithEmptyNameShouldRaiseAnException() Assert.NotNull(_connection); Assert.NotNull(_management); - await Assert.ThrowsAsync(() => _management.Exchange("").Type(ExchangeType.TOPIC).DeclareAsync()); + await Assert.ThrowsAsync(() => + _management.Exchange("").Type(ExchangeType.TOPIC).DeclareAsync()); } [Fact] @@ -307,11 +311,13 @@ public async Task RedeclareExchangeWithSameArgs() Assert.NotNull(_connection); Assert.NotNull(_management); - IExchangeSpecification exchangeSpec0 = _management.Exchange(_exchangeName).AutoDelete(true).Argument("my_key", "my _value"); + IExchangeSpecification exchangeSpec0 = + _management.Exchange(_exchangeName).AutoDelete(true).Argument("my_key", "my _value"); await exchangeSpec0.DeclareAsync(); // Second re-declare - IExchangeSpecification exchangeSpec1 = _management.Exchange(_exchangeName).AutoDelete(true).Argument("my_key", "my _value"); + IExchangeSpecification exchangeSpec1 = + _management.Exchange(_exchangeName).AutoDelete(true).Argument("my_key", "my _value"); await exchangeSpec1.DeclareAsync(); await SystemUtils.WaitUntilExchangeExistsAsync(exchangeSpec0); @@ -331,7 +337,8 @@ public async Task RedeclareExchangeWithDifferentArgs() IExchangeSpecification exchangeSpec1 = _management.Exchange(_exchangeName).Type(ExchangeType.FANOUT); - PreconditionFailedException pfex = await Assert.ThrowsAsync(exchangeSpec1.DeclareAsync); + PreconditionFailedException pfex = + await Assert.ThrowsAsync(exchangeSpec1.DeclareAsync); await exchangeSpec0.DeleteAsync(); await SystemUtils.WaitUntilExchangeDeletedAsync(exchangeSpec0); @@ -390,4 +397,34 @@ public async Task TopologyCountShouldFollowTheQueueDeclaration() queueSpecs.Clear(); } + + [Theory] + [InlineData(QueueType.QUORUM)] + [InlineData(QueueType.CLASSIC)] + public async Task PurgeQueueShouldReturnTheCorrectNumberOfMessagesPurged(QueueType queueType) + { + Assert.NotNull(_connection); + Assert.NotNull(_management); + + IQueueSpecification queueSpec = _management.Queue().Name(_queueName).Type(queueType); + await queueSpec.DeclareAsync(); + await PublishAsync(queueSpec, 19); + await SystemUtils.WaitUntilQueueMessageCount(_queueName, 19); + ulong deleted = await queueSpec.PurgeAsync(); + Assert.Equal((ulong)19, deleted); + await SystemUtils.WaitUntilQueueMessageCount(_queueName, 0); + } + + [Fact] + public async Task PurgeQueueShouldReturnErrorForStream() + { + Assert.NotNull(_connection); + Assert.NotNull(_management); + + IQueueSpecification queueSpec = _management.Queue().Name(_queueName).Type(QueueType.STREAM); + await queueSpec.DeclareAsync(); + await PublishAsync(queueSpec, 19); + await SystemUtils.WaitUntilQueueMessageCount(_queueName, 19); + await Assert.ThrowsAsync(() => queueSpec.PurgeAsync()); + } } diff --git a/Tests/PublisherTests.cs b/Tests/PublisherTests.cs index 4216ff65..81b0395c 100644 --- a/Tests/PublisherTests.cs +++ b/Tests/PublisherTests.cs @@ -84,7 +84,6 @@ public async Task SendAMessageToAQueue() Assert.Empty(_connection.GetPublishers()); } - [Fact] public async Task ValidatePublishersCount() { diff --git a/Tests/Recovery/PublisherConsumerRecoveryTests.cs b/Tests/Recovery/PublisherConsumerRecoveryTests.cs index 3e8214bd..0baec642 100644 --- a/Tests/Recovery/PublisherConsumerRecoveryTests.cs +++ b/Tests/Recovery/PublisherConsumerRecoveryTests.cs @@ -51,7 +51,6 @@ public async Task ProducerShouldChangeStatusWhenClosed() publisher.Dispose(); } - /// /// Test the Simple case where the consumer is closed and the status is changed /// diff --git a/docs/Examples/GettingStarted/Program.cs b/docs/Examples/GettingStarted/Program.cs index 81ebf6d3..fa683ca5 100644 --- a/docs/Examples/GettingStarted/Program.cs +++ b/docs/Examples/GettingStarted/Program.cs @@ -24,7 +24,6 @@ Trace.WriteLine(TraceLevel.Information, $"Connected to the broker {connection} successfully"); - // ------------------------------------------------------------------------------------ // The management object is used to declare/delete queues, exchanges, and bindings IManagement management = connection.Management(); @@ -45,7 +44,6 @@ $"Queue {queueName} and Exchange {exchangeName} declared and bound with key {routingKey} successfully"); // ------------------------------------------------------------------------------------ - // ------------------------------------------------------------------------------------ // Declare a publisher and a consumer. // The publisher can use exchange (optionally with a key) or queue to publish messages. @@ -75,7 +73,6 @@ Trace.WriteLine(TraceLevel.Information, $"[Publisher] Message: {message.Body()} Released"); break; - case OutcomeState.Rejected: Trace.WriteLine(TraceLevel.Error, $"[Publisher] Message: {message.Body()} Rejected with error: {pr.Outcome.Error}"); diff --git a/docs/Examples/HAClient/Program.cs b/docs/Examples/HAClient/Program.cs index a9de2a18..407a5de9 100644 --- a/docs/Examples/HAClient/Program.cs +++ b/docs/Examples/HAClient/Program.cs @@ -20,7 +20,6 @@ const int totalMessagesToSend = 5_000_000; - Task printStats = Task.Run(() => { while (true) @@ -34,7 +33,6 @@ } }); - Trace.WriteLine(TraceLevel.Information, "Starting"); const string containerId = "HA-Client-Connection"; @@ -74,7 +72,6 @@ } }; - IConsumer consumer = await connection.ConsumerBuilder().Queue(queueName).InitialCredits(100).MessageHandler((context, message) => { Interlocked.Increment(ref messagesReceived); diff --git a/docs/Examples/PerformanceTest/Program.cs b/docs/Examples/PerformanceTest/Program.cs index 2b5477c9..2fbcf925 100644 --- a/docs/Examples/PerformanceTest/Program.cs +++ b/docs/Examples/PerformanceTest/Program.cs @@ -15,7 +15,6 @@ bool enableConsumer = true; // ----------------------- - Trace.TraceLevel = TraceLevel.Verbose; ConsoleTraceListener consoleListener = new(); @@ -59,7 +58,6 @@ async Task MessageHandler(IContext context, IMessage message) .BuildAndStartAsync(); } - stats.Start(); _ = Task.Run(async () => { diff --git a/docs/Examples/PerformanceTest/Stats.cs b/docs/Examples/PerformanceTest/Stats.cs index 37cee2a0..95460dad 100644 --- a/docs/Examples/PerformanceTest/Stats.cs +++ b/docs/Examples/PerformanceTest/Stats.cs @@ -34,26 +34,13 @@ public bool IsRunning() return _isRunning; } + public long Consumed => Interlocked.Read(ref _consumed); - public long Consumed - { - get => Interlocked.Read(ref _consumed); - } + public long Published => Interlocked.Read(ref _published); - public long Published - { - get => Interlocked.Read(ref _published); - } + public long Failed => Interlocked.Read(ref _failed); - public long Failed - { - get => Interlocked.Read(ref _failed); - } - - public long Accepted - { - get => Interlocked.Read(ref _accepted); - } + public long Accepted => Interlocked.Read(ref _accepted); public void IncrementConsumed() { @@ -80,7 +67,6 @@ public double AcceptedPerSeconds() return Accepted / (_end - _start).TotalSeconds; } - public double ConsumedPerSeconds() { return Consumed / (_end - _start).TotalSeconds; @@ -91,7 +77,6 @@ public double PublishedPerSeconds() return Published / (_end - _start).TotalSeconds; } - public string Report(bool full = false) { if (_isRunning) diff --git a/rabbitmq-amqp-dotnet-client.sln b/rabbitmq-amqp-dotnet-client.sln index b71715f9..7c5450b4 100644 --- a/rabbitmq-amqp-dotnet-client.sln +++ b/rabbitmq-amqp-dotnet-client.sln @@ -11,11 +11,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GettingStarted", "docs/Exam EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9A316218-49D6-42B4-A64C-8B52AD8C9E4F}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + .gitignore = .gitignore Build.csproj = Build.csproj build.ps1 = build.ps1 Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets Directory.Packages.props = Directory.Packages.props + docfx.json = docfx.json + Makefile = Makefile README.md = README.md EndProjectSection EndProject