dispatch

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnotationsType    = "Annotations"
	ArticleContentType = "Article"
	ContentPackageType = "ContentPackage"
	AudioContentType   = "Audio"
	AllContentType     = "All"
)

subscription types

View Source
const (
	ContentUpdateType    = "http://www.ft.com/thing/ThingChangeType/UPDATE"
	ContentDeleteType    = "http://www.ft.com/thing/ThingChangeType/DELETE"
	AnnotationUpdateType = "http://www.ft.com/thing/ThingChangeType/ANNOTATIONS_UPDATE"
)

notification types

View Source
const (
	RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
)

Variables

View Source
var ErrSubLagging = errors.New("subscriber lagging behind")

Functions

func MarshalNotificationsJSON

func MarshalNotificationsJSON(n []Notification) ([]byte, error)

MarshalNotificationsJSON returns the JSON encoding of n. For notifications, we do not use the standard function json.Marshal() because that will always escape special characters (<,>,&) in unicode format ("\u0026P" and similar)

Types

type Dispatcher

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

func NewDispatcher

func NewDispatcher(delay time.Duration, history History, log *logger.UPPLogger) *Dispatcher

NewDispatcher creates and returns a new Dispatcher Delay argument configures minimum delay between send notifications History is a system that collects a list of all notifications send by Dispatcher

func (*Dispatcher) Send

func (d *Dispatcher) Send(n Notification)

func (*Dispatcher) Start

func (d *Dispatcher) Start()

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

func (*Dispatcher) Subscribe added in v4.2.1

func (d *Dispatcher) Subscribe(address string, subType string, monitoring bool) Subscriber

func (*Dispatcher) Subscribers

func (d *Dispatcher) Subscribers() []Subscriber

func (*Dispatcher) Unsubscribe added in v4.2.1

func (d *Dispatcher) Unsubscribe(subscriber Subscriber)

type History

type History interface {
	Push(notification Notification)
	Notifications() []Notification
}

History contains the last x notifications pushed out to subscribers.

func NewHistory

func NewHistory(size int) History

NewHistory creates a new history type

type MonitorSubscriber added in v4.2.1

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

monitorSubscriber implements a Monitor subscriber

func NewMonitorSubscriber

func NewMonitorSubscriber(address string, subType string) *MonitorSubscriber

NewMonitorSubscriber returns a new instance of a Monitor subscriber

func (*MonitorSubscriber) Address added in v4.2.1

func (m *MonitorSubscriber) Address() string

func (*MonitorSubscriber) ID added in v4.2.1

func (m *MonitorSubscriber) ID() string

func (*MonitorSubscriber) MarshalJSON added in v4.2.1

func (m *MonitorSubscriber) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of a MonitorSubscriber

func (*MonitorSubscriber) Notifications added in v4.2.1

func (m *MonitorSubscriber) Notifications() <-chan string

func (*MonitorSubscriber) Send added in v4.2.1

func (*MonitorSubscriber) Since added in v4.2.1

func (m *MonitorSubscriber) Since() time.Time

func (*MonitorSubscriber) SubType added in v4.2.1

func (m *MonitorSubscriber) SubType() string

type Notification

type Notification struct {
	APIURL           string    `json:"apiUrl"`
	ID               string    `json:"id"`
	Type             string    `json:"type"`
	SubscriberID     string    `json:"subscriberId,omitempty"`
	PublishReference string    `json:"publishReference,omitempty"`
	LastModified     string    `json:"lastModified,omitempty"`
	NotificationDate string    `json:"notificationDate,omitempty"`
	Title            string    `json:"title,omitempty"`
	Standout         *Standout `json:"standout,omitempty"`
	SubscriptionType string    `json:"-"`
}

Notification model

type NotificationConsumer added in v4.2.1

type NotificationConsumer interface {
	Subscriber
	Send(n Notification) error
}

type StandardSubscriber added in v4.2.1

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

StandardSubscriber implements a standard subscriber

func NewStandardSubscriber

func NewStandardSubscriber(address string, subType string) *StandardSubscriber

NewStandardSubscriber returns a new instance of a standard subscriber

func (*StandardSubscriber) Address added in v4.2.1

func (s *StandardSubscriber) Address() string

Address returns the IP address of the standard subscriber

func (*StandardSubscriber) ID added in v4.2.1

func (s *StandardSubscriber) ID() string

Id returns the uniquely generated subscriber identifier Returned value is assigned during the construction phase.

func (*StandardSubscriber) MarshalJSON added in v4.2.1

func (s *StandardSubscriber) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of a StandardSubscriber

func (*StandardSubscriber) Notifications added in v4.2.1

func (s *StandardSubscriber) Notifications() <-chan string

Notifications returns the channel that can provides serialized notifications send to the subscriber

func (*StandardSubscriber) Send added in v4.2.1

Send tries to send notification to the subscriber. It removes the monitoring fields from the notification. Serializes it as string and pushes it to the subscriber

func (*StandardSubscriber) Since added in v4.2.1

func (s *StandardSubscriber) Since() time.Time

Since returns the time since a subscriber have been registered

func (*StandardSubscriber) SubType added in v4.2.1

func (s *StandardSubscriber) SubType() string

SubType returns the accepted subscription type for which notifications are returned

type Standout

type Standout struct {
	Scoop bool `json:"scoop"`
}

Standout model for a Notification

type Subscriber

type Subscriber interface {
	ID() string
	Notifications() <-chan string
	Address() string
	Since() time.Time
	SubType() string
}

Subscriber represents the interface of a generic subscriber to a push stream

type SubscriberPayload

type SubscriberPayload struct {
	ID                 string `json:"id"`
	Address            string `json:"address"`
	Since              string `json:"since"`
	ConnectionDuration string `json:"connectionDuration"`
	Type               string `json:"type"`
}

SubscriberPayload is the JSON representation of a generic subscriber

Jump to

Keyboard shortcuts

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