コード例 #1
0
ファイル: example_test.go プロジェクト: stengland/ironcli
func ExampleQueue_Upsert() {
	// 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.Upsert(QueueInfo{MessageTimeout: 120}) // ok, we'll make one.
		if err != nil {
			return err
		}
	}
	// Definitely exists now.

	// Let's just add some messages.
	msgs, err := q.PushStrings("msg1", "msg2")
	if err != nil {
		return err
	}
	msgs, err := q.Peek()
	if len(msgs) != 2 {
		// and it has messages already...
	}
}
コード例 #2
0
ファイル: example_test.go プロジェクト: stengland/ironcli
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")
	}
}