Skip to content

Instantly share code, notes, and snippets.

@dhanush
Last active December 25, 2020 04:01
Show Gist options
  • Save dhanush/0718cefcd98f630171dfe55ef4a72bcd to your computer and use it in GitHub Desktop.
Save dhanush/0718cefcd98f630171dfe55ef4a72bcd to your computer and use it in GitHub Desktop.
Handles the publishing of messages to the queue
package comms
//Publish publishes a request to the amqp queue
func (c *Connection) Publish(m Message) error {
select { //non blocking channel - if there is no error will go to default where we do nothing
case err := <-c.err:
if err != nil {
c.Reconnect()
}
default:
}
p := amqp.Publishing{
Headers: amqp.Table{"type": m.Body.Type},
ContentType: m.ContentType,
CorrelationId: m.CorrelationID,
Body: m.Body.Data,
ReplyTo: m.ReplyTo,
}
if err := c.channel.Publish(c.exchange, m.Queue, false, false, p); err != nil {
return fmt.Errorf("Error in Publishing: %s", err)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment