

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: RabbitMQ
incomplete
2: Alternative Brokers
incomplete
3: Connect
incomplete
4: AMQP Protocol
incomplete
5: MQTT and STOMP
incomplete
This lesson's interactive features are locked, please to keep using them
Let's scaffold the Peril project! Fork and then clone starter code from GitHub and move it somewhere on your machine. We will use this project for the rest of the course.
The starter code contains a few interesting things
internal/gamelogic package which contains the game logic for the Peril game.internal/routing package which contains some routing constants for the game.cmd/client and cmd/server packages, which are main packages that run the client and server for the game.rabbit.sh script: a convenience for starting and stopping RabbitMQ with Docker. You can run:
./rabbit.sh start to start RabbitMQ./rabbit.sh stop to stop it./rabbit.sh logs to view the server logsgo get github.com/rabbitmq/amqp091-go
import (
amqp "github.com/rabbitmq/amqp091-go"
)
To test your code, use the script to start a RabbitMQ server with Docker in the background:
./rabbit.sh start
Once it's running, open a new terminal and run your server:
go run ./cmd/server
You should see your message that the connection was successful. Press Ctrl+C to exit the program and see the shutdown message.
The Go standard library has a package called os/signal that you can use to listen for signals. Here's an example of how you can listen for a signal:
// wait for ctrl+c
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt)
<-signalChan