Naming changes for consistency and ability to publish a NATS::Message - #5
Naming changes for consistency and ability to publish a NATS::Message#5samueleaton wants to merge 11 commits into
Conversation
…ssage There were interchangeable uses of "message", "body", and "data" referring to the message payload data. This change conforms to the NATS protocol which uses "message" as the encompassing message (headers + payload), and "payload" as the primary data. Also adds another `publish` method that takes a NATS::Message struct and pipes it to the existing `publish` method
|
|
||
| def publish(message : Message) : Nil | ||
| publish message.subject, message.payload, message.reply_to, message.headers | ||
| end |
There was a problem hiding this comment.
I'm making NATS a more central part of a service I'm working on and its nice to pass around NATS::Message or return new ones from functions so that other functions can then send in a reply or publish. Some encapsulation.
There was a problem hiding this comment.
Yeah, I don't mind this change. It seems all the first-party clients have this form of this method. The Go client seems to only have this form, even.
|
Making the naming (especially for this very specific thing) more consistent is something I've been meaning to do, tbh. I don't even remember where I got Aligning more with what the first-party clients are doing (specifically the Go client) is what the Synadia folks are recommending these days now that they've all gotten more standardized. Could you swap the name over to |
|
yeah good call, found it here as |
| # end | ||
| # ``` | ||
| def request(subject : String, message : Data = "", timeout : Time::Span = 2.seconds, headers : Headers? = nil) : Message? | ||
| def request(subject : String, data : Payload = "", timeout : Time::Span = 2.seconds, headers : Headers? = nil) : Message? |
There was a problem hiding this comment.
I kept the internal alias name as Payload because data : Data in the function signature seems a little ambiguous. The Go client uses "payload" several times when needed for clarity.
|
still have to fix some specs |
|
all specs pass |
I really like the lazy stringification to reduce heap allocations when bytes are acceptable. I'm not sure if Also, I'm also trying to consider it from the perspective of what serialization formats most people would use in case it makes sense for the most common format to use the name that's easier to type. I'm not sure, though. NATS JetStream uses JSON internally, where |
|
right, whichever naming you prefer is fine. I'm having to write a lot of Although since its lazily parsed and then cached, I would expect as a user for IMO users don't need to know about the internal implementation that we're converting a |
|
@samueleaton If you want to change these up to be |


There were interchangeable uses of "message", "body", and "data" referring
to the message payload data. This change conforms to the NATS protocol
which uses "message" as the encompassing message (headers + payload), and
"payload" as the primary data.
Also adds another
publishmethod that takes aNATS::Messagestruct andpipes it to the existing
publishmethod