A lightweight message queue for Go that requires no dedicated queue server. Just a Redis server.
Go implementation of https://github.com/smrchy/rsmq.
$ go get github.com/semihbkgr/go-rsmq
If you run a Redis server and currently use Amazon SQS or a similar message queue you might as well use this fast little replacement. Using a shared Redis server multiple Go processes can send / receive messages.
opts := &redis.Options{Addr: "localhost:6379"}
redisClient := redis.NewClient(opts)
rsmqClient := rsmq.NewRedisSMQ(redisClient, "rsmq")
defer rsmqClient.Quit()
err := rsmqClient.CreateQueue("queue", rsmq.UnsetVt, rsmq.UnsetDelay, rsmq.UnsetMaxsize)
if err != nil {
fmt.Println(err.Error())
}
id, err := rsmqClient.SendMessage("queue", "message", rsmq.UnsetVt)
if err != nil {
panic(err)
}
fmt.Printf("message sent, id: %s\n", id)
msg, err := rsmqClient.PopMessage("queue")
if err != nil {
panic(err)
}
if msg == nil {
fmt.Println("queue is empty")
} else {
fmt.Printf("message received, id: %s, message: %s", msg.ID, msg.Message)
}
All details about the queue implementation are in here.
go-rsmq follows all the naming conventions of javascript implementation.