Skip to content

Commit

Permalink
Merge branch 'perpetualChannelFix'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Robles committed Jul 19, 2018
2 parents 7e4dd95 + bb9ae8e commit 95a6e08
Showing 1 changed file with 37 additions and 40 deletions.
77 changes: 37 additions & 40 deletions producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package conejo
import (
//"errors"
"github.com/streadway/amqp"
"log"
//"log"
)

func Publish(conn *amqp.Connection, queue Queue, exchange Exchange, body string) error {
Expand All @@ -13,50 +13,47 @@ func Publish(conn *amqp.Connection, queue Queue, exchange Exchange, body string)
return err
}
channel.Confirm(false)
defer channel.Close()
//ack, nack := channel.NotifyConfirm(make(chan uint64, 1), make(chan uint64, 1))

err = declareExchange(exchange, channel)
if err != nil {
return err
} else {

err := declareQueue(queue, channel)
if err != nil {
return err
} else {

err = channel.QueueBind(
queue.Name, // queue name
queue.Name, // @TODO - FIX ME!!!
exchange.Name, // exchange
false,
nil,
)
if err != nil {
return err
} else {

if err = channel.Publish(
exchange.Name, // publish to an exchange
queue.Name, // routing to 0 or more queues
false, // mandatory
false, // immediate
amqp.Publishing{
Headers: amqp.Table{},
ContentType: "text/plain",
ContentEncoding: "",
Body: []byte(body),
DeliveryMode: amqp.Transient, // 1=non-persistent, 2=persistent
Priority: 0, // 0-9
},
); err != nil {
return err
} else {
log.Println("CONEJO: Channel closed")
channel.Close()
}
}
}
}

err = declareQueue(queue, channel)
if err != nil {
return err
}

err = channel.QueueBind(
queue.Name, // queue name
queue.Name, // @TODO - FIX ME!!!
exchange.Name, // exchange
false,
nil,
)
if err != nil {
return err
}

err = channel.Publish(
exchange.Name, // publish to an exchange
queue.Name, // routing to 0 or more queues
false, // mandatory
false, // immediate
amqp.Publishing{
Headers: amqp.Table{},
ContentType: "text/plain",
ContentEncoding: "",
Body: []byte(body),
DeliveryMode: amqp.Transient, // 1=non-persistent, 2=persistent
Priority: 0, // 0-9
},
)
if err != nil {
return err
}

return nil
}

0 comments on commit 95a6e08

Please sign in to comment.