Skip to content

Publish and subscribe to messages using standard interfaces.

License

Notifications You must be signed in to change notification settings

TomWright/deliver

Repository files navigation

Build Status codecov Documentation

deliver

go get -u github.com/tomwright/deliver

Publish + consume messages with standard interfaces.

Quick Start

This quick start assumes you already have your Subscriber or Producer created already.

For information on creating those objects, see Implementations below.

Message

Below is an example message that may be published when a user has been created.

type UserCreated struct {
	Username string `json:"username"`
}

func (m *UserCreated) Type() string {
	return "user.created"
}

func (m *UserCreated) Payload() ([]byte, error) {
	return json.Marshal(m)
}

func (m *UserCreated) WithPayload(bytes []byte) error {
	return json.Unmarshal(bytes, m)
}

Publishing

Subscribing

Implementations

Kafka

  • Message.Type() response is used as the topic.
  • Messages are marked before the given ConsumerFn is executed.

Setup:

brokers := []string{"cmg-local-kafka:9092"}
publisher, err := deliver.NewKafkaPublisher(brokers)
subscriber := deliver.NewKafkaSubscriber(brokers)