bridge

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 6 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BridgeVersion string

BridgeVersion exists so you can stamp the compiled artifact with a version number that logs when it is loaded

Functions

This section is empty.

Types

type Bridge

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

Bridge represents the communication layer between your C++ code and the go components you implement in your project

func NewBridge

func NewBridge(prefix string,
	logger func(level LogLevel, message string, args ...interface{}),
	publisher func(topic string, data []byte) error) *Bridge

func (*Bridge) Debug

func (b *Bridge) Debug(message string, args ...interface{})

func (*Bridge) Error

func (b *Bridge) Error(message string, args ...interface{})

func (*Bridge) HandleIncomingCall

func (b *Bridge) HandleIncomingCall(topic string, data []byte) ([]byte, error)

HandleIncomingCall receives a message from the C++ code and passes it off to the Message Bus where it will returrn the data received from the Message Bus.

func (*Bridge) Info

func (b *Bridge) Info(message string, args ...interface{})

func (*Bridge) MessageBusInstance

func (b *Bridge) MessageBusInstance() *MessageBus

func (*Bridge) PublishExternally

func (b *Bridge) PublishExternally(topic string, data []byte) error

PublishExternally is used in a "fire and forget" scenario where you want to publish a message from your go components to your bridge for consumption by the application platform.

func (*Bridge) RegisterService

func (b *Bridge) RegisterService(name string, service interface{})

Register your service with the bridge so that others can get a handle to it

func (*Bridge) RequestExternally

func (b *Bridge) RequestExternally(timeoutMS int, topic string, data []byte, cb func(m *Message)) (string, error)

RequestExternally is used when you want to publish a message from your go components to the application platform and you expect the application platform to send back a response within a specific time limit specified in milliseconds. This will return the unique message ID assigned to your request that is used for the single use Message Bus subscription to the message. This only returns an error if the message could not be published to the application platform.

func (*Bridge) ServiceInstance

func (b *Bridge) ServiceInstance(name string) interface{}

Ask the bridge to give you an instance of a service

func (*Bridge) Warn

func (b *Bridge) Warn(message string, args ...interface{})

type ExternalPublisher

type ExternalPublisher interface {
	PublishExternally(topic string, data []byte) error
	RequestExternally(timeoutMS int, topic string, data []byte, cb func(m *Message)) (string, error)
}

type LogLevel

type LogLevel int8
const (
	LOG_LEVEL_NONE  LogLevel = 0
	LOG_LEVEL_ERROR LogLevel = 1
	LOG_LEVEL_WARN  LogLevel = 2
	LOG_LEVEL_INFO  LogLevel = 3
	LOG_LEVEL_DEBUG LogLevel = 4
)

type Logger

type Logger interface {
	Debug(message string, args ...interface{})
	Info(message string, args ...interface{})
	Warn(message string, args ...interface{})
	Error(message string, args ...interface{})
}

func NewLogger

func NewLogger(prefix string, lvl LogLevel, l Logger) Logger

type Message

type Message struct {
	Topic   string
	Data    []byte
	Pointer interface{}
}

type MessageBus

type MessageBus struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMessageBus

func NewMessageBus() *MessageBus

func (*MessageBus) Publish

func (b *MessageBus) Publish(topic string, data []byte) ([]byte, error)

func (*MessageBus) Subscribe

func (b *MessageBus) Subscribe(topic string, h MessageHandler) uint64

func (*MessageBus) SubscribeAsync

func (b *MessageBus) SubscribeAsync(topic string, h MessageHandler, transactional bool) uint64

Transactional means we only allow one at a time to your handler

func (*MessageBus) SubscribeOnce

func (b *MessageBus) SubscribeOnce(topic string, h MessageHandler) uint64

Handler unsubscribed automatically

func (*MessageBus) SubscribeOnceAsync

func (b *MessageBus) SubscribeOnceAsync(topic string, h MessageHandler) uint64

func (*MessageBus) SubscribeTransactional

func (b *MessageBus) SubscribeTransactional(topic string, h MessageHandler) uint64

func (*MessageBus) Unsubscribe

func (b *MessageBus) Unsubscribe(topic string, subscriptionID uint64)

type MessageHandler

type MessageHandler func(m *Message) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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