This commit is contained in:
shoopea 2019-06-28 14:25:10 +08:00
parent 81f17b3ad3
commit b21e22c59a

13
mq.go
View File

@ -8,13 +8,18 @@ import (
) )
func (s MQSession) Open() error { func (s MQSession) Open() error {
var err error var (
err error
conn *amqp.Connection
ch *amqp.Channel
q *amqp.Queue
)
if s.isConnected { if s.isConnected {
return errors.New("Session is already connected.") return errors.New("Session is already connected.")
} }
if s.SSL == false { if s.SSL == false {
conn, err := amqp.Dial("amqp://" + s.User + ":" + s.Password + "@" + s.Host + "/" + s.Path) conn, err = amqp.Dial("amqp://" + s.User + ":" + s.Password + "@" + s.Host + "/" + s.Path)
s.MQConnection = conn s.MQConnection = conn
} else { } else {
return errors.New("SSL connection not implemented") return errors.New("SSL connection not implemented")
@ -24,7 +29,7 @@ func (s MQSession) Open() error {
s.MQConnection.Close() s.MQConnection.Close()
return err return err
} }
ch, err := s.MQConnection.Channel() ch, err = s.MQConnection.Channel()
s.MQChannel = ch s.MQChannel = ch
logOnError(err, "Open : Failed to open channel") logOnError(err, "Open : Failed to open channel")
if err != nil { if err != nil {
@ -32,7 +37,7 @@ func (s MQSession) Open() error {
s.MQConnection.Close() s.MQConnection.Close()
return err return err
} }
q, err := s.MQChannel.QueueDeclare( q, err = s.MQChannel.QueueDeclare(
s.Queue, // name s.Queue, // name
false, // durable false, // durable
false, // delete when unused false, // delete when unused