Last active
December 25, 2020 04:01
-
-
Save dhanush/0718cefcd98f630171dfe55ef4a72bcd to your computer and use it in GitHub Desktop.
Handles the publishing of messages to the queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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