func (r *RmCmd) Run() { var queues []mq.Queue if isPipedIn() { scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { name := scanner.Text() queues = append(queues, mq.ConfigNew(name, &r.settings)) } if err := scanner.Err(); err != nil { fmt.Fprintln(os.Stderr, err) } } else { queues = append(queues, mq.ConfigNew(r.queue_name, &r.settings)) } for _, q := range queues { err := q.Delete() if err != nil { fmt.Println(red("Error deleting queue ", q.Name, ": ", err)) } else { fmt.Println(green(LINES, q.Name, " has been sucessfully deleted.")) } } }
func (p *PopCmd) Run() { q := mq.ConfigNew(p.queue_name, &p.settings) messages, err := q.PopN(*p.n) if err != nil { fmt.Fprintln(os.Stderr, red(err)) } // If anything here fails, we still want to print out what was deleted before exiting if p.file != nil { b, err := json.Marshal(messages) if err != nil { fmt.Fprintln(os.Stderr, red(err)) printMessages(messages) } _, err = p.file.Write(b) if err != nil { fmt.Fprintln(os.Stderr, red(err)) printMessages(messages) } } if isPipedOut() { printMessages(messages) } else { plural := "" if *p.n > 1 { plural = "s" } fmt.Println(green(LINES, "Message", plural, " successfully popped off ", q.Name)) fmt.Println() fmt.Println("-------- ID ------ | Body") printMessages(messages) } }
func (p *PeekCmd) Run() { q := mq.ConfigNew(p.queue_name, &p.settings) msgs, err := q.PeekN(*p.n) if err != nil { fmt.Fprintln(os.Stderr, red(err)) return } if len(msgs) < 1 { fmt.Fprintln(os.Stderr, red("Queue is empty.")) return } if !isPipedOut() { plural := "" if *p.n > 1 { plural = "s" } fmt.Println(green(LINES, "Message", plural, " successfully peeked")) fmt.Println() fmt.Println("-------- ID ------ | Body") } printMessages(msgs) }
func (i *InfoCmd) Run() { q := mq.ConfigNew(i.queue_name, &i.settings) info, err := q.Info() if err != nil { fmt.Fprintln(os.Stderr, red(err)) return } fmt.Printf("%sName: %s\n", BLANKS, info.Name) fmt.Printf("%sCurrent Size: %d\n", BLANKS, info.Size) fmt.Printf("%sTotal messages: %d\n", BLANKS, info.TotalMessages) fmt.Printf("%sMessage expiration: %d\n", BLANKS, info.MessageExpiration) fmt.Printf("%sMessage timeout: %d\n", BLANKS, info.MessageTimeout) if info.Push != nil { fmt.Printf("%sType: %s\n", BLANKS, *info.Type) fmt.Printf("%sSubscribers: %d\n", BLANKS, len(info.Push.Subscribers)) fmt.Printf("%sRetries: %d\n", BLANKS, info.Push.Retries) fmt.Printf("%sRetries delay: %d\n", BLANKS, info.Push.RetriesDelay) if *i.subscriberList { fmt.Printf("%sSubscriber list\n", LINES) printSubscribers(info) fmt.Println() } } printQueueHudURL(BLANKS, q) }
func (c *ClearCmd) Run() { q := mq.ConfigNew(c.queue_name, &c.settings) if err := q.Clear(); err != nil { fmt.Println(red("Error clearing queue:", err)) return } fmt.Fprintln(os.Stderr, green(LINES, "Queue ", q.Name, " has been successfully cleared")) }
// This doesn't work with reserved messages // TODO: add --reserved flag to work with reserved messages // TODO: Make the message not found error more descriptive. func (d *DeleteCmd) Run() { q := mq.ConfigNew(d.queue_name, &d.settings) err := q.DeleteMessages(d.ids) if err != nil { fmt.Println(red(BLANKS, err)) return } plural := "" if len(d.ids) > 1 { plural = "s" } fmt.Println(green(BLANKS, "Done deleting message", plural)) }
func (c *CreateCmd) Run() { fmt.Printf("%sCreating queue \"%s\"\n", BLANKS, c.queue_name) q := mq.ConfigNew(c.queue_name, &c.settings) _, err := q.PushStrings("") if err != nil { fmt.Fprintln(os.Stderr, red(BLANKS, "create error: ", err)) return } err = q.Clear() if err != nil { fmt.Fprintln(os.Stderr, red(BLANKS, "create error: ", err)) } fmt.Println(green(LINES, "Queue ", q.Name, " has been successfully created.")) printQueueHudURL(BLANKS, q) }
func (p *PushCmd) Run() { q := mq.ConfigNew(p.queue_name, &p.settings) ids, err := q.PushStrings(p.messages...) if err != nil { fmt.Fprintln(os.Stderr, red(err)) } if isPipedOut() { for _, id := range ids { fmt.Println(id) } } else { fmt.Println(green(LINES, "Message succesfully pushed!")) fmt.Printf("%sMessage IDs:\n", BLANKS) fmt.Printf("%s", BLANKS) for _, id := range ids { fmt.Printf("%s ", id) } fmt.Println() } }
func (r *ReserveCmd) Run() { q := mq.ConfigNew(r.queue_name, &r.settings) messages, err := q.GetNWithTimeout(*r.n, *r.timeout) if err != nil { fmt.Fprintln(os.Stderr, red(err)) } // If anything here fails, we still want to print out what was reserved before exiting if r.file != nil { b, err := json.Marshal(messages) if err != nil { fmt.Fprintln(os.Stderr, red(err)) printReservedMessages(messages) return } _, err = r.file.Write(b) if err != nil { fmt.Fprintln(os.Stderr, red(err)) printReservedMessages(messages) return } } if len(messages) < 1 { fmt.Fprintln(os.Stderr, red("Queue is empty")) return } if isPipedOut() { printReservedMessages(messages) } else { fmt.Println(green(LINES, "Messages successfully reserved")) fmt.Println("--------- ID ------|------- Reservation ID -------- | Body") printReservedMessages(messages) } }