https://github.com/unikorp/workmq
A message queue system written in Go
https://github.com/unikorp/workmq
go golang message message-queue queue worker workers
Last synced: 3 months ago
JSON representation
A message queue system written in Go
- Host: GitHub
- URL: https://github.com/unikorp/workmq
- Owner: unikorp
- License: mit
- Created: 2017-07-20T22:40:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-24T11:43:34.000Z (about 8 years ago)
- Last Synced: 2025-04-02T20:11:26.896Z (9 months ago)
- Topics: go, golang, message, message-queue, queue, worker, workers
- Language: Go
- Size: 223 KB
- Stars: 26
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
WorkMQ
======
A message queue system written in Go.
This is a message queue implementation written in Go.
It allows to declare some queues, number of workers and processors that will process data sent in these queues.
Initially used for a Golang workshop study case, we've decided to put it open-source.

# Installation
First, install it:
```go
$ go get -u github.com/unikorp/workmq
```
Then, import it in your application code:
```go
import (
"github.com/unikorp/workmq"
)
```
# Configuration
Queues and workers configuration is managed using a `config.json` file in the root directory.
Here is an example JSON with 2 queues, listening on UDP port and exposing the given HTTP port:
```json
{
"ports": {
"udp": ":10001",
"http": ":8080"
},
"queues": {
"queue.1s": {
"processor": "processor.logger.1s",
"num_workers": 150
},
"queue.2s": {
"processor": "processor.logger.2s",
"num_workers": 200
}
}
}
```
Here, we have 2 queues:
* `queue.1s` that will be processed by registered processor `processor.logger.1s` and will use 150 workers (goroutines),
* `queue.2s` that will be processed by registered processor `processor.logger.2s` and will use 200 workers (goroutines).
# Usage
Here is a code example that initializes WorkMQ, registers a processor and start handling messages:
```go
package main
import (
"fmt"
"time"
"github.com/unikorp/workmq"
)
func main() {
app := workmq.Init()
app.AddProcessor("processor.logger.1s", func(worker *workmq.Worker, message workmq.Message) {
time.Sleep(time.Second * 1)
fmt.Printf("Worker #%d (queue: \"%s\") manages message %s\n", worker.ID, worker.Queue, message.Body)
})
app.Handle()
}
```
# Send data
You can send message data over UDP by sending a JSON string with the following structure:
```
{ "queue": "queue.1s", "body": "" }
```