Repository navigation
Publish a labelled message's contract in a "contract" header - #97
Merged
Merged
Conversation
A message whose type carries SW.PrimitiveTypes.ContractAttribute is published with a "contract" header holding key@major, so a consumer can tell which shape the body has without relying on the class name. Types without the attribute, or with a malformed key, publish exactly as before: no header. The attribute is found by name, so the bus still depends on PrimitiveTypes 10.0.0 and applications that never label a message don't have to upgrade it (a raised floor would be a package-downgrade error for anyone pinning 10.0.0). Consumers only read the headers they know, so older consumers ignore it; the dead-letter copy keeps it.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
AhmadRAbuhussein
approved these changes
Oct 30, 2026
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.
What
When a published message's type carries
SW.PrimitiveTypes.ContractAttribute(PrimitiveTypes 10.0.2), e.g.[Contract("orders.msg.placed", Major = 2)], the message gets a headercontract: orders.msg.placed@2(BusOptions.ContractHeaderName). A consumer can then tell which shape the body has, and which major, without relying on the class name. Today a message is identified only by its type name, which is also its routing key.Backward compatibility
Most applications using the bus will never label a message, so this is built to change nothing for them:
IsWellFormedfalse): it's left out rather than failing the publish. The body, routing key, exchange and every other header are unchanged.SimplyWorks.PrimitiveTypes10.0.0 and finds the attribute by its full name with reflection, cached per type. Requiring 10.0.2 would turn into a package-downgrade error (NU1605) for any application that pins 10.0.0 directly. Only the integration test project references 10.0.2.ConsumerRunnerreads only the headers it knows by name (checked on currentmainand on 10.0.2), so older consumers ignore the new one. The dead-letter copy keeps all headers, so the contract survives into.bad.contractparameters are onBasicPublisher, which is internal. The only public addition is theBusOptions.ContractHeaderNameconstant.Publish(string messageTypeName, string message)) have no type, so they carry no header.Tests
ContractHeaderTestsagainst a real broker (Testcontainers):orders.msg.placed@2;