typex

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Warning:

This file is generated by go compiler, don't change it!!!

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

抽象设备: 1.0 以后的大功能:支持抽象设备,抽象设备就是外挂的设备,Rulex本来是个规则引擎,但是1.0之前的版本没有对硬件设备进行抽象支持 因此,1.0以后增加对硬件的抽象 Target Source 描述了数据的流向,抽象设备描述了数据的载体。 举例:外挂一个设备,这个设备具备双工控制功能,例如电磁开关等,此时它强调的是设备的物理功能,而数据则不是主体。 因此需要抽象出来一个层专门来描述这些设备

Index

Constants

This section is empty.

Variables

View Source
View Source
var DefaultVersionInfo = VersionInfo{
	Product:     "COMMON",
	ReleaseTime: "2024-03-15 16:36:25",
}

Global context

View Source
var MainVersion string

Functions

func NewCCTX

func NewCCTX() (context.Context, context.CancelFunc)

Types

type AI

type AI struct {
	UUID        string                 `json:"uuid"`        // UUID
	Name        string                 `json:"name"`        // 名称
	Type        AIType                 `json:"type"`        // 类型
	IsBuildIn   bool                   `json:"isBuildIn"`   // 是否内建
	Filepath    string                 `json:"filepath"`    // 文件路径, 是相对于main的aispace目录
	Config      map[string]interface{} `json:"config"`      // 内部配置
	Description string                 `json:"description"` // 描述文字
	XAI         XAi                    `json:"-"`
}

* * 内建AI *

func NewAI

func NewAI(UUID, Name, Type, Filepath, Description string) *AI

* * 生成typex.AI应用 *

type AIType

type AIType string
const BODY_POSE_RECOGNITION AIType = "BODY_POSE_RECOGNITION"

内建类型

type CCTX

type CCTX struct {
	Ctx       context.Context
	CancelCTX context.CancelFunc
}

child context

type DCAModel

type DCAModel struct {
	UUID    string      `json:"uuid"`
	Command string      `json:"command"`
	Args    interface{} `json:"args"`
}

type DCAResult

type DCAResult struct {
	Error error
	Data  string
}

type Device

type Device struct {
	UUID        string                 `json:"uuid"`        // UUID
	Name        string                 `json:"name"`        // 设备名称,例如:灯光开关
	Type        DeviceType             `json:"type"`        // 类型,一般是设备-型号,比如 ARDUINO-R3
	AutoRestart bool                   `json:"autoRestart"` // 是否允许挂了的时候重启
	Description string                 `json:"description"` // 设备描述信息
	BindRules   map[string]Rule        `json:"-"`           // 与之关联的规则
	State       DeviceState            `json:"state"`       // 状态
	Config      map[string]interface{} `json:"config"`      // 配置
	Device      XDevice                `json:"-"`           // 实体设备
}

设备元数据, 本质是保存在配置里面的数据的一个内存映射实例

func NewDevice

func NewDevice(t DeviceType,
	name string,
	description string,
	config map[string]interface{}) *Device

type DeviceRegistry

type DeviceRegistry interface {
	Register(DeviceType, *XConfig)
	Find(DeviceType) *XConfig
	All() []*XConfig
}

type DeviceState

type DeviceState int
const (
	// 设备故障
	DEV_DOWN DeviceState = 0
	// 设备启用
	DEV_UP DeviceState = 1

	// 外部停止
	DEV_STOP DeviceState = 3
)

func (DeviceState) String added in v0.5.2

func (s DeviceState) String() string

type DeviceTopology

type DeviceTopology struct {
	Id       string                 // 子设备的ID
	Name     string                 // 子设备名
	LinkType int                    // 物理连接方式: 0-ETH 1-WIFI 3-BLE 4 LORA 5 OTHER
	State    int                    // 状态: 0-Down 1-Working
	Info     map[string]interface{} // 子设备的一些额外信息
}

* * 子设备网络拓扑[2023-04-17新增] *

type DeviceType

type DeviceType string
const (
	SIEMENS_PLC                DeviceType = "SIEMENS_PLC"                // SIEMENS-S71200
	GENERIC_MODBUS             DeviceType = "GENERIC_MODBUS"             // 通用Modbus
	GENERIC_MODBUS_POINT_EXCEL DeviceType = "GENERIC_MODBUS_POINT_EXCEL" // 通用Modbus通过Excel表配置点位
	GENERIC_UART               DeviceType = "GENERIC_UART"               // 通用串口
	GENERIC_SNMP               DeviceType = "GENERIC_SNMP"               // SNMP 支持
	ICMP_SENDER                DeviceType = "ICMP_SENDER"                // ICMP_SENDER
	GENERIC_PROTOCOL           DeviceType = "GENERIC_PROTOCOL"           // 通用自定义协议处理器
	GENERIC_OPCUA              DeviceType = "GENERIC_OPCUA"              // 通用OPCUA
	GENERIC_CAMERA             DeviceType = "GENERIC_CAMERA"             // 通用摄像头
	GENERIC_AIS_RECEIVER       DeviceType = "GENERIC_AIS_RECEIVER"       // 通用AIS
	GENERIC_BACNET_IP          DeviceType = "GENERIC_BACNET_IP"          // 通用BacnetIP
	RHINOPI_IR                 DeviceType = "RHINOPI_IR"                 // 大犀牛PI的红外线接收器
	GENERIC_HTTP_DEVICE        DeviceType = "GENERIC_HTTP_DEVICE"        // GENERIC_HTTP
	HNC8                       DeviceType = "HNC8"                       // 华中数控机床
	KDN                        DeviceType = "KDN"                        // 凯帝恩控机床
)

支持的设备类型

func (DeviceType) String added in v0.6.5

func (d DeviceType) String() string

type DriverDetail

type DriverDetail struct {
	UUID        string `json:"uuid" binding:"required"`
	Name        string `json:"name" binding:"required"`
	Type        string `json:"type" binding:"required"`
	Description string `json:"description" binding:"required"`
}

外挂驱动, 比如串口, PLC等, 驱动可以挂在输入或者输出资源上。 典型案例: 1. MODBUS TCP模式 ,数据输入后转JSON输出到串口屏幕上 2. MODBUS TCP模式外挂了很多继电器,来自云端的 PLC 控制指令先到网关, 然后网关决定推送到哪个外挂

type DriverState

type DriverState int

Abstract driver interface

const (
	// STOP 状态一般用来直接停止一个资源,监听器不需要重启
	DRIVER_STOP DriverState = 0
	// UP 工作态
	DRIVER_UP DriverState = 1
	// DOWN 状态是某个资源挂了,属于工作意外,需要重启
	DRIVER_DOWN DriverState = 2
)

type Extlib

type Extlib struct {
	Value []string `ini:"extlibs,,allowshadow" json:"extlibs"`
}

Global config

type InEnd

type InEnd struct {
	//
	UUID        string          `json:"uuid"`
	State       SourceState     `json:"state"`
	Type        InEndType       `json:"type"`
	Name        string          `json:"name"`
	Description string          `json:"description"`
	BindRules   map[string]Rule `json:"-"`
	//
	Config        map[string]interface{} `json:"config"`
	DataModelsMap map[string]XDataModel  `json:"-"`
	Source        XSource                `json:"-"`
}

func NewInEnd

func NewInEnd(Type InEndType,
	n string,
	d string,
	c map[string]interface{}) *InEnd

func (*InEnd) GetConfig

func (in *InEnd) GetConfig(k string) interface{}

type InEndType

type InEndType string

InEndType

const (
	MQTT            InEndType = "MQTT"
	HTTP            InEndType = "HTTP"
	COAP            InEndType = "COAP"
	GRPC            InEndType = "GRPC"
	NATS_SERVER     InEndType = "NATS_SERVER"
	RULEX_UDP       InEndType = "RULEX_UDP"
	GENERIC_IOT_HUB InEndType = "GENERIC_IOT_HUB"
	INTERNAL_EVENT  InEndType = "INTERNAL_EVENT" // 内部消息
	GENERIC_MQTT    InEndType = "GENERIC_MQTT"   // 通用MQTT
)

func (InEndType) String

func (i InEndType) String() string

type ModelType

type ModelType int

Rule type is for property store, XSource implements struct type is actually worker

const (
	T_INT32  ModelType = iota // int32
	T_FLOAT                   // float
	T_DOUBLE                  // double
	T_TEXT                    // pure text
	T_BOOL                    // boolean
	T_JSON                    // json
	T_BIN                     // byte
)

'T' means Type

type OutEnd

type OutEnd struct {
	UUID        string      `json:"uuid"`
	State       SourceState `json:"state"`
	Type        TargetType  `json:"type"`
	Name        string      `json:"name"`
	Description string      `json:"description"`
	//
	Config map[string]interface{} `json:"config"`
	Target XTarget                `json:"-"`
}

func NewOutEnd

func NewOutEnd(t TargetType,
	n string,
	d string,
	c map[string]interface{}) *OutEnd

func (*OutEnd) GetConfig

func (out *OutEnd) GetConfig(k string) interface{}

type Parity

type Parity string

* * 串口校验形式 *

const (
	ODD  Parity = "O" // 奇校验
	EVEN Parity = "E" // 偶校验
	NONE Parity = "N" // 不校验
)

type ResourceRegistry added in v0.6.7

type ResourceRegistry interface {
	Register(DeviceType, *XConfig)
	Find(DeviceType) *XConfig
	All() []*XConfig
}

* * 资源管理器 *

type Rule

type Rule struct {
	Id          string      `json:"id"`
	UUID        string      `json:"uuid"`
	Type        string      `json:"type"` // 脚本类型,目前支持"lua"
	Status      RuleStatus  `json:"status"`
	Name        string      `json:"name"`
	FromSource  string      `json:"fromSource"` // 来自数据源
	FromDevice  string      `json:"fromDevice"` // 来自设备
	Actions     string      `json:"actions"`
	Success     string      `json:"success"`
	Failed      string      `json:"failed"`
	Description string      `json:"description"`
	LuaVM       *lua.LState `json:"-"` // Lua VM
}

规则描述

func NewLuaRule

func NewLuaRule(e RuleX,
	uuid string,
	name string,
	description string,
	fromSource string,
	fromDevice string,
	success string,
	actions string,
	failed string) *Rule

func NewRule

func NewRule(e RuleX,
	uuid string,
	name string,
	description string,
	fromSource string,
	fromDevice string,
	success string,
	actions string,
	failed string) *Rule

New

func (*Rule) AddLib

func (r *Rule) AddLib(rx RuleX, ModuleName string, funcName string,
	f func(l *lua.LState) int)

* * AddLib: 根据 KV形式加载库(推荐) * - Global: 命名空间 * - funcName: 函数名称

func (*Rule) LoadExternLuaLib

func (r *Rule) LoadExternLuaLib(path string) error

* * 加载外部LUA脚本,方便用户自己写一些东西 * 需要注意的: * - 不要和标准库里面的变量冲突了 * - 默认加载到 _G 环境里

type RuleStatus

type RuleStatus int
const RULE_RUNNING RuleStatus = 1
const RULE_STOP RuleStatus = 0

规则状态: 0: 停止 1: 运行中

type RuleX

type RuleX interface {
	//
	// 启动规则引擎
	//
	Start() *RulexConfig

	//
	// 执行任务
	//
	WorkInEnd(*InEnd, string) (bool, error)
	WorkDevice(*Device, string) (bool, error)
	//
	// 获取配置
	//
	GetConfig() *RulexConfig
	//
	// 加载输入
	//
	LoadInEndWithCtx(in *InEnd, ctx context.Context, cancelCTX context.CancelFunc) error
	//
	// 获取输入
	//
	GetInEnd(string) *InEnd
	//
	// 保存输入
	//
	SaveInEnd(*InEnd)
	//
	// 删除输入
	//
	RemoveInEnd(string)
	//
	// 所有输入列表
	//
	AllInEnd() *sync.Map
	//
	// 加载输出
	//
	LoadOutEndWithCtx(in *OutEnd, ctx context.Context, cancelCTX context.CancelFunc) error
	//
	// 所有输出
	//
	AllOutEnd() *sync.Map
	//
	// 获取输出
	//
	GetOutEnd(string) *OutEnd
	//
	// 保存输出
	//
	SaveOutEnd(*OutEnd)
	//
	// 删除输出
	//
	RemoveOutEnd(string)
	//
	// 加载Hook
	//
	LoadHook(XHook) error
	//
	// 加载插件
	//
	LoadPlugin(string, XPlugin) error
	//
	// 所有插件列表
	//
	AllPlugins() *sync.Map
	//
	// 加载规则
	//
	LoadRule(*Rule) error
	//
	// 所有规则列表
	//
	AllRule() *sync.Map
	//
	// 获取规则
	//
	GetRule(id string) *Rule
	//
	// 删除规则
	//
	RemoveRule(uuid string)
	//
	// 运行 lua 回调
	//
	RunSourceCallbacks(*InEnd, string)
	RunDeviceCallbacks(*Device, string)
	//
	// 运行 hook
	//
	RunHooks(string) //TODO Hook 未来某个版本会加强,主要用来加载本地动态库
	//
	// 获取版本
	//
	Version() VersionInfo

	//
	// 停止规则引擎
	//
	Stop()
	//
	// Snapshot Dump
	//
	SnapshotDump() string
	//
	// 加载设备
	//
	LoadDeviceWithCtx(in *Device, ctx context.Context, cancelCTX context.CancelFunc) error
	//
	// 获取设备
	//
	GetDevice(string) *Device
	//
	// 保存设备
	//
	SaveDevice(*Device)
	//
	//
	//
	AllDevices() *sync.Map
	//
	// 删除设备
	//
	RemoveDevice(string)
	//
	// 重启源
	//
	RestartInEnd(uuid string) error
	//
	// 重启目标
	//
	RestartOutEnd(uuid string) error
	//
	// 重启设备
	//
	RestartDevice(uuid string) error
}

RuleX interface

type RulexConfig

type RulexConfig struct {
	AppName               string `ini:"app_name" json:"appName"`
	AppId                 string `ini:"app_id" json:"appId"`
	MaxQueueSize          int    `ini:"max_queue_size" json:"maxQueueSize"`
	SourceRestartInterval int    `ini:"resource_restart_interval" json:"sourceRestartInterval"`
	GomaxProcs            int    `ini:"gomax_procs" json:"gomaxProcs"`
	EnablePProf           bool   `ini:"enable_pprof" json:"enablePProf"`
	EnableConsole         bool   `ini:"enable_console" json:"enableConsole"`
	LogLevel              string `ini:"log_level" json:"logLevel"`
	LogPath               string `ini:"log_path" json:"logPath"`
	LuaLogPath            string `ini:"lua_log_path" json:"luaLogPath"`
	MaxStoreSize          int    `ini:"max_store_size" json:"maxStoreSize"`
	AppDebugMode          bool   `ini:"app_debug_mode" json:"appDebugMode"`
	Extlibs               Extlib `ini:"extlibs,,allowshadow" json:"extlibs"`
	UpdateServer          string `ini:"update_server" json:"updateServer"`
}

type RulexResourceRegistry added in v0.6.7

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

func NewRulexResourceRegistry added in v0.6.7

func NewRulexResourceRegistry() *RulexResourceRegistry

func (*RulexResourceRegistry) All added in v0.6.7

func (rm *RulexResourceRegistry) All() []*XConfig

func (*RulexResourceRegistry) Find added in v0.6.7

func (rm *RulexResourceRegistry) Find(name InEndType) *XConfig

func (*RulexResourceRegistry) Register added in v0.6.7

func (rm *RulexResourceRegistry) Register(name InEndType, f *XConfig)

type ServiceArg

type ServiceArg struct {
	UUID string      `json:"uuid"` // 插件UUID, Rulex用来查找插件的
	Name string      `json:"name"` // 服务名, 在服务中响应识别
	Args interface{} `json:"args"` // 服务参数
}

插件的服务参数

type ServiceResult

type ServiceResult struct {
	Out interface{} `json:"out"`
}

type SourceRegistry

type SourceRegistry interface {
	Register(InEndType, *XConfig)
	Find(InEndType) *XConfig
	All() []*XConfig
}

type SourceState

type SourceState int

Source State

const (
	SOURCE_DOWN  SourceState = 0 // 此状态需要重启
	SOURCE_UP    SourceState = 1
	SOURCE_PAUSE SourceState = 2
	SOURCE_STOP  SourceState = 3
)

func (SourceState) String added in v0.5.2

func (s SourceState) String() string

type TargetRegistry

type TargetRegistry interface {
	Register(TargetType, *XConfig)
	Find(TargetType) *XConfig
	All() []*XConfig
}

type TargetType

type TargetType string

TargetType

const (
	MONGO_SINGLE  TargetType = "MONGO_SINGLE"
	MONGO_CLUSTER TargetType = "MONGO_CLUSTER"
	REDIS_SINGLE  TargetType = "REDIS_SINGLE"
	FLINK_SINGLE  TargetType = "FLINK_SINGLE"
	MQTT_TARGET   TargetType = "MQTT"
	MYSQL_TARGET  TargetType = "MYSQL"
	PGSQL_TARGET  TargetType = "PGSQL"
	NATS_TARGET   TargetType = "NATS"
	HTTP_TARGET   TargetType = "HTTP"
	// TDENGINE
	TDENGINE_TARGET TargetType = "TDENGINE"
	// GRPC
	GRPC_CODEC_TARGET TargetType = "GRPC_CODEC_TARGET"
	// UDP Server
	UDP_TARGET TargetType = "UDP_TARGET"
	// SQLITE
	SQLITE_TARGET TargetType = "SQLITE_TARGET"
	// USER_G776 DTU
	USER_G776_TARGET TargetType = "USER_G776_TARGET"
	// TCP 透传
	TCP_TRANSPORT TargetType = "TCP_TRANSPORT"
)

* * 输出资源类型 *

func (TargetType) String

func (i TargetType) String() string

type TopologyPoint

type TopologyPoint struct {
	UUID   string `json:"uuid"`
	Parent string `json:"parent"`
	Name   string `json:"name"`
	Alive  bool   `json:"alive"`
	Tag    string `json:"tag"`
}

拓扑接入点,比如 modbus 检测点等 UUID: gyh9uo7uh7o67u Name: ModbusMeter001 Alive: true Tag: modbus

type VersionInfo added in v0.6.5

type VersionInfo struct {
	ReleaseTime string
	Arch        string
	Product     string
	Dist        string
}

type XAi

type XAi interface {
	Start(map[string]interface{}) error
	Infer([][]float64) [][]float64
	Stop()
}

* * AI 应用层接口 *

type XAiRuntime

type XAiRuntime interface {
	GetRuleX() RuleX
	ListAi() []*AI
	LoadAi(Ai *AI) error
	GetAi(uuid string) *AI
	RemoveAi(uuid string) error
	UpdateAi(Ai *AI) error
	StartAi(uuid string) error
	StopAi(uuid string) error
	Stop()
}

* * AI 应用管理器接口 *

type XConfig

type XConfig struct {
	Type      string              `json:"type"` // 类型
	Engine    RuleX               `json:"-"`
	NewDevice func(RuleX) XDevice `json:"-"`
	NewSource func(RuleX) XSource `json:"-"`
	NewTarget func(RuleX) XTarget `json:"-"`
}

type XDataModel

type XDataModel struct {
	Name      string      `json:"name"`      // 字段名
	Tag       string      `json:"tag"`       // 标签
	ValueType ModelType   `json:"valueType"` // 值类型
	Value     interface{} `json:"value"`     // 具体的值
}

* 数据模型, 例如某个Modbus电表可以支持读取电流/C 和电压/V参数: *[ * { * "name":"voltage", * "tag":"voltage", * "valueType":"float", * "value":220 * } *] *

func (XDataModel) String added in v0.5.1

func (m XDataModel) String() string

type XDataPipe added in v0.6.3

type XDataPipe interface {
	Start() error
	Read([]byte) error
	Write([]byte) error
	Stop() error
}

* * Pipe: 和外界交互使用 *

type XDevice

type XDevice interface {
	// 初始化 通常用来获取设备的配置
	Init(devId string, configMap map[string]interface{}) error
	// 启动, 设备的工作进程
	Start(CCTX) error
	// 从设备里面读数据出来, 第一个参数一般作flag用, 也就是常说的指令类型
	OnRead(cmd []byte, data []byte) (int, error)
	// 把数据写入设备, 第一个参数一般作flag用, 也就是常说的指令类型
	OnWrite(cmd []byte, data []byte) (int, error)
	// 新特性, 适用于自定义协议读写
	OnCtrl(cmd []byte, args []byte) ([]byte, error)
	// 设备当前状态
	Status() DeviceState
	// 停止设备, 在这里释放资源,一般是先置状态为STOP,然后CancelContext()
	Stop()
	//
	// 0.5.2 新增 Reload() error
	//
	// 设备属性,是一系列属性描述
	Property() []iotschema.IoTSchema
	// 链接指向真实设备,保存在内存里面,和SQLite里的数据是对应关系
	Details() *Device
	// 状态
	SetState(DeviceState)
	// 驱动接口, 通常用来和硬件交互
	Driver() XExternalDriver
	// 外部调用, 该接口是个高级功能, 准备为了设计分布式部署设备的时候用, 但是相当长时间内都不会开启
	// 默认情况下该接口没有用
	OnDCACall(UUID string, Command string, Args interface{}) DCAResult
}

真实工作设备,即具体实现

type XExternalDriver

type XExternalDriver interface {
	Test() error
	Init(map[string]string) error
	Work() error
	State() DriverState
	Read(cmd []byte, data []byte) (int, error)
	Write(cmd []byte, data []byte) (int, error)
	DriverDetail() DriverDetail
	Stop() error
}

驱动由源(Source)或者设备(Device)启动,驱动的状态(Status)被RULEX获取,或者被源或者设备获取后返回给RULEX

type XHook

type XHook interface {
	Work(data string) error
	Error(error)
	Name() string
}

XHook for enhancement rulex with golang

type XLib

type XLib interface {
	Name() string
	LibFun(RuleX) func(*lua.LState) int
}

XLib: 库函数接口; TODO: V0.1.2废弃

type XPlugin

type XPlugin interface {
	Init(*ini.Section) error // 参数为外部配置
	Start(RuleX) error
	Service(ServiceArg) ServiceResult // 对外提供一些服务
	Stop() error
	PluginMetaInfo() XPluginMetaInfo
}

* * 插件: 用来增强RULEX的外部功能,本色不属于RULEX *

type XPluginMetaInfo

type XPluginMetaInfo struct {
	UUID     string `json:"uuid"`
	Name     string `json:"name"`
	Version  string `json:"version"`
	Homepage string `json:"homepage"`
	HelpLink string `json:"helpLink"`
	Author   string `json:"author"`
	Email    string `json:"email"`
	License  string `json:"license"`
}

* * 插件的元信息结构体 * 注意:插件信息这里uuid,name有些是固定写死的,比较特殊,不要轻易改变已有的,否则会导致接口失效 * 只要是已有的尽量不要改这个UUID。 *

type XService

type XService interface {
	Load()
	Get()
	List()
	Remove()
	Stop()
}

* * TODO: 定义一系列接口,以后每个涉及到CURD管理的都实现这个接口 * 暂时先放在这里作为参考,短期内不会重构 *

type XSource

type XSource interface {
	//
	// 测试资源是否可用
	//
	Test(inEndId string) bool
	//
	// 用来初始化传递资源配置
	//
	Init(inEndId string, configMap map[string]interface{}) error
	//
	// 启动资源
	//
	Start(CCTX) error
	//
	// 数据模型, 用来描述该资源支持的数据, 对应的是云平台的物模型
	//
	DataModels() []XDataModel
	//
	// 获取资源状态
	//
	Status() SourceState
	//
	// 获取资源绑定的的详情
	//
	Details() *InEnd
	//
	// 驱动接口, 通常用来和硬件交互
	//
	Driver() XExternalDriver
	//
	//
	//
	Topology() []TopologyPoint
	//
	// 停止资源, 用来释放资源
	//
	Stop()
	//
	// 来自外面的数据
	//
	DownStream([]byte) (int, error)
	//
	// 上行数据
	//
	UpStream([]byte) (int, error)
}

XSource: 终端资源, 比如实际上的 MQTT 客户端

type XStatus

type XStatus struct {
	PointId     string             // Input: Source; Output: Target
	Enable      bool               // 是否开启
	Ctx         context.Context    // context
	CancelCTX   context.CancelFunc // cancel
	XDataModels []XDataModel       // 数据模型
	RuleEngine  RuleX              // rulex
	Busy        bool               // 是否处于忙碌状态, 防止请求拥挤
}

XStatus for source status

type XStore

type XStore interface {
	// 设置值
	Set(k string, v string)
	// 设置值和值超时时间
	SetWithDuration(k string, v string, long time.Duration)
	// 获取值
	Get(k string) string
	// 删除值
	Delete(k string) error
	// 统计数量
	Count() int
	// 模糊查询匹配
	// 支持: *AAA AAA* A*B
	FuzzyGet(k string) any
}

* * 缓存器接口 *

type XStream

type XStream interface {
	Start() error
	State() XStatus
	Close()
}

------------------------------------------------

Remote Stream

------------------------------------------------ ┌───────────────┐ ┌────────────────┐ │ RULEX │ <─────── │ SERVER │ │ RULEX │ ───────>│ SERVER │ └───────────────┘ └────────────────┘ ------------------------------------------------

type XTarget

type XTarget interface {
	//
	// 用来初始化传递资源配置
	//
	Init(outEndId string, configMap map[string]interface{}) error
	//
	// 启动资源
	//
	Start(CCTX) error
	//
	// 获取资源状态
	//
	Status() SourceState
	//
	// 获取资源绑定的的详情
	//
	Details() *OutEnd
	//
	// 数据出口
	//
	To(data interface{}) (interface{}, error)
	//
	// 停止资源, 用来释放资源
	//
	Stop()
}

Stream from source and to target

Jump to

Keyboard shortcuts

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