-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d06b97
commit c08d964
Showing
13 changed files
with
115 additions
and
132 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Diagnostics; | ||
using System.Text; | ||
using Eventuous.Diagnostics; | ||
using Eventuous.Subscriptions.Context; | ||
|
||
namespace Eventuous.Connector.Base.Grpc; | ||
|
||
public class GrpcResponseHandler { | ||
|
||
readonly List<LocalContext> _contexts = new(); | ||
|
||
public string Prepare( | ||
DelayedAckConsumeContext context, | ||
Func<DelayedAckConsumeContext, ValueTask>? next | ||
) { | ||
var activity = context.Items.TryGetItem<Activity>("activity"); | ||
_contexts.Add(new LocalContext(context, next, activity?.Context.TraceId, activity?.Context.SpanId)); | ||
return Encoding.UTF8.GetString((context.Message as byte[])!); | ||
} | ||
|
||
public async Task Handler(ProjectionResponse result, CancellationToken cancellationToken) { | ||
var ctx = _contexts.Single(x => x.Context.MessageId == result.EventId); | ||
|
||
using var activity = Start(); | ||
_contexts.Remove(ctx); | ||
await ctx.Next!(ctx.Context.WithItem("projectionResult", result)); | ||
|
||
Activity? Start() | ||
=> ctx.TraceId == null || ctx.SpanId == null ? null | ||
: EventuousDiagnostics.ActivitySource.StartActivity( | ||
ActivityKind.Producer, | ||
new ActivityContext( | ||
ctx.TraceId.Value, | ||
ctx.SpanId.Value, | ||
ActivityTraceFlags.Recorded | ||
) | ||
); | ||
} | ||
|
||
record LocalContext( | ||
DelayedAckConsumeContext Context, | ||
Func<DelayedAckConsumeContext, ValueTask>? Next, | ||
ActivityTraceId? TraceId, | ||
ActivitySpanId? SpanId | ||
); | ||
} |
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
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.