package mqMgr

import (
	"fmt"
	"testing"
	"time"
)

var (
	queueHSYObj = NewHSYQueue("q-1", "ex-1", "rkey-1", "guest", "guest", "127.0.0.1", 5672)
)

func TestHSYSendMessage(t *testing.T) {
	message := "这是测试内容. Test"

	if queueHSYObj == nil {
		fmt.Println("初始化失败")
		return
	}
	defer queueHSYObj.ReleaseRes()

	err := queueHSYObj.SendMessage(message, "direct")
	if err != nil {
		t.Errorf("There should be no error, but now there is: %s", err)
		return
	}

	time.Sleep(time.Second)

	go func() {
		msgs, err := queueHSYObj.ReceiveMessage()
		if err != nil {
			t.Errorf("There should be no error, but now there is: %s", err)
			return
		}

		for msg := range msgs {
			fmt.Println("收到消息", string(msg.Body))
		}

	}()

	time.Sleep(time.Second)
}
