mirror of https://github.com/dapr/cli.git
add pubsub component name to publish command (#435)
This commit is contained in:
parent
294fa19a20
commit
edaae6e199
|
@ -16,12 +16,13 @@ import (
|
||||||
|
|
||||||
var publishTopic string
|
var publishTopic string
|
||||||
var publishPayload string
|
var publishPayload string
|
||||||
|
var pubsubName string
|
||||||
|
|
||||||
var PublishCmd = &cobra.Command{
|
var PublishCmd = &cobra.Command{
|
||||||
Use: "publish",
|
Use: "publish",
|
||||||
Short: "Publish an event to multiple consumers",
|
Short: "Publish an event to multiple consumers",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
err := publish.SendPayloadToTopic(publishTopic, publishPayload)
|
err := publish.SendPayloadToTopic(publishTopic, publishPayload, pubsubName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error publishing topic %s: %s", publishTopic, err))
|
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error publishing topic %s: %s", publishTopic, err))
|
||||||
return
|
return
|
||||||
|
@ -34,7 +35,9 @@ var PublishCmd = &cobra.Command{
|
||||||
func init() {
|
func init() {
|
||||||
PublishCmd.Flags().StringVarP(&publishTopic, "topic", "t", "", "the topic the app is listening on")
|
PublishCmd.Flags().StringVarP(&publishTopic, "topic", "t", "", "the topic the app is listening on")
|
||||||
PublishCmd.Flags().StringVarP(&publishPayload, "data", "d", "", "(optional) a json serialized string")
|
PublishCmd.Flags().StringVarP(&publishPayload, "data", "d", "", "(optional) a json serialized string")
|
||||||
|
PublishCmd.Flags().StringVarP(&pubsubName, "pubsub", "", "", "name of the pub/sub component")
|
||||||
PublishCmd.MarkFlagRequired("app-id")
|
PublishCmd.MarkFlagRequired("app-id")
|
||||||
PublishCmd.MarkFlagRequired("topic")
|
PublishCmd.MarkFlagRequired("topic")
|
||||||
|
PublishCmd.MarkFlagRequired("pubsub")
|
||||||
RootCmd.AddCommand(PublishCmd)
|
RootCmd.AddCommand(PublishCmd)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// SendPayloadToTopic publishes the topic
|
// SendPayloadToTopic publishes the topic
|
||||||
func SendPayloadToTopic(topic, payload string) error {
|
func SendPayloadToTopic(topic, payload, pubsubName string) error {
|
||||||
if topic == "" {
|
if topic == "" {
|
||||||
return errors.New("topic is missing")
|
return errors.New("topic is missing")
|
||||||
}
|
}
|
||||||
|
if pubsubName == "" {
|
||||||
|
return errors.New("pubsubName is missing")
|
||||||
|
}
|
||||||
|
|
||||||
l, err := standalone.List()
|
l, err := standalone.List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -37,7 +40,7 @@ func SendPayloadToTopic(topic, payload string) error {
|
||||||
b = []byte(payload)
|
b = []byte(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("http://localhost:%s/v%s/publish/%s", fmt.Sprintf("%v", app.HTTPPort), api.RuntimeAPIVersion, topic)
|
url := fmt.Sprintf("http://localhost:%s/v%s/publish/%s/%s", fmt.Sprintf("%v", app.HTTPPort), api.RuntimeAPIVersion, pubsubName, topic)
|
||||||
// nolint: gosec
|
// nolint: gosec
|
||||||
r, err := http.Post(url, "application/json", bytes.NewBuffer(b))
|
r, err := http.Post(url, "application/json", bytes.NewBuffer(b))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue