# Federation
Federation is a kind of clustering mechanism which provides high-availability and horizontal scaling.
In Federation mode, multiple gmqtt brokers can be grouped together and "act as one".
However, it is impossible to fulfill all requirements in MQTT specification in a distributed environment.
There are some limitations:
1. Persistent session cannot be resumed from another node.
2. Clients with same client id can connect to different nodes at the same time and will not be kicked out.
This is because session information only stores in local node and does not share between nodes.
## Quick Start
The following commands will start a two nodes federation, the configuration files can be found [here](./examples).
Start node1 in Terminal1:
```bash
$ gmqttd start -c path/to/retry_join/node1_config.yml
```
Start node2 in Terminate2:
```bash
$ gmqttd start -c path/to/retry_join/node2_config2.yml
```
After node1 and node2 is started, they will join into one federation atomically.
We can test the federation with `mosquitto_pub/sub`:
Connect to node2 and subscribe topicA:
```bash
$ mosquitto_sub -t topicA -h 127.0.0.1 -p 1884
```
Connect to node1 and send a message to topicA:
```bash
$ mosquitto_pub -t topicA -m 123 -h 127.0.0.1 -p 1883
```
The `mosquitto_sub` will receive "123" and print it in the terminal.
```bash
$ mosquitto_sub -t topicA -h 127.0.0.1 -p 1884
123
```
## Join Nodes via REST API
Federation provides gRPC/REST API to join/leave and query members information, see [swagger](./swagger/federation.swagger.json) for details.
In addition to join nodes upon starting up, you can join a node into federation by using `Join` API.
Start node3 with the configuration with empty `retry_join` which means that the node will not join any nodes upon starting up.
```bash
$ gmqttd start -c path/to/retry_join/join_node3_config.yml
```
We can send `Join` request to any nodes in the federation to get node3 joined, for example, sends `Join` request to node1:
```bash
$ curl -X POST -d '{"hosts":["127.0.0.1:8932"]}' '127.0.0.1:8083/v1/federation/join'
{}
```
And check the members in federation:
```bash
curl http://127.0.0.1:8083/v1/federation/members
{
"members": [
{
"name": "node1",
"addr": "192.168.0.105:8902",
"tags": {
"fed_addr": "192.168.0.105:8901"
},
"status": "STATUS_ALIVE"
},
{
"name": "node2",
"addr": "192.168.0.105:8912",
"tags": {
"fed_addr": "192.168.0.105:8911"
},
"status": "STATUS_ALIVE"
},
{
"name": "node3",
"addr": "192.168.0.105:8932",
"tags": {
"fed_addr": "192.168.0.105:8931"
},
"status": "STATUS_ALIVE"
}
]
}%
```
You will see there are 3 nodes ara alive in the federation.
## Configuration
```go
// Config is the configuration for the federation plugin.
type Config struct {
// NodeName is the unique identifier for the node in the federation. Defaults to hostname.
NodeName string `yaml:"node_name"`
// FedAddr is the gRPC server listening address for the federation internal communication.
// Defaults to :8901.
// If the port is missing, the default federation port (8901) will be used.
FedAddr string `yaml:"fed_addr"`
// AdvertiseFedAddr is used to change the federation gRPC server address that we advertise to other nodes in the cluster.
// Defaults to "FedAddr" or the private IP address of the node if the IP in "FedAddr" is 0.0.0.0.
// However, in some cases, there may be a routable address that cannot be bound.
// If the port is missing, the default federation port (8901) will be used.
AdvertiseFedAddr string `yaml:"advertise_fed_addr"`
// GossipAddr is the address that the gossip will listen on, It is used for both UDP and TCP gossip. Defaults to :8902
GossipAddr string `yaml:"gossip_addr"`
// AdvertiseGossipAddr is used to change the gossip server address that we advertise to other nodes in the cluster.
// Defaults to "GossipAddr" or the private IP address of the node if the IP in "GossipAddr" is 0.0.0.0.
// If the port is missing, the default gossip port (8902) will be used.
AdvertiseGossipAddr string `yaml:"advertise_gossip_addr"`
// RetryJoin is the address of other nodes to join upon starting up.
// If port is missing, the default gossip port (8902) will be used.
RetryJoin []string `yaml:"retry_join"`
// RetryInterval is the time to wait between join attempts. Defaults to 5s.
RetryInterval time.Duration `yaml:"retry_interval"`
// RetryTimeout is the timeout to wait before joining all nodes in RetryJoin successfully.
// If timeout expires, the server will exit with error. Defaults to 1m.
RetryTimeout time.Duration `yaml:"retry_timeout"`
// SnapshotPath will be pass to "SnapshotPath" in serf configuration.
// When Serf is started with a snapshot,
// it will attempt to join all the previously known nodes until one
// succeeds and will also avoid replaying old user events.
SnapshotPath string `yaml:"snapshot_path"`
// RejoinAfterLeave will be pass to "RejoinAfterLeave" in serf configuration.
// It controls our interaction with the snapshot file.
// When set to false (default), a leave causes a Serf to not rejoin
// the cluster until an explicit join is received. If this is set to
// true, we ignore the leave, and rejoin the cluster on start.
RejoinAfterLeave bool `yaml:"rejoin_after_leave"`
}
```
## Implementation Details
### Inner-node Communication
Nodes in the same federation communicate with each other through a couple of gRPC streaming apis:
```proto
message Event {
uint64 id = 1;
oneof Event {
Subscribe Subscribe = 2;
Message message = 3;
Unsubscribe unsubscribe = 4;
}
}
service Federation {
rpc Hello(ClientHello) returns (ServerHello){}
rpc EventStream (stream Event) returns (stream Ack){}
}
```
In general, a node is both Client and Server which implements the `Federation` gRPC service.
* As Client, the node will send subscribe, unsubscribe and message published events to other nodes if necessary.
Each event has a EventID, which is incremental and unique in a session.
* As Server, when receives a event from Client, the node returns an acknowledgement after the event has been handled successfully.
### Session State
The event is designed to be idempotent and will be delivered at least once, just like the QoS 1 message in MQTT protocol.
In order to implement QoS 1 protocol flows, the Client and Server need to associate state with a SessionID,
this is referred to as the Session State. The Server also stores the federation tree and retained messages as part of the Session State.
The Session State in the Client consists of:
* Events which have been sent to the Server, but have not been acknowledged.
* Events pending transmission to the Server.
The Session State in the Server consists of:
* The existence of a Session, even if the rest of the Session State is empty.
* The EventID of the next event that the Server is willing to accept.
* Events which have been received from the Client, but have not sent acknowledged yet.
The Session State stores in memory only. When the Client starts, it generates a random UUID as SessionID.
When the Client detects a new node is joined or reconnects to the Server, it sends the `Hello` request which contains the SessionID to perform a handshake.
During the handshake, the Server will check whether the session for the SessionID exists.
* If the session not exists, the Server sends response with `clean_start=true`.
* If the session exists, the Server sends response with `clean_start=false` and sets the next EventID that it is willing to accept to `next_event_id`.
After handshake succeed, the Client will start `EventStr
没有合适的资源?快使用搜索试试~ 我知道了~
物联网管理平台.zip
共1473个文件
go:560个
js:155个
vue:154个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 67 浏览量
2024-01-23
14:37:03
上传
评论
收藏 110.74MB ZIP 举报
温馨提示
在选购物联网产品相关的时候,大部分的产品都只能是使用厂家指定的平台,无法实现不同的产品不同的平台互联互通,比如小米的产品无法接入带自家的系统里面等,总是会有这样那样的限制。正是由于这么多的限制,因此打算建立一个全新的物联网生态联盟,在该联盟里面的厂家可以在设备里面实现自身的协议或者可以将该平台集成到设备里面去,从而实现设备不受限制的互联互通,后面也会建立起一个平台,在该平台上大家可以贡献自己制作的插件,从而实现躺着收费的梦想,平台上厂家也可以上线自己的设备,从而省去昂贵的广告费用,可以让利给消费者,从而让消费者可以买到便宜实用的产品。 IOTFast平台是基于Goframe2.0 + vue3.x + CompositionAPI + typescript + vite + element plus + vue-router-next + next.vuex 等开发,适配电脑PC,手机,平板的物联网平台,该平台可以运行于多种平台上面,支持跨平台的物联网接入及管理方案,独创的GO插件系统,支持跨语言,跨平台接入,为后期的系统扩展打下了坚实的基础。该平台实现了众多的web技术开发和物联网
资源推荐
资源详情
资源评论
收起资源包目录
物联网管理平台.zip (1473个子文件)
luajit.1 2KB
msvcbuild.bat 4KB
ps4build.bat 3KB
xedkbuild.bat 3KB
psvitabuild.bat 3KB
linux_arm_complie.bat 95B
win_compile.bat 91B
minilua.c 170KB
lj_parse.c 79KB
lj_record.c 73KB
lj_opt_fold.c 61KB
lj_asm.c 56KB
lj_cparse.c 55KB
lj_crecord.c 53KB
lj_alloc.c 40KB
lj_opt_mem.c 30KB
lj_api.c 28KB
lj_ffrecord.c 27KB
lj_snap.c 27KB
lj_ccall.c 27KB
lj_gc.c 26KB
lj_opt_narrow.c 25KB
lib_string.c 24KB
lj_cconv.c 24KB
lj_err.c 23KB
lj_trace.c 23KB
lj_opt_split.c 23KB
lib_ffi.c 22KB
lj_gdbjit.c 21KB
lj_ccallback.c 18KB
lj_ctype.c 18KB
lj_tab.c 18KB
lib_package.c 17KB
lib_jit.c 17KB
lib_base.c 17KB
lj_debug.c 17KB
lj_strscan.c 15KB
lj_opt_loop.c 15KB
lj_dispatch.c 15KB
luajit.c 14KB
lj_meta.c 14KB
lib_io.c 13KB
lj_ir.c 13KB
lj_bcread.c 13KB
buildvm.c 13KB
lj_lex.c 12KB
lj_bcwrite.c 11KB
buildvm_peobj.c 11KB
buildvm_lib.c 10KB
lj_clib.c 10KB
lj_mcode.c 10KB
lj_carith.c 10KB
lj_str.c 9KB
lib_debug.c 9KB
lib_aux.c 9KB
lj_state.c 9KB
lj_cdata.c 8KB
buildvm_asm.c 8KB
lib_table.c 7KB
lj_opt_sink.c 7KB
buildvm_fold.c 6KB
lib_os.c 6KB
lj_lib.c 6KB
lib_math.c 6KB
lj_func.c 6KB
lj_load.c 4KB
lj_vmmath.c 3KB
libLua_windows.c 3KB
libLua_linux.c 3KB
ljamalg.c 2KB
lj_opt_dce.c 2KB
lj_char.c 2KB
lib_bit.c 2KB
lj_vmevent.c 1KB
lib_init.c 1KB
lj_obj.c 956B
lj_udata.c 848B
lj_bc.c 261B
extfile.cnf 78B
rbac_model.conf 223B
openssl.conf 113B
COPYRIGHT 3KB
index.1658457169439.css 359KB
chunk-vendors.0a3c4472.css 213KB
demo2.1658457169439.css 20KB
index.165845716943922.css 16KB
index.165845716943910.css 15KB
demo1.1658457169439.css 11KB
main.1658457169439.css 10KB
index.16584571694392.css 6KB
bluequad.css 5KB
index.165845716943912.css 5KB
index.165845716943920.css 5KB
app.bdc9d33b.css 5KB
index.165845716943923.css 5KB
index.16584571694396.css 5KB
index.165845716943919.css 4KB
index.165845716943915.css 4KB
index.165845716943921.css 4KB
index.16584571694399.css 3KB
共 1473 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
博士僧小星
- 粉丝: 1921
- 资源: 5876
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- MATLAB大数据仿真案例-蚁群算法(ACO)用于求解旅行商(TSP)问题.rar
- MySQL基础知识-个人笔记.rar
- Project8.ipynb
- Python实现BWO-LSTM白鲸算法优化长短期记忆神经网络时间序列预测(完整源码和数据)
- C语言实现文件读写操作的几种常用方法-C 语言.rar
- RK 3568 Android11 版本的梯形校正补丁
- 基于pyqt yolov5 dlib的驾驶员行为监控系统源码+模型.zip
- python代码案例详解-旅行商问题的多种求解算法.rar
- 单相电力电子负载仿真,PWM整流+单相并网逆变
- C语言功能模块(配置文件读取 、debug日志记录等).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功