/go-queue

In-memory message queue written in go

Primary LanguageGo

Go-Queue

Test Cases Go Report Card Coverage Status

An in-memory message broker build with Go.

Description

Go-Queue is an in-memory message broker which is thread safe and is Interface based. It provides a comprehensive way of subscription to topics based on pattern match.

Installation

go get github.com/Dev-Destructor/go-queue

Sample Demo

  func main() {
    broker := mq.NewBroker()
  }

Subscription of a topic

Through Exact matching
  func main() {
    broker := mq.NewBroker()

    testSubscriber := broker.Subscribe(mq.ExactMatcher("test"))
  }
Through Exact matching
  func main() {
    broker := mq.NewBroker()

    testSubscribers := broker.Subscribe(regexp.MustCompile(`tests\.\w*`))
  }

Publishing to a topic

  func main() {
    broker := mq.NewBroker()

    broker.Publish("test", "Hello World")
  }

Reading from a topic

  func main() {
    broker := mq.NewBroker()

    testSubscriber := broker.Subscribe(mq.ExactMatcher("test"))

    go func() {
      value, ok := testSubscriber.Poll()
      if !ok {
        return
      }

      fmt.Println(value)
    }()
  }