Skip to content

Commit

Permalink
Merge pull request #30 from uniteeio/feature/v10
Browse files Browse the repository at this point in the history
v10
  • Loading branch information
titouancreach authored Jul 7, 2023
2 parents 6bd5ad6 + 08209b6 commit 1d8aebd
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 464 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ For now, we mainly focus on Redis as an event store because:
- Scheduling messages
- Treat pending messages at start
- Recurring task (cron)
- Localized messages

# How to use

Expand Down Expand Up @@ -144,13 +145,15 @@ services.AddTransient<IConsumer, UserRegisteredConsumer>();

All consumers should be added using `AddTransient`. So, they all have their own scope since they are executed concurrently.

If you want to your consumer to be able to reply, then, implement `IRedisStreamConsumerWithContext<TRequest, TResponse>` instead.
If you want to your consumer to be able to reply or access metadata of the message, then, implement `IRedisStreamConsumerWithContext<TRequest, TResponse>` instead.

```csharp
public class UserRegisteredConsumer : IRedisStreamConsumeWithContext<UserRegistered, MyResponse>
public class UserRegisteredConsumer : IRedisStreamConsumeWithContext<UserRegistered, MyResponse> // Use object or anything if you didn't plan to respond to the message.
{
public async Task ConsumeAsync(UserRegistered message, IRedisStreamMessageContext context)
{
_logger.LogInformation(context.Locale);

await _email.Send(message.Email);

await context.ReplyAsync(new MyResponse());
Expand Down
5 changes: 3 additions & 2 deletions Unitee.EventDriven.Abstraction/Abstractions/IConsumer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Unitee.EventDriven.Abstraction;

/// <summary>
/// Juste pour pouvoir récupérer la liste de tous les consumers depuis l'injection de dépendances.
/// Ne doit jamais être implémenté directement sans passer par IConsummer<T>.
/// Used to mark a class as a consumer.
/// Should never be implemented directly without passing through IConsummer<T> / IConsumerWithContext<T> or IConsumerWithMetadata<T, TMetadata>
/// </summary>
public interface IConsumer { }

Expand All @@ -15,3 +15,4 @@ public interface IConsumer<T> : IConsumer
{
public Task ConsumeAsync(T message);
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ namespace Unitee.EventDriven.Abstraction;
public interface IMessageContext<TReturn>
{
public Task<TReturn> ReplyAsync<TMessage>(TMessage message);
}
}
11 changes: 8 additions & 3 deletions Unitee.EventDriven.Abstraction/Abstractions/IMessageHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
namespace Unitee.EventDriven.Abstraction;


///
/// <summary>
/// Used for Azure Service Bus messages only
/// </summary>
public interface IMessageHandler<T>
{
/// <summary>
/// Appelle le bon consumer enregistré pour le message de type T
/// Route to the right consumer.
/// </summary>
/// <returns>
/// True si un consumer a été trouvé et appelé, false sinon.
/// True if the message was handled, false otherwise.
/// </returns>
public Task<bool> HandleAsync(T originalMessage);
}
}
4 changes: 3 additions & 1 deletion Unitee.EventDriven.Abstraction/Model/MessageOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public record MessageOptions()
public DateTimeOffset? ScheduledEnqueueTime { get; init; }
public string? MessageId { get; init; }
public string? SessionId { get; set; }
}
public DateTimeOffset? ExpireAt { get; init; }
public string? Locale { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.15.0" />
<PackageReference Include="CSharpFunctionalExtensions" Version="2.40.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
Expand Down
4 changes: 3 additions & 1 deletion Unitee.EventDriven.RedisStream.Tests.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"path": "Unitee.EventDriven.RedisStream"
}
],
"settings": {}
"settings": {
"dotnet.defaultSolution": "/Users/tcreach/Documents/Projects/Unitee.EventDriven/Unitee.EventDriven.RedisStream.Tests/Unitee.EventDriven.RedisStream.Tests.sln"
}
}
Loading

0 comments on commit 1d8aebd

Please sign in to comment.