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

feat: Subscription get message by id json output #1704

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions pkg/ctl/subscription/get_message_by_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ import (
"github.com/streamnative/pulsarctl/pkg/cmdutils"
)

type readMessage struct {
Properties map[string]string `json:"properties"`
MessageId utils.MessageID `json:"messageId"`
Payload []byte `json:"payload"`
PayloadAsString string `json:"PayloadString"`
}

func GetMessageByIDCmd(vc *cmdutils.VerbCmd) {
var desc cmdutils.LongDescription
desc.CommandUsedFor = "This command is used for getting messages by the given legerID and entryID" +
Expand Down Expand Up @@ -85,14 +92,28 @@ func doGetMessageByID(vc *cmdutils.VerbCmd, legerID int64, entryID int64) error
return fmt.Errorf("no message found with the given legerID and entryID")
}
message := messages[0]

propertiesJSON, err := json.Marshal(message.GetProperties())
if err != nil {
return err
}

vc.Command.Println(fmt.Sprintf(`Message ID: %s
Properties: %s
Message: %s`, message.GetMessageID(), propertiesJSON, hex.Dump(message.Payload)))
textOutput := fmt.Sprintf(
`Message ID: %s
Properties: %s
Message:
%s`, message.GetMessageID(), propertiesJSON, hex.Dump(message.Payload))

oc := cmdutils.NewOutputContent().
WithObject(&readMessage{
MessageId: message.GetMessageID(),
Properties: message.GetProperties(),
Payload: message.Payload,
PayloadAsString: string(message.Payload),
}).
WithText(textOutput)

err = vc.OutputConfig.WriteOutput(vc.Command.OutOrStdout(), oc)

return nil
return err
}
Loading