Skip to content

Commit

Permalink
fix: stop cosuming if -c and message count is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
marianozunino committed Oct 10, 2024
1 parent b58c783 commit 84cd146
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@ Messages can be captured from an AMQP or AMQPS RabbitMQ server, with flexible TL
GroupID: "available-commands",
RunE: func(cmd *cobra.Command, args []string) error {
cfg := config.New(

config.WithRabbitMQURL(fmt.Sprintf("%s://%s/%s", getProtocol(), viper.GetString("url"), viper.GetString("virtualhost"))),
config.WithExchange(viper.GetString("exchange")),
config.WithQueue(queue),
config.WithOutputFile(viper.GetString("output")),
config.WithUseAMQPS(viper.GetBool("amqps")),
config.WithVirtualHost(viper.GetString("virtualhost")),
config.WithSkipTLSVerification(viper.GetBool("skip-tls-verify")),
config.WithAutoAck(viper.GetBool("auto-ack")),
config.WithFileMode(viper.GetString("file-mode")),
config.WithStopAfterConsume(viper.GetBool("stop-after-consume")),
config.WithPrettyPrint(viper.GetBool("pretty-print")),
config.WithQueue(queue),
config.WithStopAfterConsume(stopAfterConsume),
config.WithAutoAck(autoAck),
)

return app.Dump(cfg)
Expand Down
5 changes: 5 additions & 0 deletions internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func bindQueueToRoutingKeys(consumer *rmq.Consumer, queueName string, routingKey

// Helper function to process messages
func processMessages(msgs <-chan rmq.Message, writer *filewriter.Writer, msgCount int, stopAfterConsume bool) error {
if msgCount == 0 && stopAfterConsume {
color.Yellow("No messages to consume. Exiting.")
return nil
}

consumedCount := 0
blue := color.New(color.FgBlue)

Expand Down

0 comments on commit 84cd146

Please sign in to comment.