pubsub

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionPut    = "put"
	ActionDelete = "delete"
)

const

View Source
const (
	EventKVChange = "kv-changed"
)

const

Variables

This section is empty.

Functions

func Init

func Init()

Init create serf agent

func ObserveOnce

func ObserveOnce(o *Observer, topic *Topic) error

ObserveOnce observe key changes by (key or labels) or (key and labels)

func Publish

func Publish(event *KVChangeEvent) error

Publish send event

func Start

func Start()

Start start serf agent

Types

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus is message bug

type EventHandler

type EventHandler struct {
}

EventHandler handler serf custom event

func (*EventHandler) HandleEvent

func (h *EventHandler) HandleEvent(e serf.Event)

HandleEvent send event to subscribers

type KVChangeEvent

type KVChangeEvent struct {
	Key      string
	Action   string //include: put,delete
	Labels   map[string]string
	DomainID string
	Project  string
}

KVChangeEvent is event between kie nodes, and broadcast by serf

func NewKVChangeEvent

func NewKVChangeEvent(payload []byte) (*KVChangeEvent, error)

NewKVChangeEvent create a struct base on event payload

type Observer

type Observer struct {
	UUID      string
	RemoteIP  string
	UserAgent string
	Event     chan *KVChangeEvent
}

Observer represents a client polling request

type Options

type Options struct {
	BindAddr      string
	AdvertiseAddr string
	RPCAddr       string
}

Options is serf options

type Topic

type Topic struct {
	Key          string            `json:"key,omitempty"`
	Labels       map[string]string `json:"-"`
	LabelsFormat string            `json:"labels,omitempty"`
	DomainID     string            `json:"domainID,omitempty"`
	Project      string            `json:"project,omitempty"`
	MatchType    string            `json:"match,omitempty"`
}

Topic can be subscribe

func ParseTopicString

func ParseTopicString(s string) (*Topic, error)

ParseTopicString parse topic string to topic struct

func (*Topic) Match

func (t *Topic) Match(event *KVChangeEvent) bool

Match compare event with topic If the match type is set to exact in long pulling request, only update request with exactly the same label of pulling request will match the request and will trigger an immediate return.

If the match type is not set, it will be matched when pulling request labels is equal to update request labels or a subset of it.

Jump to

Keyboard shortcuts

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