https://github.com/syucream/posix_mq
a Go wrapper for POSIX Message Queues
https://github.com/syucream/posix_mq
golang ipc message-queue posix
Last synced: 8 months ago
JSON representation
a Go wrapper for POSIX Message Queues
- Host: GitHub
- URL: https://github.com/syucream/posix_mq
- Owner: syucream
- License: mit
- Created: 2018-10-10T16:19:31.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-01-04T09:23:05.000Z (about 2 years ago)
- Last Synced: 2025-04-19T12:13:51.717Z (9 months ago)
- Topics: golang, ipc, message-queue, posix
- Language: Go
- Homepage:
- Size: 24.4 KB
- Stars: 22
- Watchers: 3
- Forks: 18
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# posix_mq
a Go wrapper for POSIX Message Queues
posix_mq is a Go wrapper for POSIX Message Queues. It's important you read [the manual for POSIX Message Queues](http://man7.org/linux/man-pages/man7/mq_overview.7.html), ms_send(2) and mq_receive(2) before using this library. posix_mq is a very light wrapper, and will not hide any errors from you.
posix_mq is tested on only Linux in Docker container.
## Example
- sender
```go
package main
import (
"fmt"
"log"
"time"
"github.com/syucream/posix_mq/src/posix_mq"
)
const maxTickNum = 10
func main() {
oflag := posix_mq.O_WRONLY | posix_mq.O_CREAT
mq, err := posix_mq.NewMessageQueue("/posix_mq_example", oflag, 0666, nil)
if err != nil {
log.Fatal(err)
}
defer mq.Close()
count := 0
for {
count++
mq.Send([]byte(fmt.Sprintf("Hello, World : %d\n", count)), 0)
fmt.Println("Sent a new message")
if count >= maxTickNum {
break
}
time.Sleep(1 * time.Second)
}
}
```
- receiver
```go
package main
import (
"fmt"
"log"
"github.com/syucream/posix_mq/src/posix_mq"
)
const maxTickNum = 10
func main() {
oflag := posix_mq.O_RDONLY
mq, err := posix_mq.NewMessageQueue("/posix_mq_example", oflag, 0666, nil)
if err != nil {
log.Fatal(err)
}
defer mq.Close()
fmt.Println("Start receiving messages")
count := 0
for {
count++
msg, _, err := mq.Receive()
if err != nil {
log.Fatal(err)
}
fmt.Printf(string(msg))
if count >= maxTickNum {
break
}
}
}
```
## Acknowledgement
It's inspired by [Shopify/sysv_mq](https://github.com/Shopify/sysv_mq)