Preserve context fields on scheduled sends to non-native transports#2572
Closed
ArieGato wants to merge 1 commit intoJasperFx:mainfrom
Closed
Preserve context fields on scheduled sends to non-native transports#2572ArieGato wants to merge 1 commit intoJasperFx:mainfrom
ArieGato wants to merge 1 commit intoJasperFx:mainfrom
Conversation
When an envelope is scheduled to a transport without native scheduled-send support (RabbitMQ, Kafka, SharedMemory, ...), MessageRoute wraps it via ForScheduledSend and the transport ultimately serializes the inner envelope. Previously context-derived fields (TenantId, SagaId, CorrelationId, UserName) were only stamped on the outer wrapper, so the inner lost them by the time it reached the receiving handler. Extracts a virtual StampEnvelope method on MessageBus containing the idempotent context-derived stamps and applies it to both the outer envelope and the inner envelope of a scheduled wrap. MessageContext overrides it to add SagaId. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
|
Hey, I'm going to want a little more review on this one, so it's not going to make the release this morning |
Contributor
Author
|
Should I put any effort in this to resolve the merge conflict? |
3 tasks
Member
|
I took your test, but went a little different way to keep overhead out of the hot path: #2605 |
Contributor
Author
|
Great you fixed it, thnx! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2571.
Summary
MessageRoute.ForScheduledSendwraps it and previously eagerly serialized the inner intoouter.DatabeforeTrackEnvelopeCorrelationcould stamp context fields. The inner therefore arrived on the receive side withTenantId = null,SagaId = null,CorrelationId/UserNameunset — breaking multi-tenanted saga timeouts and observability chains.EnvelopeReaderWriter.Write, which now unwrapsmodel.Messageto serialize the inner.MessageBus.StampEnvelopewith the idempotent context-derived stamps (Source,CorrelationId,TenantId,UserName);MessageContextoverrides it to addSagaId.TrackEnvelopeCorrelationcalls it on the outer and, when the envelope is a scheduled wrap, also on the inner.Test plan
CoreTests.Runtime.Scheduled.inner_envelope_is_stamped_before_serialization— in-process via SharedMemory wrap path; assertsTenantId,CorrelationId,UserNameon the delivered inner.Wolverine.RabbitMQ.Tests.scheduled_saga_timeout_preserves_tenant— end-to-end multi-tenant saga with Marten + RabbitMQ + durable outbox; verifies the handler runs under the original tenant and the saga completes.main, pass in isolation).