messaging

package
v0.1.6-0...-5c25bcb Latest Latest
Warning

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

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

Documentation

Overview

Package messaging enables the agent to perform many messaging features. Agent can register/unregister message services. Send/Reply to messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicNotifier

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

BasicNotifier is channel based implementation of basic notifier.

func NewNotifier

func NewNotifier(connection chan NotificationPayload, filter FilterNotification) *BasicNotifier

NewNotifier return notifier instance.

func (*BasicNotifier) Notify

func (n *BasicNotifier) Notify(topic string, message []byte) error

Notify sends the given message to the subscribers based on filter logic.

type Client

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

Client enable access to messaging features.

func New

func New(ctx provider, registrar MessageHandler, notifier Notifier) (*Client, error)

New return new instance of message client.

func (*Client) RegisterService

func (c *Client) RegisterService(name, msgType string, purpose ...string) error

RegisterService registers new message service to message handler registrar.

func (*Client) Reply

func (c *Client) Reply(ctx context.Context, msg json.RawMessage, msgID string, startNewThread bool,
	waitForResponse string) (json.RawMessage, error)

Reply sends reply to existing message.

func (*Client) Send

func (c *Client) Send(msg json.RawMessage, opts ...SendMessageOpions) (json.RawMessage, error)

Send sends new message based on destination options provided.

func (*Client) Services

func (c *Client) Services() []string

Services returns list of registered service names.

func (*Client) UnregisterService

func (c *Client) UnregisterService(name string) error

UnregisterService unregisters given message service handler registrar.

type FilterNotification

type FilterNotification func(string, []byte) bool

FilterNotification filters incoming notifications.

type MessageHandler

type MessageHandler interface {
	// Services returns list of available message services in this message handler
	Services() []dispatcher.MessageService
	// Register registers given message services to this message handler
	Register(msgSvcs ...dispatcher.MessageService) error
	// Unregister unregisters message service with given name from this message handler
	Unregister(name string) error
}

MessageHandler maintains registered message services and it allows dynamic registration of message services.

type NotificationPayload

type NotificationPayload struct {
	Topic string
	Raw   []byte
}

NotificationPayload represent notification payload.

type Notifier

type Notifier interface {
	Notify(topic string, message []byte) error
}

Notifier represents a notification dispatcher.

type SendMessageOpions

type SendMessageOpions func(opts *sendMsgOpts)

SendMessageOpions is the options for choosing message destinations.

func SendByConnectionID

func SendByConnectionID(connectionID string) SendMessageOpions

SendByConnectionID option to choose message destination by connection ID.

func SendByDestination

func SendByDestination(destination *service.Destination) SendMessageOpions

SendByDestination option to set message destination.

func SendByTheirDID

func SendByTheirDID(theirDID string) SendMessageOpions

SendByTheirDID option to choose message destination by connection ID.

func WaitForResponse

func WaitForResponse(ctx context.Context, responseType string) SendMessageOpions

WaitForResponse option to set message response type. Message reply will wait for the response of this message type and matching thread ID.

Jump to

Keyboard shortcuts

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