Skip to content

LimJiAn/go-rabbitmq-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-rabbitmq-example

Go amqp091-go

🎯 docker-compose, cobra 를 사용한 rabbitmq example 입니다.

🎯 go-rabbitmq-example using docker-compose and cobra.

⚙️ Installation

$ git clone https://github.com/LimJiAn/go-rabbitmq-example

👀 Usage

1. Run RabbitMQ Server (docker-compose.yml)

$ docker compose build
$ docker compose up

2. Wait 1-2 minutes

[+] Running 1/0
 ✔ Container rabbitmq  Created                                                                                                                               0.0s
Attaching to rabbitmq
...
...
...
...
rabbitmq  |  completed with 4 plugins.
rabbitmq  | 2023-09-06 09:25:43.553462+00:00 [info] <0.474.0> Server startup complete; 4 plugins started.
rabbitmq  | 2023-09-06 09:25:43.553462+00:00 [info] <0.474.0>  * rabbitmq_prometheus
rabbitmq  | 2023-09-06 09:25:43.553462+00:00 [info] <0.474.0>  * rabbitmq_management
rabbitmq  | 2023-09-06 09:25:43.553462+00:00 [info] <0.474.0>  * rabbitmq_management_agent
rabbitmq  | 2023-09-06 09:25:43.553462+00:00 [info] <0.474.0>  * rabbitmq_web_dispatch

3. You can see useful RabbitMQ dashboard at localhost:15672

Rabbitmq dashboard

4. Command

  • Run publish, consume
$ go run main.go --help
go rabbitmq example is a CLI tool for rabbitmq example.

Usage:
  go-rabbitmq-example [flags]
  go-rabbitmq-example [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  consume     receive message from queue
  help        Help about any command
  publish     Send message to queue.

Flags:
  -h, --help     help for go-rabbitmq-example
  -t, --toggle   Help message for toggle

Use "go-rabbitmq-example [command] --help" for more information about a command.

  • Run publish
$ go run main.go publish --help
publish.go, consume.go together make a simple example of using RabbitMQ

Usage:
  go-rabbitmq-example publish [flags]

Flags:
  -c, --count int           count of message to send (default 1)
  -e, --exchange string     exchange name
  -h, --help                help for publish
  -q, --queue string        queue name (default "hello")
  -r, --routingkey string   routing key (default "info")
  -t, --type string         exchange type [direct, fanout, topic, headers] (default "direct")

  • Run consume
$ go run main.go consume --help
publish.go, consume.go together make a simple example of using RabbitMQ

Usage:
  go-rabbitmq-example consume [flags]

Flags:
  -e, --exchange string     exchange name
  -h, --help                help for consume
  -q, --queue string        queue name (default "hello")
  -r, --routingkey string   routing key (default "info")
  -t, --type string         exchange type (default "direct")

5. Example

  • Without flag
$ go run main.go publish
$ go run main.go consume
2023/09/07 20:00:00  📧 Sent Hello World!!
2023/09/07 20:00:00  ✋ Waiting for messages. To exit press CTRL+C
2023/09/07 20:00:00  🆗 Received a message: Hello World!! / Count: 1

  • With flag
$ go run main.go publish -e=test -c=3
$ go run main.go consume -e=test
2023/09/08 20:00:00  📮 exchangeName: test, routingKey: info, exchangeType: direct, count: 3
2023/09/08 20:00:00  📧 Sent Hello World!! [1]
2023/09/08 20:00:00  📧 Sent Hello World!! [2]
2023/09/08 20:00:00  📧 Sent Hello World!! [3]
2023/09/08 20:00:00  📮 exchangeName: test, routingKey: info, exchangeType: direct, queue: hello
2023/09/08 20:00:00  ✋ Waiting for messages. To exit press CTRL+C
2023/09/08 20:00:00  🆗 Received a message: Hello World!! [1] / Count: 1
2023/09/08 20:00:00  🆗 Received a message: Hello World!! [2] / Count: 2
2023/09/08 20:00:00  🆗 Received a message: Hello World!! [3] / Count: 3

📚 Reference

About

Using RabbitMQ with Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages