Created
April 7, 2016 09:16
-
-
Save fzerorubigd/f8238b4eb3c821afc82e56683ae0a8cd to your computer and use it in GitHub Desktop.
a simple queue status query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "log" | |
| "os" | |
| "github.com/ogier/pflag" | |
| "github.com/streadway/amqp" | |
| ) | |
| func fatal(err error) { | |
| if err != nil { | |
| log.Print(err) | |
| os.Exit(-1) | |
| } | |
| } | |
| func main() { | |
| address := pflag.String("address", "127.0.0.1", "rabbitmq address") | |
| port := pflag.Int("port", 5672, "rabbitmq port") | |
| user := pflag.StringP("user", "u", "guest", "rabbitmq user") | |
| password := pflag.StringP("password", "p", "guest", "rabbitmq password") | |
| queue := pflag.StringP("queue", "q", "", "rabbitmq queue") | |
| pflag.Parse() | |
| conn, err := amqp.Dial(fmt.Sprintf("amqp://%s:%s@%s:%d/", *user, *password, *address, *port)) | |
| fatal(err) | |
| channel, err := conn.Channel() | |
| fatal(err) | |
| q, err := channel.QueueInspect(*queue) | |
| fatal(err) | |
| data, err := json.MarshalIndent(q, "", "\t") | |
| fatal(err) | |
| fmt.Println(string(data)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment