Communicating with RabbitMQ in Go

Now, we have a message broker (RabbitMQ). Before building an asynchronous API, we should learn how a Go program can talk to the message broker and send/receive the messages. While doing so, we'll create clients for production and consumption.

First, we have to create a connection to dial to the broker. If the connection is successful, a Channel needs to be created out of the connection. It has the API for performing operations on the message broker. Then, we can define a queue that messages are sent to. Finally, we publish a message to the queue.

We use an open source Go package called amqp for working with RabbitMQ.

Let's create our first program of this chapter:

  1. Create a directory like this for a message ...

Get Hands-On RESTful Web Services with Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.