unifrost: github.com/unifrost/unifrost Index | Files | Directories

package unifrost

import "github.com/unifrost/unifrost"

Package unifrost is a go module for relaying pubsub messages to the web using SSE(Eventsource). It is based on Twitter's implementation for real-time event-streaming in their new web app.

Supported brokers

Google Cloud Pub/Sub
Amazon Simple Queueing Service
Azure Service Bus (Pending)
RabbitMQ
NATS
Kafka
In-memory (Only for testing)

For examples check https://github.com/unifrost/unifrost/tree/master/examples/

Index

Package Files

client.go doc.go streamer.go

Variables

var (
    // ErrNoClient is returned if the client-id is not registered in the streamer.
    ErrNoClient = errors.New("streamer: Client doesn't exists")
)

type Client Uses

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

Client manages all the topic subscriptions.

func (*Client) Close Uses

func (client *Client) Close(ctx context.Context) error

Close closes the client and shutdowns all the subscriptions.

func (*Client) Connected Uses

func (client *Client) Connected() bool

Connected reports whether client is connected to the server.

func (*Client) GetTopics Uses

func (client *Client) GetTopics(ctx context.Context) []string

GetTopics returns a slice of all the topics the client is subscribed to.

func (*Client) TotalTopics Uses

func (client *Client) TotalTopics(ctx context.Context) int

TotalTopics returns the number of topics the client is subscribed to.

type Option Uses

type Option func(*Streamer) error

Option is a self-refrential function for configuration parameters

func ClientTTL Uses

func ClientTTL(t time.Duration) Option

ClientTTL is an option that is used to set the client's TTL default TTL is 1 minute

type Streamer Uses

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

Streamer handles all the clients and subscriptions. It implements the http.Handler interface for easy embedding with any API server.

func NewStreamer Uses

func NewStreamer(subClient drivers.SubscriberClient, options ...Option) (*Streamer, error)

NewStreamer returns *unifrost.Streamer, handles all the clients and subscriptions.

Additional configuration options can be added with unifrost.Option functions.

func (*Streamer) Close Uses

func (streamer *Streamer) Close(ctx context.Context) error

Close closes the streamer and also closes all the connected clients.

func (*Streamer) GetClient Uses

func (streamer *Streamer) GetClient(ctx context.Context, clientID string) *Client

GetClient returns *unifrost.Client, the client instance of the specified clientID.

func (*Streamer) NewClient Uses

func (streamer *Streamer) NewClient(ctx context.Context) (*Client, error)

NewClient returns *unifrost.Client, creates a new client with an autogenerated client-id.

func (*Streamer) NewCustomClient Uses

func (streamer *Streamer) NewCustomClient(ctx context.Context, clientID string) (*Client, error)

NewCustomClient returns *unifrost.Client, creates a new client with the specified clientID.

func (*Streamer) RemoveClient Uses

func (streamer *Streamer) RemoveClient(ctx context.Context, clientID string) error

RemoveClient removes the specified client from closes and removes it.

func (*Streamer) ServeHTTP Uses

func (streamer *Streamer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the http handler for eventsource. For connecting query parameter 'id' is required i.e client-id.

func (*Streamer) Subscribe Uses

func (streamer *Streamer) Subscribe(ctx context.Context, clientID string, topic string) error

Subscribe subscribes the specified client to the specified topic. If specified client doesn't exists ErrNoClient error is returned.

func (*Streamer) TotalClients Uses

func (streamer *Streamer) TotalClients(ctx context.Context) int

TotalClients returns the number of client connected to the streamer.

func (*Streamer) Unsubscribe Uses

func (streamer *Streamer) Unsubscribe(ctx context.Context, clientID string, topic string) error

Unsubscribe method unsubscribes the specified client to the specified topic and shutdowns the subscription. If specified client doesn't exists ErrNoClient error is returned.

Directories

PathSynopsis
driversPackage drivers contains all the drivers required to connect to different brokers, under a single easy to use interface.
drivers/gcpdriver
drivers/kafkadriver
drivers/memdriver
drivers/natsdriver
drivers/rabbitdriver
drivers/sqsdriver

Package unifrost imports 12 packages (graph). Updated 2020-01-12. Refresh now. Tools for package owners.