MQTT Gateway. kafka + rpcx + echo …
以微服务+MQ构建支持高并发连接的分布式消息服务系统
Node
通过订阅MQ消息的方式,完成消息在节点间的转发n
个node, 发送m
条消息/topic/node,节点消费的需求是n
*m
条/topicGateway编程模型
根据配置选择 conf/conf.toml
- MQ
conf.broker
- Kafka
- 服务注册与发现
conf.auth
- Etcd
- Consul
# 启动Gateway,[-h]帮助查看可选参数
$ cd gateway
$ go run -tags "consul" main.go
# RPC Auth服务,[-h]帮助查看可选参数
$ cd api
$ go run -tags "consul" main.go
host
=gmqtt.k8s.hbchen.com
port
=80
broker
Developing
- api
- auth
- RPC服务间的访问控制:RBAC
- client
- auth
- client auth
- pub/sub auth
- register
- register
- unregister
- cluster
- nodes
- 节点列表
- clients
- 终端列表
- sessions
- 会话列表
- topics
- 话题信息
- subscriptions
- 订阅信息
- console
- deploy
```bash
$ go test -run=TestClient$
# 1 client pub, sent 100000 messages, no sub
# qos 0
Total sent 100000 messages dropped 0 in 3096.074512 ms, 0.030961 ms/msg, 32298 msgs/sec
# qos 1
Total sent 100000 messages dropped 0 in 10411.318733 ms, 0.104113 ms/msg, 9604 msgs/sec
Total Sent 1000000 messages dropped 0 in 65403.199238 ms, 0.065403 ms/msg, 15289 msgs/sec
Total Received 1000000 messages in 65403.199238 ms, 0.065403 ms/msg, 15289 msgs/sec
Total Sent 1000000 messages dropped 0 in 68339.624216 ms, 0.068340 ms/msg, 14632 msgs/sec
Total Received 1000000 messages in 68339.624216 ms, 0.068340 ms/msg, 14632 msgs/sec
## 备用命令
#### Protobuf
```bash
# 在.proto有import时注意相对的路径
protoc -I=$GOPATH/src:. --go_out=. api/proto/define.proto
# Start the server
$ bin/zookeeper-server-start.sh config/zookeeper.properties
$ bin/kafka-server-start.sh config/server.properties
# List topic
bin/kafka-topics.sh --list --zookeeper localhost:2181
# Start a consumer
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic --from-beginning
# 启动报错,需修改conf/application.conf
kafka-manager.zkhosts="localhost:2181"