/memq

A simple thread-safe in-memory message broker for Go

Primary LanguageGoMIT LicenseMIT

memq

build Go Reference Go Report Card

A simple thread-safe in-memory message broker fo Go.

Quick Start

  1. Get it:

    go get github.com/sergeykonkin/memq
  2. Use it:

    // Import:
    import (
        "github.com/sergeykonkin/memq"
    )
    
    // Create new Broker:
    b := memq.NewBroker()
    
    // Subscribe to topic:
    b.Subscribe("my-topic", func(msg interface{}) {
        fmt.Printf("New message: %v", msg)
    })
    
    // Publish to topic:
    b.Publish("my-topic", "Hello World!")
    
    // You can also save a subscription to unsubscribe later:
    sub := b.Subscribe("my-topic", anotherHandler)
    defer sub.Unsubscribe()

Note that for now Broker supports only fan-out mode, so if there are 2 or more subscribers for a topic - they all will be receiving new messages.

License

MIT