feat: Subscription get message by id json output #1704
Merged
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.
This change is to add a possiblity of JSON output from the
subscription.get_message_by_idcommand.Motivation
In our organization we suggested our teams to utilize Pulsarctl when investigating or debugging Pulsar topics, subscriotions.
Almost all of our messages are in the end json serialized data, but we have also had a few people utilize only strings as the data within the the byte[] sent to pulsar.
When an issue occurs in a consuming system, where e.g a message is received correctly, but fails to be proccesed in the system it always a guarentee that the consuming code allows the team to investigate the message data. That all depends on how they´ve set up their system.
However we advise to use Pulsarctl as a means to be able to view their messages, maybe copy the message content out to examine it further.
But currently the output of the command is a funky raw text outputted along with a hex.Dump of the []byte. looking like this:

In my example the message is very small, but lets say the message had like 50 fields with properties, maybe nested.
The column to the right becomes very big and hard to copy value from without doing some terminal magic and converting.
With this the change a JSON representation of the message - alongside the payload is outputted:

We can then copy the entire result (or pipe it to something else), unescape the escaped json from
PayloadAsStringproperty and have the JSON content available"I know that messages can also be something entirely else like a file read from disk to a byte array - like a jpg sent as a byte[].
This with text output looks like this:

And with json output looks like this:

Modifications
Describe the modifications you've done.
Add
readMessagestructAdd usage of WithObject output as wel.
Verifying this change
I have another PR #1699 for the same command fixing a typo.
And this issue #1703 for verifying needs some input.
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
Documentation
Check the box below.
no-need-doc