To use an AMQP (Advanced Message Queuing Protocol) broker in Go, we can leverage the streadway/amqp
package. This package provides us with the functionality to connect, publish, consume messages and more to/from an AMQP broker, with RabbitMQ being the most popular implementation of AMQP.
To connect to a RabbitMQ broker, we can use the Dial function from the streadway/amqp package.
main.go308 chars20 lines
In the above example, we connect to a RabbitMQ broker running on localhost
with default credentials (guest:guest
).
From here, we can create a channel, declare a queue, publish or consume messages, and many more operations using the conn
object.
gistlibby LogSnag