Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flat headers #2613

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Flat headers #2613

wants to merge 4 commits into from

Conversation

ramonsmits
Copy link
Member

@ramonsmits ramonsmits commented Nov 5, 2024

NServiceBus serialized all headers into a single native header to workaround the 10 header limit. However, for native integration purposes is can be useful to set the headers so that the message format conforms to the receiver contract.

@ramonsmits ramonsmits self-assigned this Nov 5, 2024
…for publicly visible type or member 'TransportOperationExt'

if (flatHeaders)
{
foreach (var i in transportOperation.Message.Headers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramonsmits you mention the limit of 10. What would happen if the collection here is bigger than 10?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SzymonPobiega Likely we'll get a HTTP 4xx error but not sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I know we discussed this and I didn't raise a flag but I thought about it more and maybe a better option (more in-line with the other transports we touched) would be to have an API that allows the user to register a callback here that is in form of:

Func<Dictionary<string,string>, List<MessageAttributeValue>

The default value of that callback would do what we do (put all the headers in a single attribute) but users would be able to override it. This way we require the users to think about the mapping and explicitly take control over it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @SzymonPobiega here. When the native integration feature was improved to support what it supports today, we spent a lot of time thinking about a possible "promote headers" feature that would have allowed users to promote specific headers selectively to be message attributes. Considering that the transport has no control over the number of headers, this could blow up unexpectedly upon a Core change that adds new headers that suddenly overflow the amount of allowed message attributes.

I'd even argue that there should be no default behavior, and the user must always consciously select which headers should be promoted to avoid any surprise with subsequent releases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SzymonPobiega yes, discussed such a similar callback. Problem with SQS is that as mentioned on Slack that there are multiple native messages types due to the usage of SNS and SQS and batched/non-batched. A callback for headers which is shared between all is a good alternative but... there are 2 options:

  1. When registered, only use that and replace are header serializer
  2. When registered, invoke after our header serializer

Benefit of (1) is that it skips our header serialization which could be undone by changes made in the callback. In our use-case we could remove that header

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the native integration feature was improved to support what it supports today, we spent a lot of time thinking about a possible "promote headers" feature that would have allowed users to promote specific headers selectively to be message attributes. ....... I'd even argue that there should be no default behavior, and the user must always consciously select which headers should be promoted to avoid any surprise with subsequent releases.

This is similar to MT which uses envelopes. The transport can decide which header is puts in the header part of the serialized envelope of the payload and which headers to put in the native headers. In that regard MT is more flexible as it would allow to register a custom serializer with specific behavior.

its a cross transport concern and we already have issues in NServiceBus core repo on envelope support

…ey to MessageDispatcher to be similar in design as other transports.
@mauroservienti
Copy link
Member

NServiceBus serialized all headers into a single native header to workaround the 10 header limit. However, for native integration purposes is can be useful to set the headers.

It would be helpful to provide more context about the why of:

native integration purposes is can be useful to set the headers

@ramonsmits
Copy link
Member Author

It would be helpful to provide more context about the why of:

native integration purposes is can be useful to set the headers

@mauroservienti I've updated it to:

"However, for native integration purposes is can be useful to set the headers so that the message format conforms to the receiver contract."

better?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants