mybus

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PublishService - Client service method
	PublishService = "ClientService.PushEvent"
)
View Source
const (
	// RegisterService - Server subscribe service method
	RegisterService = "ServerService.Register"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BusPublisher

type BusPublisher interface {
	Publish(key string, args ...any)
	HasCallback(key string) bool
	WaitAsync()
}

发布标准

type BusSubscriber

type BusSubscriber interface {
	Subscribe(key string, fn any) error
	SubscribeAsync(key string, fn any) error
	SubscribeOnce(key string, fn any) error
	SubscribeOnceAsync(key string, fn any) error
	Unsubscribe(key string, fn any)
}

订阅标准

type ClientArg

type ClientArg struct {
	Args  []interface{}
	Topic string
}

ClientArg - object containing event for client to publish locally

type ClientBus

type ClientBus interface {
	RpcBus
	Subscribe(key string, fn any, serverAddr, serverPath string) error
	SubscribeOnce(key string, fn any, serverAddr, serverPath string) error
	ClientService() *ClientService
}

func NewClient

func NewClient(address, path string, bus EventBus) ClientBus

NewClient - create a client object with the address and server path

type ClientService

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

ClientService - service object listening to events published in a remote event bus

func (*ClientService) PushEvent

func (service *ClientService) PushEvent(arg *ClientArg, reply *bool) error

PushEvent - exported service to listening to remote events

type EventBus

type EventBus interface {
	BusSubscriber
	BusPublisher
}

func NewEventBus

func NewEventBus() EventBus

type NetworkBus

type NetworkBus interface {
	ClientBus
	ServerBus
}

func NewNetworkBus

func NewNetworkBus(address, path string) NetworkBus

NewNetworkBus - returns a new network bus object at the server address and path

type NetworkService

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

NetworkBusService - object capable of serving the network bus

type RpcBus

type RpcBus interface {
	Start() error
	Stop()
	ServerAddr() string
	ServerPath() string
	Bus() EventBus
}

type ServerBus

type ServerBus interface {
	RpcBus
	RegisterType(param any)
	HasClientSubscribed(arg *SubscribeArg) bool
	ClientSubscribed() *mymap.MultiMap[string, *SubscribeArg]
	RPCCallback(arg *SubscribeArg) func(args ...interface{})
	ServerService() *ServerService
}

func NewServer

func NewServer(address, path string, bus EventBus) ServerBus

NewServer - create a new Server at the address and path

type ServerService

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

ServerService - service object to listen to remote subscriptions

func (*ServerService) Register

func (service *ServerService) Register(arg *SubscribeArg, success *bool) error

Register - Registers a remote handler to this event bus for a remote subscribe - a given client address only needs to subscribe once event will be republished in local event bus

type SubscribeArg

type SubscribeArg struct {
	ClientAddr    string
	ClientPath    string
	ServiceMethod string
	SubscribeType SubscribeType
	Topic         string
}

SubscribeArg - object to hold subscribe arguments from remote event handlers

type SubscribeType

type SubscribeType int

SubscribeType - how the client intends to subscribe

const (
	// Subscribe - subscribe to all events
	Subscribe SubscribeType = iota
	// SubscribeOnce - subscribe to only one event
	SubscribeOnce
)

Jump to

Keyboard shortcuts

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