package rmb
import "github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go"
Index ¶
- Constants
- Variables
- func GetTwinID(ctx context.Context) uint32
- func LoggerMiddleware(ctx context.Context, payload []byte) (context.Context, error)
- func NewRedisPool(address string, size ...uint32) (*redis.Pool, error)
- type Client
- func Default() (Client, error)
- func NewRMBClient(address string, poolSize ...uint32) (Client, error)
- type DefaultRouter
- func NewRouter(address string) (*DefaultRouter, error)
- func (m *DefaultRouter) Handlers() []string
- func (m *DefaultRouter) Run(ctx context.Context) error
- func (m *DefaultRouter) Subroute(prefix string) Router
- func (m *DefaultRouter) Use(mw Middleware)
- func (m *DefaultRouter) WithHandler(topic string, handler Handler)
- type Error
- type Handler
- type Incoming
- type IncomingResponse
- type Middleware
- type OutgoingResponse
- type RemoteError
- type Request
- type Router
Constants ¶
const ( DefaultSchema = "application/json" // DefaultAddress default redis address when no address is passed DefaultAddress = "tcp://127.0.0.1:6379" )
Variables ¶
var ( // ErrFunctionNotFound is an err returned if the handler function is not found ErrFunctionNotFound = fmt.Errorf("function not found") )
Functions ¶
func GetTwinID ¶
GetTwinID returns the twin id from context.
func LoggerMiddleware ¶
LoggerMiddleware simple logger middleware.
func NewRedisPool ¶
Types ¶
type Client ¶
type Client interface { Call(ctx context.Context, twin uint32, fn string, data interface{}, result interface{}) error }
Client is an rmb abstract client interface.
func Default ¶
Default return instance of to default (local) rmb shortcut for NewClient(DefaultAddress)
func NewRMBClient ¶
NewRMBClient creates a new rmb client that runs behind an rmb-peer. This client does not talk to the rmb relay directly, instead talk to an rmb-peer instance (like a gateway) that itself maintains a connection to the relay. the rmb-peer does all the heavy lifting, including signing, encryption, validation of the response, etc...
hence the address in this case, is an address to the local redis that must be the same one used with the rmb-peer process.
for more details about rmb-peer please check https://github.com/threefoldtech/rmb-rs Since the rmb protocol does not specify a "payload" format this Client and the DefaultRouter both uses json to encode and decode the rpc body. Hence this client should be always 100% compatible with services built with the DefaultRouter.
type DefaultRouter ¶
type DefaultRouter struct {
// contains filtered or unexported fields
}
DefaultRouter implements Router interface. It then can be used to register handlers to quickly implement servers that are callable over RMB.
func NewRouter ¶
func NewRouter(address string) (*DefaultRouter, error)
NewRouter creates a new default router. with the local redis address. Normally you want to do NewRouter(DefaultAddress)
func (*DefaultRouter) Handlers ¶
func (m *DefaultRouter) Handlers() []string
Handlers return full name of all registered handlers
func (*DefaultRouter) Run ¶
func (m *DefaultRouter) Run(ctx context.Context) error
Run runs listeners to the configured handlers and will trigger the handlers in the case an event comes in
func (*DefaultRouter) Subroute ¶
func (*DefaultRouter) Use ¶
func (m *DefaultRouter) Use(mw Middleware)
func (*DefaultRouter) WithHandler ¶
WithHandler adds a topic handler to the messagebus
type Error ¶
type Handler ¶
Handler is a handler function type
type Incoming ¶
type Incoming struct { Version int `json:"ver"` Reference string `json:"ref"` Command string `json:"cmd"` Expiration int `json:"exp"` Data string `json:"dat"` TwinSrc string `json:"src"` RetQueue string `json:"ret"` Schema string `json:"shm"` Epoch int64 `json:"now"` }
Incoming request that need to be handled by servers
func GetRequest ¶
GetRequest gets a message from the context, panics if it's not there
func (*Incoming) GetPayload ¶
GetPayload returns the payload for a message's data
type IncomingResponse ¶
type IncomingResponse struct { Version int `json:"ver"` Reference string `json:"ref"` Data string `json:"dat"` TwinSrc string `json:"src"` Schema string `json:"shm"` Epoch int64 `json:"now"` Error *Error `json:"err,omitempty"` }
type Middleware ¶
Middleware is middleware function type
type OutgoingResponse ¶
type OutgoingResponse struct { Version int `json:"ver"` Reference string `json:"ref"` Data string `json:"dat"` TwinDest string `json:"dst"` Schema string `json:"shm"` Epoch int64 `json:"now"` Error *Error `json:"err,omitempty"` }
type RemoteError ¶
func (RemoteError) Error ¶
func (e RemoteError) Error() string
type Request ¶
type Request struct { Version int `json:"ver"` Reference string `json:"ref"` Command string `json:"cmd"` Expiration int `json:"exp"` Data string `json:"dat"` TwinDest []uint32 `json:"dst"` Session *string `json:"con"` RetQueue string `json:"ret"` Schema string `json:"shm"` Epoch int64 `json:"now"` }
Request is an outgoing request struct used to make rpc calls over rmb
func (*Request) GetPayload ¶
GetPayload returns the payload for a message's data
type Router ¶
type Router interface { WithHandler(route string, handler Handler) Subroute(route string) Router Use(Middleware) }
Router is the router interface
Source Files ¶
client.go interface.go mw.go redis.go rmb.go
Directories ¶
Path | Synopsis |
---|---|
examples | |
examples/client | |
examples/rpc_client | |
examples/server | |
peer | Package direct package provides the functionality to create a direct websocket connection to rmb relays without the need to rmb peers. |
peer/encoder | |
peer/examples | |
peer/examples/peer | |
peer/examples/peer_pingmany | |
peer/examples/router_server | |
peer/examples/rpc | |
peer/types |
- Version
- v0.16.6 (latest)
- Published
- Mar 17, 2025
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 3 hours ago –
Tools for package owners.