Giter Club home page Giter Club logo

go-msg's Introduction

go-msg

GoDoc Build Status

Pub/Sub Message Primitives for Go

This library contains the basic primitives for developing pub-sub systems.

Messages are published to Topics. Servers subscribe to Messages.

These primitives specify abstract behavior of pub-sub; they do not specify implementation. A Message could exist in an in-memory array, a file, a key/value store like RabbitMQ, or even something like Amazon SNS/SQS or Google Pub/Sub. In order to tap into that backend, a concrete implementation must be written for it.

Here's a list of backends that are currently supported:

Backend Link
Channels https://github.com/zerofox-oss/go-msg/backends/mem
AWS (SNS,SQS) https://github.com/zerofox-oss/go-aws-msg
Google PubSub https://github.com/paultyng/go-msg-pubsub

How it works

Backend

A backend simply represents the infrastructure behind a pub-sub system. This is where Messages live.

Examples could include a key/value store, Google Pub/Sub, or Amazon SNS + SQS.

Message

A Message represents a discrete unit of data. It contains a body and a list of attributes. Attributes can be used to distinguish unique properties of a Message, including how to read the body. More on that in [decorator patterns][].

Publish

A Message is published to a Topic. A Topic writes the body and attributes of a Message to a backend using a MessageWriter. A MessageWriter may only be used for one Message, much like a net/http ResponseWriter

When the MessageWriter is closed, the data that was written to it will be published to that backend and it will no longer be able to be used.

Subscribe

A Server subscribes to Messages from a backend. It's important to note that a Server must know how to convert raw data to a Message - this will be unique to each backend. For example, the way you read message attributes from a file is very different from how you read them from SQS. A Server is always live, so it will continue to block indefinitely while it is waiting for messages until it is shut down.

When a Message is created, the Server passes it to a Receiver for processing. This is similar to how net/http Handler works. A Receiver may return an error if it was unable to process the Message. This will indicate to the Server that the Message must be retried. The specifics to this retry logic will be specific to each backend.

Benefits

This library was originally conceived because we needed a way to reduce copy-pasted code across our pub-sub systems and we wanted to try out other infrastructures.

These primitives allow us to achieve both of those goals. Want to try out Kafka instead of AWS? No problem! Just write a library that utilizes these primitives and the Kafka SDK.

What these primitives or any implementation of these primitives DO NOT DO is mask or replace all of the functionality of all infrastructures. If you want to use a particular feature of AWS that does not fit with these primitives, that's OK. It might make sense to add that feature to the primitives, it might not. We encourage you to open an issue to discuss such additions.

Aside from the code re-use benefits, there's a number of other features which we believe are useful, including:

  • Concrete implementations can be written once and distributed as libraries.

  • Decorator Patterns

  • Built-in concurrency controls into Server.

  • Context deadlines and cancellations. This allows for clean shutdowns to prevent data loss.

  • Transaction-based Receivers.

go-msg's People

Contributors

dvrkps avatar shezadkhan137 avatar tmessi avatar xopherus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-msg's Issues

Calling Attributes.Set panic when Attributes is nil

my code like this.

m := &msg.Message{}
m.Attributes.Set("aa", "aaa")

error message is this.

panic: assignment to entry in nil map

It is necessary to makeAttributes for msg.Message if msg.Message.Attributes is nil when call Set function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.