messages

package
v0.0.0-...-bd111a6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventDefinition

type EventDefinition struct {
	Providers         []*ProviderDefinition `yaml:"messageProviders,omitempty"`
	EventDestinations []*EventNode          `yaml:"eventDestinations,omitempty"`
}

EventDefinition contains providers, event sources, and event destinations.

type EventNode

type EventNode struct {
	Name        string `yaml:"name"`
	Topic       string `yaml:"topic"`
	ProviderRef string `yaml:"providerRef"`
}

EventNode represents either an event source or destination and consists of a provider reference and the topic to either send to or receive from.

type Provider

type Provider interface {
	// Send a new message to an eventDestination.
	// The first parameter is message body. The second parameter is optional header or context
	Send(*EventNode, []byte, interface{}) error
	// Subscribe to eventDefinition from an eventSource.
	Subscribe(*EventNode) error
	// Receive a message from an eventSource. The timeout can be configured by setting the timeout (in seconds) on the messageProvider.
	Receive(*EventNode) ([]byte, error)
	// Listen for eventDefinition on an eventSource and calls the specified ReceiverFunc on the event payload.
	ListenAndServe(*EventNode, ReceiverFunc)
}

Provider must be implemented for whichever messaging provider to be supported.

type ProviderDefinition

type ProviderDefinition struct {
	Name          string        `yaml:"name"`
	ProviderType  string        `yaml:"providerType"`
	URL           string        `yaml:"url"`
	Timeout       time.Duration `yaml:"timeout"`
	SkipTLSVerify bool          `yaml:"skipTLSVerify,omitempty"`
}

ProviderDefinition describes a message provider and its URLs.

type ReceiverFunc

type ReceiverFunc func([]byte)

ReceiverFunc is called when an event is received from an event source.

type Service

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

Service contains the event definition and registered providers.

func NewService

func NewService(fileName string) (*Service, error)

NewService initializes the message providers, and event sources and destinations.

func (*Service) GetEventDefinition

func (s *Service) GetEventDefinition() *EventDefinition

GetEventDefinition returns the structure for eventDefinitions.yaml.

func (*Service) GetNode

func (s *Service) GetNode(name string) *EventNode

GetNode returns the node with the name `name`.

func (*Service) GetProvider

func (s *Service) GetProvider(name string) Provider

GetProvider returns the provider with the name `name`.

func (*Service) Register

func (s *Service) Register(name string, mp Provider) error

Register a new provider.

func (*Service) Send

func (s *Service) Send(dest string, body []byte, other interface{}) error

Send a message to the destination with the name `dest`.

Jump to

Keyboard shortcuts

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