Simple Messaging

Simple messaging for pub/sub and producer/consumer. Pure Go!

Usage

Request-Response

Producer:

consumerAddr, err := net.ResolveTCPAddr("tcp", "localhost:8080")
if err != nil {
    panic(err)
}
producer := messaging.NewProducer(consumerAddr)
producer.Start()
defer producer.Close()

producer.EnsureSent([]byte("Hello World!"))

Consumer:

consumerListenAddr, err := net.ResolveTCPAddr("tcp", ":8080")
if err != nil {
    panic(err)
}
consumer := messaging.NewConsumer(consumerListenAddr, 1024)
consumer.Start()
defer consumer.Close()

message := consumer.Receive()

Pub-Sub

Subscriber:

pubAddr, err := net.ResolveTCPAddr("tcp", "localhost:8080")
if err != nil {
    panic(err)
}
sub := messaging.NewSubscriber(pubAddr, 1024)
sub.Start()
defer sub.Close()

message := sub.EnsureReceived()

Publisher:

pubListenAddr, err := net.ResolveTCPAddr("tcp", ":8080")
if err != nil {
    panic(err)
}
pub := messaging.NewPublisher(pubListenAddr)
pub.Start()
defer pub.Close()

pub.Send([]byte("Hello World!"))

TODO

  • Receivers confirm receipt of messages via reply

GitHub

View Github