spark

package
v0.34.4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 11 Imported by: 1

README

spark

Package spark implements a simple pub/sub mechanism that allows clients to watch resources.

WebSocket

To watch resources, the client initiates a WebSocket connection to the group action:

wss://example.com/v1/api/watch

And then subscribes to streams:

{
  "subscribe": {
    "items": {
      "state": true
    } 
  }
}

The server then forwards matching events to the client:

{
  "items": {
    "5c880eb87b0a67df9a6a2efc": "created"
  } 
}

If necessary, the client can unsubscribe from streams:

{
  "unsubscribe": ["items"]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event added in v0.17.0

type Event struct {
	// Type specifies the event type.
	Type coal.Event

	// ID is the ID of the changed resource.
	ID coal.ID

	// Model is the changed model.
	//
	// Note: The model is unavailable for deleted events unless soft delete
	// has been enabled.
	Model coal.Model

	// Stream is the stream this event originated from.
	Stream *Stream
}

Event describes an event.

type Map added in v0.17.0

type Map map[string]interface{}

Map holds custom data for a subscription.

type Stream added in v0.17.0

type Stream struct {
	// Model defines the model this stream is associated with.
	Model coal.Model

	// Store defines the store to use for opening the stream.
	Store *coal.Store

	// Validator is the callback used to validate subscriptions on the stream.
	Validator func(*Subscription) error

	// Selector is the callback used to decide which events are forwarded to
	// a subscription.
	Selector func(*Event, *Subscription) bool

	// SoftDelete can be set to true to support soft deleted documents.
	SoftDelete bool
	// contains filtered or unexported fields
}

Stream describes a single model stream and how clients can subscribe to it.

func (*Stream) Name added in v0.17.0

func (s *Stream) Name() string

Name returns the name of the stream.

type Subscription added in v0.17.0

type Subscription struct {
	// Context is the original context of the request.
	Context *fire.Context

	// Data is the user-defined data bag.
	Data Map

	// Stream is the subscribed stream.
	Stream *Stream
}

Subscription is a single subscription to a stream by a client.

type Watcher added in v0.17.0

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

Watcher will watch multiple collections and serve watch requests by clients.

func NewWatcher added in v0.17.0

func NewWatcher(reporter func(error)) *Watcher

NewWatcher creates and returns a new watcher.

func (*Watcher) Action added in v0.17.0

func (w *Watcher) Action() *fire.Action

Action returns an action that should be registered in the group under the "watch" name.

func (*Watcher) Add added in v0.17.0

func (w *Watcher) Add(stream *Stream)

Add will add a stream to the watcher.

func (*Watcher) Close added in v0.20.0

func (w *Watcher) Close()

Close will close the watcher and all opened streams.

Jump to

Keyboard shortcuts

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