54 lines
922 B
Go
54 lines
922 B
Go
package rmq
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
const url = "amqp://samba:samba@testbuild.shoa.com:5672/vh_samba"
|
|
const exchangeName = "test_e"
|
|
const queueName = "test_q"
|
|
|
|
func testCreateMq(t *testing.T) *Rmq {
|
|
mq, err := NewRmq(url)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = mq.ExchangeDeclare(exchangeName, ExchangeDirect)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = mq.QueueDeclare(queueName)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
return mq
|
|
}
|
|
|
|
func testPublish(t *testing.T, mq *Rmq) {
|
|
err := mq.Publish(exchangeName, queueName, []byte("hello world"))
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
func testConsume(t *testing.T, mq *Rmq) {
|
|
msgs, err := mq.Consume(queueName)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
for msg := range msgs {
|
|
t.Log(string(msg.Body))
|
|
}
|
|
return
|
|
}
|
|
|
|
func TestRabbitmq(t *testing.T) {
|
|
mq := testCreateMq(t)
|
|
defer mq.Close()
|
|
go testConsume(t, mq)
|
|
testPublish(t, mq)
|
|
time.Sleep(2 * time.Second)
|
|
}
|