-
Notifications
You must be signed in to change notification settings - Fork 407
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
Extend message struct to include a raw interface #205
base: master
Are you sure you want to change the base?
Extend message struct to include a raw interface #205
Conversation
Add a new field to the message struct in order to pass user data such as a struct of pointers. Despite of the data can be stored on the message payload it have two dissavantages: 1) It forces the user to marshall/unmarshall the data each time that the message is passed in the pipeline 2) Data such as signaling channels or pointers can not be casted to a []byte. Signed-off-by: Daniel Canessa <[email protected]>
Hey @danielcanessa, thanks for the proposal. The disadvantages that you list are actually there by design, as Pub/Subs are distributed by nature. I guess you would like to use this with go-channel implementation, which is the only Pub/Sub that would support it. However, go-channel is an exception here and I think we shouldn't change the public API just to take advantage of its features. Note that the Can you share how do you use watermill and what's your use case for this? |
thanks for the quick response @m110
Each time that a request is queued I create a message and published it to the pipeline. I'm passing a structure with pointers in the message in order to modify the data in the different stages of the router. Besides, a signaling channel is included in the struct because I need to block the request to the RPC2 listener until the pipeline modifies all the necessary data. Right now I have two issues with the current message implementation:
Can you please suggest an alternative given the current message structure, please? |
Hey @danielcanessa. So I have another proposal that should allow you to achieve the same thing without modifying the Preferably, this would be enabled by a config boolean flag, as this is changing the current behavior. Then, you would be able to send it like this: someStruct := myStruct{/* ... */}
msg := message.NewMessage(watermill.NewUUID(), nil)
ctx := context.WithValue(msg.Context(), "my_key", someStruct)
msg.SetContext(ctx)
publisher.Publish("topic", msg)
// Then in subscriber:
someStruct := msg.Context().Value("my_key").(myStruct) It doesn't look that good, but the Would that solve your use case? |
Hi @m110 ! I'm wondering if changing the message context in pubsub will cause issues in other parts of watermill. Could you please give me more details about the changes required on watermill side? |
Hey @danielcanessa. The implementation should be straightforward - in the line I've mentioned, in the gochannel Pub/Sub, we could copy the message's This shouldn't have any impact on other parts of watermill. The config I mentioned is this struct: https://github.com/ThreeDotsLabs/watermill/blob/master/pubsub/gochannel/pubsub.go#L15 I'm happy to review a PR, or I could look into this during this weekend. :) |
hi @m110! |
Hello @danielcanessa!
Maybe the solution here may be adding a configuration that will explicitly copy the context in this Pub/Sub (with false as default, to not break default Pub/Sub behavior)? |
Any plan to retake this? |
Add a new field to the message struct in order to pass user data such as a struct of pointers.
Despite the data can be stored on the message payload it has two disadvantages:
The user data approach is valid for routers running inside the same process.
Signed-off-by: Daniel Canessa [email protected]