Introduction
Configuration
Language Support
AMQP 0-9-1 Overview
More Exchange Types
More Consumer Features
Queue Deep-dive
Other Features
Reliable Message Delivery
High Availability and Backup
Monitoring
Management HTTP API
Tutorials
Networking
LavinMQ CLI
LavinMQ with Golang
The recommended library for Golang to access LavinMQ server is amqp091-go.
Before we jump right into writing our code, let’s set up the development environment.
Go development environment
- Download and install Go. Confirm that it’s available from your command line:
go version
- Create a directory for your project and navigate into it:
mkdir go_sample && cd go_sample
- Enable dependency tracking for your code:
go mod init go_sample
Publishing messages
In your project directory, create a file producer.go
and add the snippet
below to it.
In the snippet above, we first of all imported a couple of packages - the amqp Go client library included. We then established a connection to the LavinMQ server over a channel. Finally, we created a queue and published a “Hello world” message to the queue.
Note: Remember to replace “lavinmq server URL” in the snippet above with your correct URL.
Before running the producer, first, run go mod tidy
in your terminal - This way, Go will
add the amqp091-go
module as a requirement, as well as a go.sum
file for use in authenticating
the module.
You can now run the producer with go run producer.go
Consume messages
In your project directory, create a file consumer.go
and add the snippet
below to it.
Note: Again, remember to replace “lavinmq server URL” in the snippet above with your correct URL.
Run the consumer with go run consumer.go
Ready to take the next steps? Here are some things you should keep in mind:
Managed LavinMQ instance on CloudAMQP
LavinMQ has been built with performance and ease of use in mind - we've benchmarked a throughput of about 1,000,000 messages/sec. You can try LavinMQ without any installation hassle by creating a free instance on CloudAMQP. Signing up is a breeze.
Help and feedback
We welcome your feedback and are eager to address any questions you may have about this piece or using LavinMQ. Join our Slack channel to connect with us directly. You can also find LavinMQ on GitHub.