pubsub

package
v0.0.0-...-96bfa84 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

README

Pub Sub

Pub Subs provide a common way to interact with different message bus implementations to achieve reliable, high-scale scenarios based on event-driven async communications, while allowing users to opt-in to advanced capabilities using defined metadata.

Currently supported pub-subs are:

  • Redis Streams

Implementing a new Pub Sub

A compliant pub sub needs to implement the following interface:

type PubSub interface {
	Init(metadata Metadata) error
	Publish(req *PublishRequest) error
	Subscribe(req SubscribeRequest, handler func(msg *NewMessage) error) error
}

Documentation

Index

Constants

View Source
const (
	// DefaultCloudEventType is the default event type for an Actions published event
	DefaultCloudEventType = "com.actions.event.sent"
	// CloudEventsSpecVersion is the specversion used by Actions for the cloud events implementation
	CloudEventsSpecVersion = "0.3"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudEventsEnvelope

type CloudEventsEnvelope struct {
	ID              string      `json:"id"`
	Source          string      `json:"source"`
	Type            string      `json:"type"`
	SpecVersion     string      `json:"specversion"`
	DataContentType string      `json:"datacontenttype"`
	Data            interface{} `json:"data"`
}

CloudEventsEnvelope describes the Actions implementation of the Cloud Events spec Spec details: https://github.com/cloudevents/spec/blob/master/spec.md

func NewCloudEventsEnvelope

func NewCloudEventsEnvelope(id, source, eventType string, data []byte) *CloudEventsEnvelope

NewCloudEventsEnvelope returns a new CloudEventsEnvelope

type Metadata

type Metadata struct {
	Properties map[string]string `json:"properties"`
}

Metadata represents a set of message-bus specific properties

type MockPubSub

type MockPubSub struct {
	mock.Mock
}

func (*MockPubSub) Init

func (m *MockPubSub) Init(metadata Metadata) error

func (*MockPubSub) Publish

func (m *MockPubSub) Publish(req *PublishRequest) error

func (*MockPubSub) Subscribe

func (m *MockPubSub) Subscribe(req SubscribeRequest, handler func(msg *NewMessage) error) error

type NewMessage

type NewMessage struct {
	Data  []byte `json:"data"`
	Topic string `json:"topic"`
}

NewMessage is an event arriving from a message bus instance

type PubSub

type PubSub interface {
	Init(metadata Metadata) error
	Publish(req *PublishRequest) error
	Subscribe(req SubscribeRequest, handler func(msg *NewMessage) error) error
}

PubSub is the interface for message buses

type PublishRequest

type PublishRequest struct {
	Data  []byte `json:"data"`
	Topic string `json:"topic"`
}

PublishRequest is the request to publish a message

type SubscribeRequest

type SubscribeRequest struct {
	Topic string `json:"topic"`
}

SubscribeRequest is the request to subscribe to a topic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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