https://github.com/althk/ipmq
An extremely simple thread-safe in-process messaging queue
https://github.com/althk/ipmq
golang-library in-process message-queue
Last synced: 11 months ago
JSON representation
An extremely simple thread-safe in-process messaging queue
- Host: GitHub
- URL: https://github.com/althk/ipmq
- Owner: althk
- License: mit
- Created: 2022-06-08T19:07:50.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-15T17:31:21.000Z (about 4 years ago)
- Last Synced: 2025-06-03T00:31:56.630Z (about 1 year ago)
- Topics: golang-library, in-process, message-queue
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## In-Process Messaging Queue
An extremely simple, in-process messaging queue that allows messages to be pushed to multiple consumers in the same process in a thread-safe way.
The API is very light, here's an example:
```go
import github.com/althk/ipmq
func main() {
q := ipmq.New() // get a new instance of type ipmq.MQ
someConsumerFn := func(msg ipmq.Msg) error {
// do something with msg
}
cancel, err := q.Register(someConsumerFn)
if err != nil {
// registration failed, do something
}
// if the consumer needs to unregister
// simply call cancel
// cancel() // unregisters the consumer
// push a msg to all registered consumers
q.Push("some msg") // calls all consumers concurrently
}
```
If there is a need for multiple 'topics', simply instantiate multiple instances of `ipmq.MQ` via `ipmq.New`.