notification2

package
v0.15.10 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	SourceWildcard = "*"
	ActionWildcard = "*"
)
View Source
const (
	// MaximumRetryInterval is the maximum interval (in seconds) between reconnection attempts
	MaximumRetryInterval int64 = 300

	// MinimumRetryInterval is the minimum interval (in seconds) between reconnection attempts
	MinimumRetryInterval int64 = 5

	// RetryBackoffFactor is the backoff factor applied to the retry interval for every unsuccessful reconnection attempt.
	// i.e. the next retry interval is calculated as followins
	// interval = MinimumRetryInterval
	// interval = Min(MaximumRetryInterval, interval * RetryBackoffFactor)
	RetryBackoffFactor float64 = 2
)

Variables

Functions

func SetLogger

func SetLogger(log logger.Logger)

Types

type ActionType

type ActionType string
var ActionTypeCreate ActionType = "CREATE"
var ActionTypeDelete ActionType = "DELETE"
var ActionTypeUpdate ActionType = "UPDATE"

type ClientSubscription

type ClientSubscription struct {
	Pattern  string
	Action   string
	Out      chan<- Message
	Disabled bool
}

type ConnectionOptions

type ConnectionOptions struct {
	// Send pings to client with this interval. Must be less than pongWait.
	PingInterval time.Duration
	PongWait     time.Duration
	WriteWait    time.Duration
	Insecure     bool
}

func (*ConnectionOptions) GetPingDuration

func (o *ConnectionOptions) GetPingDuration() time.Duration

func (*ConnectionOptions) GetPongDuration

func (o *ConnectionOptions) GetPongDuration() time.Duration

func (*ConnectionOptions) GetWriteDuration

func (o *ConnectionOptions) GetWriteDuration() time.Duration

type Hub

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

Hub maintains the set of active subscriptions and broadcasts messages to the clients.

func NewHub

func NewHub() *Hub

func (*Hub) Run

func (h *Hub) Run()

type Message

type Message struct {
	Identifier  []byte `json:"identifier"`
	Description []byte `json:"description"`
	Action      []byte `json:"action"`
	Payload     []byte `json:"data,omitempty"`
}

Message is the type delivered to subscribers.

func (*Message) JSON

func (m *Message) JSON() gjson.Result

type Notification2Client

type Notification2Client struct {
	Subscription      Subscription
	ConnectionOptions ConnectionOptions
	// contains filtered or unexported fields
}

Notification2Client is a client used for the notification2 interface

func NewNotification2Client

func NewNotification2Client(host string, wsDialer *websocket.Dialer, subscription Subscription, options ConnectionOptions) *Notification2Client

NewNotification2Client initializes a new notification2 client used to subscribe to realtime notifications from Cumulocity

func (*Notification2Client) Close

func (c *Notification2Client) Close() error

Close the connection

func (*Notification2Client) Connect

func (c *Notification2Client) Connect() error

Connect performs a handshake with the server and will repeatedly initiate a websocket connection until `Close` is called on the client.

func (*Notification2Client) Endpoint

func (c *Notification2Client) Endpoint() string

func (*Notification2Client) IsConnected

func (c *Notification2Client) IsConnected() bool

IsConnected returns true if the websocket is connected

func (*Notification2Client) Register

func (c *Notification2Client) Register(pattern string, out chan<- Message)

func (*Notification2Client) SendMessageAck

func (c *Notification2Client) SendMessageAck(messageIdentifier []byte) error

func (*Notification2Client) URL

func (c *Notification2Client) URL() string

func (*Notification2Client) Unsubscribe

func (c *Notification2Client) Unsubscribe() error

Unsubscribe unsubscribe to a given pattern

type Subscription

type Subscription struct {
	Consumer string `json:"consumer,omitempty"`
	Token    string `json:"token,omitempty"`

	TokenRenewal func(string) (string, error)
}

Jump to

Keyboard shortcuts

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