Skip to content

INT-3978 Fix MessageHistory for Message types #1764

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

Closed
wants to merge 2 commits into from

Conversation

artembilan
Copy link
Member

JIRA: https://jira.spring.io/browse/INT-3978

Previously the MessageHistory.write() always used MessageBuilder to populated the history header.
Since the MessageBuilder doesn't care about the source message type, we might lose some important information,
like AdviceMessage.inputMessage

  • Add conditional logic into the MessageHistory for all known Message<?> implementations
  • Provide appropriate tests in the MessageHistoryTests for known Message<?> implementations
  • Make AdviceMessage generic and fix all affected code on the matter
  • Since MutableMessage is public already, fix MongoDbMessageStore.DBObjectToMutableMessageConverter to use
    MutableMessage type directly.

JIRA: https://jira.spring.io/browse/INT-3978

Previously the `MessageHistory.write()` always used `MessageBuilder` to populated the `history` header.
Since the `MessageBuilder` doesn't care about the `source` message type, we might lose some important information,
like `AdviceMessage.inputMessage`

* Add conditional logic into the `MessageHistory` for all known `Message<?>` implementations
* Provide appropriate tests in the `MessageHistoryTests` for known `Message<?>` implementations
* Make `AdviceMessage` generic and fix all affected code on the matter
* Since `MutableMessage` is public already, fix `MongoDbMessageStore.DBObjectToMutableMessageConverter` to use
`MutableMessage` type directly.
}
else {
message = messageBuilderFactory.fromMessage(message).setHeader(HEADER_NAME, history).build();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should consider making the message history header mutable - via a MessageHistoryHolder; that way, we only have to rebuild the message in the first trackable component; each subsequent track would still get a new MessageHistory and each MB.build() would have to detect an existing holder, create a new one and transfer the existing history.

That way, pub/subs etc would inherit the history to-date, but have a unique holder so changes on one leg of the pub/sub would not be reflected in the other other leg. If the MB.build() didn't create a new holder, we'd get cross-talk.

Since MessageHistory is already a container object, we should be able to avoid a new class - just clone it in MB and replace the components on new writes.

@artembilan
Copy link
Member Author

Pushed.
Let me know if I understood your properly or if you need more info.

@garyrussell
Copy link
Contributor

I don't think we can rely on a boolean like that - we don't know what user code might do - they might channel.send() the same message to multiple channels.

Instead, just have the message builder detect if there is a history object and replace it with a new one (with the same contents) and, in message history write, if there's already contents, clone them and add the new track.

messageHistory.components.add(metadata);

This won't work because the contents are shared - we need new contents every time.

Since this is a bit complicated, it should perhaps be a different JIRA and not done as part of this fix but I definitely want to look at it for performance reasons.

@artembilan
Copy link
Member Author

Reverted the performance tuning PoC.
See https://jira.spring.io/browse/INT-3983 for more information.

((AdviceMessage) message).getInputMessage());
}
else {
message = messageBuilderFactory.fromMessage(message).setHeader(HEADER_NAME, history).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps add a DEBUG log (or WARN?) for not-recognized message types (e.g. User) ?

@artembilan
Copy link
Member Author

Pushed the WARN when the Message isn't of standard type.

@garyrussell
Copy link
Contributor

Merged as 1df7815

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.

2 participants