Skip to content

Commit 7b49427

Browse files
authored
Document outcome (#69)
Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent ef798d3 commit 7b49427

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

RabbitMQ.AMQP.Client/IPublisher.cs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,54 @@ public PublisherException(string message) : base(message)
1515
}
1616
}
1717

18+
/// <summary>
19+
/// Represents the status of a publish operation.
20+
/// Accepted: The message was accepted for publication.
21+
/// Rejected: The message was rejected by the broker.
22+
/// Released: The message was released by the broker.
23+
/// </summary>
1824
public enum OutcomeState
1925
{
2026
Accepted,
2127
Rejected,
2228
Released,
2329
}
30+
31+
/// <summary>
32+
/// PublishOutcome represents the outcome of a publish operation.
33+
/// It contains the state of the outcome and an error if the outcome is not successful.
34+
/// </summary>
2435

2536
public class PublishOutcome
2637
{
27-
private readonly OutcomeState _state;
28-
private readonly Error? _error;
29-
3038
public PublishOutcome(OutcomeState state, Error? error)
3139
{
32-
_state = state;
33-
_error = error;
40+
State = state;
41+
Error = error;
3442
}
3543

36-
public OutcomeState State => _state;
37-
public Error? Error => _error;
44+
public OutcomeState State { get; }
45+
46+
public Error? Error { get; }
3847
}
3948

4049
public class PublishResult
4150
{
42-
private IMessage _message;
43-
private PublishOutcome _outcome;
44-
4551
public PublishResult(IMessage message, PublishOutcome outcome)
4652
{
47-
_message = message;
48-
_outcome = outcome;
53+
Message = message;
54+
Outcome = outcome;
4955
}
5056

51-
public IMessage Message => _message;
52-
public PublishOutcome Outcome => _outcome;
57+
public IMessage Message { get; }
58+
59+
public PublishOutcome Outcome { get; }
5360
}
5461

62+
/// <summary>
63+
/// Interface for publishing messages to an AMQP broker.
64+
/// Implementations of this interface are expected to be thread-safe.
65+
/// </summary>
5566
public interface IPublisher : ILifeCycle
5667
{
5768
Task<PublishResult> PublishAsync(IMessage message, CancellationToken cancellationToken = default);

RabbitMQ.AMQP.Client/Impl/AmqpPublisher.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@ await base.OpenAsync()
9999
}
100100
}
101101

102-
// TODO: Consider implementing this method with the send method
103-
// a way to send a batch of messages
104-
105-
// protected override async Task<int> ExecuteAsync(SenderLink link)
106-
// {
107-
// int batch = this.random.Next(1, this.role.Args.Batch);
108-
// Message[] messages = CreateMessages(this.id, this.total, batch);
109-
// await Task.WhenAll(messages.Select(m => link.SendAsync(m)));
110-
// this.total += batch;
111-
// return batch;
112-
// }
113-
102+
103+
/// <summary>
104+
/// Publishes a message to the broker in an asynchronous manner.
105+
/// The PublishResult is synchronous. In order to increase the performance
106+
/// you can use more tasks to publish messages in parallel
107+
/// </summary>
108+
/// <param name="message"></param>
109+
/// <param name="cancellationToken"></param>
110+
/// <returns></returns>
111+
/// <exception cref="InvalidOperationException"></exception>
112+
/// <exception cref="NotSupportedException"></exception>
113+
/// <exception cref="PublisherException"></exception>
114114
public async Task<PublishResult> PublishAsync(IMessage message, CancellationToken cancellationToken = default)
115115
{
116116
ThrowIfClosed();

docs/Examples/GettingStarted/Program.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@
7171
case OutcomeState.Accepted:
7272
Trace.WriteLine(TraceLevel.Information, $"[Publisher] Message: {message.Body()} confirmed");
7373
break;
74+
case OutcomeState.Released:
75+
Trace.WriteLine(TraceLevel.Information, $"[Publisher] Message: {message.Body()} Released");
76+
break;
77+
78+
7479
case OutcomeState.Rejected:
7580
Trace.WriteLine(TraceLevel.Error,
76-
$"outcome result, state: {pr.Outcome.State}, message_id: " +
77-
$"{message.MessageId()}, error: {pr.Outcome.Error}");
81+
$"[Publisher] Message: {message.Body()} Rejected with error: {pr.Outcome.Error}");
7882
break;
7983
default:
8084
throw new ArgumentOutOfRangeException();

0 commit comments

Comments
 (0)