pubsub

package module
v0.0.0-...-0972d97 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2018 License: MIT Imports: 2 Imported by: 0

README

PubSub

Pub/Sub interface and implementations for

  • Dummy: dummy implementation without message transmission
  • Mem: exchange in app memory
  • RabbitMQ

Todo implementations

  • Kafka
  • ZMQ

Interface

Published - publish the messages Subscriber - listen for messages Message - interface that wraps messages that receives the Subscriber

Interfaces provide methods to register functions for Marshaling and UnMarshaling.

Publishing
  1. Create new Published and attach Marshaller to it
  2. Publish you variable foo with Publisher.Publish(foo). Marshalling happens in Publisher.Publish method
Subscription
  1. Create new Subscriber
  2. Attach unmarshaller
  3. Listen for incoming messages on channel from Subscriber.Start
  4. Each message could be unmarshalled by calling message.UnMarshal(&structure)
type Publisher interface {
	Marshaller(marshaller Marshaller)
	Publish(context.Context, string, interface{}) error
	Errors() <-chan error
}

type Subscriber interface {
	UnMarshaller(unmarshaller UnMarshaller)
	Start() <-chan Message
	Errors() <-chan error
	Stop() error
}

type Message interface {
	UnMarshal(interface{}) error
	Done() error
}

Contributors

  1. Sergey Chebotar - design / rabbitmq implementation
  2. Stan Shulga - examples for rabbitmq

Documentation

Index

Constants

View Source
const (
	NoMarshaller   = "marshaller not specified"
	NoUnMarshaller = "unmarshaller not specified"
)

Variables

View Source
var ErrorNoMarshaller = errors.New(NoMarshaller)
View Source
var ErrorNoUnMarshaller = errors.New(NoUnMarshaller)

Functions

This section is empty.

Types

type Marshaller

type Marshaller func(interface{}) ([]byte, error)

type Message

type Message interface {
	UnMarshal(interface{}) error
	Done() error
}

type Publisher

type Publisher interface {
	Publish(context.Context, string, interface{}) error
	Errors() <-chan error
}

type Subscriber

type Subscriber interface {
	Start() <-chan Message
	Errors() <-chan error
	Stop() error
}

type UnMarshaller

type UnMarshaller func(source []byte, destination interface{}) error

Directories

Path Synopsis
example
mem
rabbitmq/message
Package message is a generated protocol buffer package.
Package message is a generated protocol buffer package.
marshalling
gob

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL