Skip to content

Commit 73653a9

Browse files
authored
Publisher first version (#9)
* Publisher First version --------- Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent 7a43277 commit 73653a9

31 files changed

+997
-164
lines changed

Directory.Packages.props

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<!-- RabbitMQ.Amqp.Client -->
7-
<PackageVersion Include="AMQPNetLite.Core" Version="2.4.10" />
7+
<PackageVersion Include="AMQPNetLite.Core" Version="2.4.11" />
88
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
99
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
1010
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
@@ -17,4 +17,16 @@
1717
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
1818
<!-- docs/**/*.csproj -->
1919
</ItemGroup>
20+
<ItemGroup Label=".NET 6 Specific" Condition="'$(TargetFramework)' == 'net6.0'">
21+
<!-- RabbitMQ.Amqp.Client -->
22+
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
23+
</ItemGroup>
24+
<ItemGroup Label=".NET 7 Specific" Condition="'$(TargetFramework)' == 'net7.0'">
25+
<!-- RabbitMQ.Amqp.Client -->
26+
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="7.0.0" />
27+
</ItemGroup>
28+
<ItemGroup Label=".NET 8 Specific" Condition="'$(TargetFramework)' == 'net8.0'">
29+
<!-- RabbitMQ.Amqp.Client -->
30+
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
31+
</ItemGroup>
2032
</Project>

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,28 @@
44
This library is in early stages of development.
55
It is meant to be used with RabbitMQ 4.0.
66

7+
## How to Run
8+
- start the broker with `ci/start-broker.sh`
9+
- run the tests with ` dotnet test ./Build.csproj --logger "console;verbosity=detailed" /p:AltCover=true`
710

11+
## Getting Started
12+
You can find an example in: `docs/Examples/GettingStarted`
13+
14+
15+
## TODO
16+
17+
- [x] Declare queues
18+
- [ ] Declare exchanges
19+
- [ ] Declare bindings
20+
- [x] Simple Publish messages
21+
- [x] Implement backpressure ( atm it is implemented with MaxInflightMessages `MaxInFlight(2000).`)
22+
- [ ] Simple Consume messages
23+
- [ ] Implement metrics ( See `System.Diagnostics.DiagnosticSource` [Link](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/metrics-instrumentation) )
24+
- [x] Recovery connection on connection lost
25+
- [x] Recovery management on connection lost
26+
- [x] Recovery queues on connection lost
27+
- [ ] Recovery publisher on connection lost
28+
- [ ] Recovery consumer on connection lost
29+
- [ ] Docker image to test in LRE
30+
- [ ] Check the TODO in the code
831

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace RabbitMQ.AMQP.Client;
2+
3+
public class InvalidAddressException(string message) : Exception(message);
4+
5+
public interface IAddressBuilder<out T>
6+
{
7+
8+
T Exchange(string exchange);
9+
10+
T Queue(string queue);
11+
12+
T Key(string key);
13+
}

RabbitMQ.AMQP.Client/IClosable.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ public enum State
99
Closed,
1010
}
1111

12-
public class Error
12+
public class Error(string? errorCode, string? description)
1313
{
14-
public string? Description { get; internal set; }
15-
public string? ErrorCode { get; internal set; }
14+
public string? Description { get; } = description;
15+
public string? ErrorCode { get; } = errorCode;
16+
17+
public override string ToString()
18+
{
19+
return $"Code: {ErrorCode} - Description: {Description}";
20+
}
1621
}
1722

18-
public interface IClosable
23+
public interface IClosable // TODO: Create an abstract class with the event and the State property
1924
{
20-
public State State { get; }
25+
public State State { get; }
2126

2227
Task CloseAsync();
2328

RabbitMQ.AMQP.Client/IConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace RabbitMQ.AMQP.Client;
22

3-
public class ConnectionException(string? message, Exception? innerException) : Exception(message, innerException);
3+
public class ConnectionException(string? message) : Exception(message);
44

5-
public interface IConnection : IClosable
5+
public interface IConnection
66
{
77
IManagement Management();
88
Task ConnectAsync();

RabbitMQ.AMQP.Client/IEntities.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public interface IQueueSpecification : IEntityDeclaration<IQueueInfo>
2626
IQueueSpecification Arguments(Dictionary<object, object> arguments);
2727

2828
public Dictionary<object, object> Arguments();
29-
29+
3030
IQueueSpecification Type(QueueType type);
31-
31+
3232
public QueueType Type();
33-
33+
3434
// IQuorumQueueSpecification Quorum();
3535
}
3636

RabbitMQ.AMQP.Client/IManagement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface IManagement : IClosable
1010
IQueueSpecification Queue(string name);
1111

1212
IQueueDeletion QueueDeletion();
13-
13+
1414
ITopologyListener TopologyListener();
1515
}
1616

RabbitMQ.AMQP.Client/IMessage.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ namespace RabbitMQ.AMQP.Client;
22

33
public interface IMessage
44
{
5-
IMessage Body(object body);
6-
object Body();
7-
5+
public object Body();
86
// properties
97
string MessageId();
108
IMessage MessageId(string id);

RabbitMQ.AMQP.Client/IPublisher.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace RabbitMQ.AMQP.Client;
2+
3+
public class PublisherException(string message) : Exception(message);
4+
5+
public enum OutcomeState
6+
{
7+
Accepted,
8+
Failed,
9+
}
10+
11+
public class OutcomeDescriptor(ulong code, string description, OutcomeState state, Error? error)
12+
{
13+
public OutcomeState State { get; internal set; } = state;
14+
public ulong Code { get; internal set; } = code;
15+
public string Description { get; internal set; } = description;
16+
17+
public Error? Error { get; internal set; } = error;
18+
}
19+
20+
public delegate void OutcomeDescriptorCallback(IMessage message, OutcomeDescriptor outcomeDescriptor);
21+
22+
public interface IPublisher : IClosable
23+
{
24+
Task Publish(IMessage message,
25+
OutcomeDescriptorCallback outcomeCallback); // TODO: Add CancellationToken and callBack
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace RabbitMQ.AMQP.Client;
2+
3+
public interface IPublisherBuilder : IAddressBuilder<IPublisherBuilder>
4+
{
5+
IPublisherBuilder PublishTimeout(TimeSpan timeout);
6+
7+
IPublisherBuilder MaxInflightMessages(int maxInFlight);
8+
IPublisher Build();
9+
}

0 commit comments

Comments
 (0)