func (ir *IronRunner) Consume(name string, messages int) { q := mq.New(name) _, err := q.PopN(messages) if err != nil { log.Println(err) } }
func ExampleQueue_Upsert() error { // Prepare a Queue from configs q := mq.New("my_queue") // Upsert will create the queue on the server or update its message_timeout // to 120 if it already exists. // Let's just make sure we don't have a queue, because we can. if _, err := q.Info(); mq.ErrQueueNotFound(err) { _, err := q.Update(mq.QueueInfo{MessageTimeout: 120}) // ok, we'll make one. if err != nil { return err } } // Definitely exists now. // Let's just add some messages. _, err := q.PushStrings("msg1", "msg2") if err != nil { return err } msgs, err := q.Peek() if len(msgs) != 2 { // and it has messages already... } return nil }
func (ir *IronRunner) Produce(name, body string, messages int) { q := mq.New(name) msgs := make([]string, messages) for i := 0; i < messages; i++ { msgs[i] = body } _, err := q.PushStrings(msgs...) if err != nil { log.Println(err) } }
// CreateIronQueue creates and returns Iron.io queue func CreateIronQueue(name string) (*mq.Queue, error) { subscribers := []mq.QueueSubscriber{} subscription := mq.PushInfo{ Retries: 3, RetriesDelay: 60, ErrorQueue: "error_queue", Subscribers: subscribers, } queue_type := "push" queueInfo := mq.QueueInfo{Type: queue_type, MessageExpiration: 60, MessageTimeout: 56, Push: &subscription} _, err := mq.CreateQueue(name, queueInfo) if err != nil { return nil, err } queue := mq.New(name) return &queue, nil }
func ExampleQueue() { // Standard way of using a queue will be to just start pushing or // getting messages, q.Upsert isn't necessary unless you explicitly // need to create a queue with custom settings. q := mq.New("my_queue2") // Simply pushing messages will create a queue if it doesn't exist, with defaults. msgs, err := q.PushStrings("msg1", "msg2") if err != nil { return err } msgs, err := q.GetN(2) if err != nil { return err } if len(msgs) != 2 { return errors.New("not good") } }