-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More samples and working stream middleware
- Loading branch information
Showing
22 changed files
with
309 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Sample.Contracts; | ||
|
||
public record AutoRefreshRequest : IStreamRequest<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Sample.Contracts; | ||
|
||
public record CachedRequest : IRequest<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Sample.Contracts; | ||
|
||
public record ResilientRequest : IRequest<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Runtime.CompilerServices; | ||
using Sample.Contracts; | ||
|
||
namespace Sample.Handlers; | ||
|
||
[RegisterHandler] | ||
public class AutoRefreshStreamRequestHandler : IStreamRequestHandler<AutoRefreshRequest, string> | ||
{ | ||
[TimerRefresh(3000)] | ||
public async IAsyncEnumerable<string> Handle(AutoRefreshRequest request, [EnumeratorCancellation] CancellationToken cancellationToken) | ||
{ | ||
yield return DateTimeOffset.Now.ToString("h:mm:ss tt"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Sample.Contracts; | ||
|
||
namespace Sample.Handlers; | ||
|
||
|
||
[RegisterHandler] | ||
public class CachedRequestHandler : IRequestHandler<CachedRequest, string> | ||
{ | ||
[Cache(MaxAgeSeconds = 20)] | ||
public Task<string> Handle(CachedRequest request, CancellationToken cancellationToken) | ||
{ | ||
var r = DateTimeOffset.UtcNow.ToLocalTime().ToString("h:mm:ss tt"); | ||
return Task.FromResult(r); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
namespace Sample.Handlers; | ||
|
||
public class MyStreamRequestMiddleware<TRequest, TResult> : IStreamRequestMiddleware<TRequest, TResult> where TRequest : IStreamRequest<TResult> | ||
// [RegisterMiddleware] | ||
public class MyStreamRequestMiddleware<TRequest, TResult>(ILogger<MyStreamRequestMiddleware<TRequest, TResult>> logger) : IStreamRequestMiddleware<TRequest, TResult> where TRequest : IStreamRequest<TResult> | ||
{ | ||
public IAsyncEnumerator<TResult> Process( | ||
public IAsyncEnumerable<TResult> Process( | ||
TRequest request, | ||
StreamRequestDelegate<TResult> next, | ||
StreamRequestHandlerDelegate<TResult> next, | ||
IStreamRequestHandler<TRequest, TResult> requestHandler, | ||
CancellationToken cancellationToken | ||
) | ||
{ | ||
logger.LogInformation($"MyStreamRequestMiddleware called for {typeof(TRequest).FullName}"); | ||
return next(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Sample.Contracts; | ||
using Shiny.Mediator.Resilience; | ||
|
||
namespace Sample.Handlers; | ||
|
||
|
||
[RegisterHandler] | ||
public class ResilientRequestHandler : IRequestHandler<ResilientRequest, string> | ||
{ | ||
static bool timeoutRequest; | ||
|
||
[Resilient("test")] | ||
public async Task<string> Handle(ResilientRequest request, CancellationToken cancellationToken) | ||
{ | ||
if (timeoutRequest) | ||
{ | ||
await Task.Delay(3000, cancellationToken); | ||
} | ||
|
||
timeoutRequest = !timeoutRequest; | ||
return DateTimeOffset.UtcNow.ToString("f"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.