hub

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: CC0-1.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

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

Hub - Abstraction between message publishers & subscribers, works as a multiplexer ( or router )

func New

func New(ctx context.Context, addr string, cap uint64) (*Hub, error)

New - Creates a new instance of hub, ready to be used

func (*Hub) AddSubscription

func (h *Hub) AddSubscription(subId uint64, conn net.Conn, topics ...string) uint32

AddSubscription - Subscriber showing intent of receiving messages from a non-empty set of topics [ on-the-fly i.e. after subscriber has been registered ]

func (*Hub) Evict

func (h *Hub) Evict(ctx context.Context, running chan struct{})

Evict - As soon as it's determined peer is not anymore connected & it didn't follow graceful tear down ( didn't unsubscribe from topics ) its entry from subscription table to be evicted

func (*Hub) Listen

func (h *Hub) Listen(ctx context.Context, addr string, done chan bool)

Listen - Hub listens for TCP connections, accepts those & spawns new go routine for handling each of those

func (*Hub) Next

func (h *Hub) Next() *ops.Msg

next - Next queued message to act on, if any

func (*Hub) Process

func (h *Hub) Process(ctx context.Context, running chan struct{})

Process - Listens for new message ready to published & works on publishing it to all topic subscribers

func (*Hub) Publish

func (h *Hub) Publish(msg *ops.Msg) uint32

Publish - Message publish request to be enqueued for some worker to process, while this function will calcalate how many clients will receive this message & respond back

func (*Hub) Queued

func (h *Hub) Queued() bool

queued - Manager to check whether it has anything to act on

func (*Hub) Subscribe

func (h *Hub) Subscribe(conn net.Conn, topics ...string) (uint64, uint32)

Subscribe - Client sends subscription request with a non-empty list of topics it's interested in, for very first time, which is why one unique id to be generated

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(subId uint64, topics ...string) uint32

Unsubscribe - Subscriber shows intent of not receiving messages from non-empty set of topics

Jump to

Keyboard shortcuts

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