Skip to content

Commit 670aac4

Browse files
committed
Add XML doc to IConsumer and related entities.
Follow-up to #105.
1 parent ad3f4a4 commit 670aac4

File tree

5 files changed

+112
-52
lines changed

5 files changed

+112
-52
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This source code is dual-licensed under the Apache License, version 2.0,
2+
// and the Mozilla Public License, version 2.0.
3+
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
5+
using System;
6+
7+
namespace RabbitMQ.AMQP.Client
8+
{
9+
/// <summary>
10+
/// Exception returned during consumer operations. See <see cref="IConsumer"/>.
11+
/// </summary>
12+
public class ConsumerException : Exception
13+
{
14+
public ConsumerException(string message) : base(message)
15+
{
16+
}
17+
}
18+
}

RabbitMQ.AMQP.Client/IConsumer.cs

+72-47
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,82 @@
22
// and the Mozilla Public License, version 2.0.
33
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
44

5-
using System;
65
using System.Collections.Generic;
76
using System.Threading.Tasks;
87

98
namespace RabbitMQ.AMQP.Client
109
{
11-
public class ConsumerException : Exception
12-
{
13-
public ConsumerException(string message) : base(message)
14-
{
15-
}
16-
}
17-
1810
// TODO cancellation token
11+
/// <summary>
12+
/// Delegate to process an incoming message.
13+
/// </summary>
14+
/// <param name="context">The message context.</param>
15+
/// <param name="message">The message itself.</param>
16+
/// <returns><see cref="Task"/> that represents the async operation.</returns>
1917
public delegate Task MessageHandler(IContext context, IMessage message);
2018

19+
/// <summary>
20+
/// <para>API to consume messages from a RabbitMQ queue.</para>
21+
/// <para>Instances are configured and created with a <see cref="IConsumerBuilder"/>.</para>
22+
/// <para>See <see cref="IConnection.ConsumerBuilder()"/> and <see cref="IConsumerBuilder"/>.</para>
23+
/// </summary>
2124
public interface IConsumer : ILifeCycle
2225
{
26+
/// <summary>
27+
/// Pause the consumer to stop receiving messages.
28+
/// </summary>
2329
void Pause();
30+
31+
/// <summary>
32+
/// Request to receive messages again.
33+
/// </summary>
2434
void Unpause();
35+
36+
/// <summary>
37+
/// Returns the number of unsettled messages.
38+
/// </summary>
2539
long UnsettledMessageCount { get; }
2640
}
2741

2842
public interface IContext
2943
{
30-
///<summary>
31-
/// Accept the message (AMQP 1.0 <code>accepted</code> outcome).
32-
///
33-
/// This means the message has been processed and the broker can delete it.
34-
///
44+
/// <summary>
45+
/// <para>Accept the message (AMQP 1.0 <c>accepted</c> outcome).</para>
46+
/// <para>This means the message has been processed and the broker can delete it.</para>
3547
/// </summary>
3648
void Accept();
3749

3850
///<summary>
39-
/// Discard the message (AMQP 1.0 <code>rejected</code> outcome).
40-
///This means the message cannot be processed because it is invalid, the broker can drop it
41-
/// or dead-letter it if it is configured.
51+
/// <para>Discard the message (AMQP 1.0 <c>rejected</c> outcome).</para>
52+
/// <para>
53+
/// This means the message cannot be processed because it is invalid, the broker can
54+
/// drop it or dead-letter it if it is configured.
55+
/// </para>
4256
///</summary>
4357
void Discard();
4458

4559
///<summary>
46-
///Discard the message with annotations to combine with the existing message annotations.
47-
///This means the message cannot be processed because it is invalid, the broker can drop it
48-
///or dead-letter it if it is configured.
49-
///Application-specific annotation keys must start with the <code>x-opt-</code> prefix.
50-
///Annotation keys the broker understands starts with <code>x-</code>, but not with <code>x-opt-
51-
///</code>.
52-
///This maps to the AMQP 1.0 <code>
53-
///modified{delivery-failed = true, undeliverable-here = true}</code> outcome.
54-
/// <param name="annotations"> annotations message annotations to combine with existing ones </param>
55-
///<a
56-
/// href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-modified">AMQP
57-
/// 1.0 <code>modified</code> outcome</a>
58-
///
59-
/// The annotations can be used only with Quorum queues, see https://www.rabbitmq.com/docs/amqp#modified-outcome
60+
/// <para>
61+
/// Discard the message with annotations to combine with the existing message annotations.
62+
/// </para>
63+
/// <para>
64+
/// This means the message cannot be processed because it is invalid, the broker can drop
65+
/// it or dead-letter it if it is configured.
66+
/// </para>
67+
/// <para>
68+
/// Application-specific annotation keys must start with the <c>x-opt-</c> prefix.
69+
/// </para>
70+
/// <para>
71+
/// Annotation keys that the broker understands start with <c>x-</c>, but not with
72+
/// <c>x-opt-</c>. This maps to the AMQP 1.0 <c>modified{delivery-failed = false,
73+
/// undeliverable-here = false}</c> outcome.
74+
/// </para>
75+
/// <para>
76+
/// The annotations can be used only with Quorum queues, see
77+
/// <a href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-modified">
78+
/// AMQP 1.0 <c>modified</c> outcome.</a>
79+
/// </para>
80+
/// <param name="annotations">Message annotations to combine with existing ones.</param>
6081
///</summary>
6182
void Discard(Dictionary<string, object> annotations);
6283

@@ -70,23 +91,27 @@ public interface IContext
7091
void Requeue();
7192

7293
///<summary>
73-
///Requeue the message with annotations to combine with the existing message annotations.
74-
///
75-
///This means the message has not been processed and the broker can requeue it and deliver it
76-
/// to the same or a different consumer.
77-
/// Application-specific annotation keys must start with the <code>x-opt-</code> prefix.
78-
/// Annotation keys the broker understands starts with <code>x-</code>, but not with <code>x-opt-
79-
/// </code>.
80-
///
81-
/// This maps to the AMQP 1.0 <code>
82-
/// modified{delivery-failed = false, undeliverable-here = false}</code> outcome.
83-
///
84-
/// <param name="annotations"> annotations message annotations to combine with existing ones </param>
85-
///<a
86-
/// href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-modified">AMQP
87-
/// 1.0 <code>modified</code> outcome</a>
88-
///
89-
///The annotations can be used only with Quorum queues, see https://www.rabbitmq.com/docs/amqp#modified-outcome
94+
/// <para>
95+
/// Requeue the message with annotations to combine with the existing message annotations.
96+
/// </para>
97+
/// <para>
98+
/// This means the message has not been processed and the broker can requeue it and
99+
/// deliver it to the same or a different consumer.
100+
/// </para>
101+
/// <para>
102+
/// Application-specific annotation keys must start with the <c>x-opt-</c> prefix.
103+
/// </para>
104+
/// <para>
105+
/// Annotation keys that the broker understands start with <c>x-</c>, but not with
106+
/// <c>x-opt-</c>. This maps to the AMQP 1.0 <c>modified{delivery-failed = false,
107+
/// undeliverable-here = false}</c> outcome.
108+
/// </para>
109+
/// <para>
110+
/// The annotations can be used only with Quorum queues, see
111+
/// <a href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-modified">
112+
/// AMQP 1.0 <c>modified</c> outcome.</a>
113+
/// </para>
114+
/// <param name="annotations">Message annotations to combine with existing ones.</param>
90115
///</summary>
91116
void Requeue(Dictionary<string, object> annotations);
92117
}

RabbitMQ.AMQP.Client/Impl/AmqpConsumer.cs

+9
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ await _configuration.Handler(context, amqpMessage)
193193
Trace.WriteLine(TraceLevel.Verbose, $"{ToString()} is closed.");
194194
}
195195

196+
/// <summary>
197+
/// Pause the consumer to stop receiving messages.
198+
/// </summary>
196199
public void Pause()
197200
{
198201
if (_receiverLink is null)
@@ -224,8 +227,14 @@ ref Unsafe.As<PauseStatus, int>(ref _pauseStatus),
224227
}
225228
}
226229

230+
/// <summary>
231+
/// Get the number of unsettled messages.
232+
/// </summary>
227233
public long UnsettledMessageCount => _unsettledMessageCounter.Get();
228234

235+
/// <summary>
236+
/// Request to receive messages again.
237+
/// </summary>
229238
public void Unpause()
230239
{
231240
if (_receiverLink is null)

RabbitMQ.AMQP.Client/Impl/DeliveryContext.cs

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public DeliveryContext(IReceiverLink link, Message message, UnsettledMessageCoun
2424
_metricsReporter = metricsReporter;
2525
}
2626

27+
/// <summary>
28+
/// <para>Accept the message (AMQP 1.0 <c>accepted</c> outcome).</para>
29+
/// <para>This means the message has been processed and the broker can delete it.</para>
30+
/// </summary>
2731
public void Accept()
2832
{
2933
try
@@ -43,6 +47,13 @@ public void Accept()
4347
}
4448
}
4549

50+
///<summary>
51+
/// <para>Discard the message (AMQP 1.0 <c>rejected</c> outcome).</para>
52+
/// <para>
53+
/// This means the message cannot be processed because it is invalid, the broker can
54+
/// drop it or dead-letter it if it is configured.
55+
/// </para>
56+
///</summary>
4657
public void Discard()
4758
{
4859
try

Tests/OAuth2Tests.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
using System.IdentityModel.Tokens.Jwt;
88
using System.Linq;
99
using System.Security.Claims;
10-
using System.Security.Cryptography;
11-
using System.Text;
1210
using System.Threading;
1311
using System.Threading.Tasks;
14-
using Amqp;
1512
using Microsoft.IdentityModel.Tokens;
1613
using RabbitMQ.AMQP.Client;
1714
using RabbitMQ.AMQP.Client.Impl;
@@ -55,7 +52,7 @@ public async Task RefreshTokenShouldNotDisconnectTheClient()
5552
.OAuth2Options(new OAuth2Options(GenerateToken(DateTime.UtcNow.AddMilliseconds(1_000))))
5653
.Build());
5754
await connection.RefreshTokenAsync(GenerateToken(DateTime.UtcNow.AddMinutes(5)));
58-
Thread.Sleep(TimeSpan.FromSeconds(1));
55+
await Task.Delay(TimeSpan.FromSeconds(1));
5956
Assert.NotNull(connection);
6057
Assert.Equal(State.Open, connection.State);
6158
await connection.CloseAsync();
@@ -131,7 +128,7 @@ public async Task ConnectionShouldReconnectWithTheNewToken()
131128
};
132129

133130
Assert.Equal(State.Open, connection.State);
134-
Thread.Sleep(TimeSpan.FromSeconds(1));
131+
await Task.Delay(TimeSpan.FromSeconds(1));
135132
await WaitUntilConnectionIsKilledAndOpen(_containerId);
136133
Assert.Equal(State.Open, connection.State);
137134
await WhenTcsCompletes(twoRecoveryEventsSeenTcs);

0 commit comments

Comments
 (0)