Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Gmqtt is a flexible, high-performance MQTT broker library that fully implements the MQTT protocol V3.x and V5 in golang

License

NotificationsYou must be signed in to change notification settings

DrmagicE/gmqtt

Repository files navigation

中文文档

GmqttMentioned in Awesome GoBuild StatuscodecovGo Report Card

Project state

This project is less maintained due to personal reasons. Here are some information for people who want to use this project.

Gmqtt was used in production and worked well. The production environment was serving hundreds of clients(or maybe thousands or 10 thousands now), andeach client published QoS 1 message to report their state every 15 seconds. The subscribers on the cloud would store those state into persist backend.All clients were non-persistent session and using v3.1.1 protocol.

It is suggested to evaluate and test carefully before running in your production environment.

Features

  • Provide hook method to customized the broker behaviours(Authentication, ACL, etc..). Seeserver/hooks.go for details
  • Support tls/ssl and websocket
  • Provide flexible plugable mechanism. Seeserver/plugin.go and/plugin for details.
  • Provide Go interface for extensions to interact with the server. For examples, the extensions or plugins can publish message or add/remove subscription through function call.SeeServer interface inserver/server.go andadmin for details.
  • Provide metrics (by using Prometheus). (plugin:prometheus)
  • Provide GRPC and REST APIs to interact with server. (plugin:admin)
  • Provide session persistence which means the broker can retrieve the session data after restart.Currently, only redis backend is supported.
  • Provide clustering, seefederation plugin for examples and details. (WARNING: This is an experimental feature, and has never been used in production environment.)

Get Started

To get started with gmqtt, we need to compile it from the source code. Please ensure that you have a workingGo environment.

The following command will start gmqtt broker with default configuration.The broker listens on 1883 for tcp server and 8883 for websocket server withadmin andprometheus plugin loaded.

$ git clone https://github.com/DrmagicE/gmqtt$cd gmqtt/cmd/gmqttd$ go run. start -c default_config.yml

configuration

Gmqtt use-c flag to define configuration path. If not set, gmqtt reads$HOME/gmqtt.yml as default. Here is asample configuration.

session persistence

Gmqtt uses memory to store session data by default and it is the recommended way because of the good performance.But the session data will be lose after the broker restart. You can use redis as backend storage to prevent dataloss from restart:

persistence:type:redisredis:# redis server addressaddr:"127.0.0.1:6379"# the maximum number of idle connections in the redis connection poolmax_idle:1000# the maximum number of connections allocated by the redis connection pool at a given time.# If zero, there is no limit on the number of connections in the pool.max_active:0# the connection idle timeout, connection will be closed after remaining idle for this duration. If the value is zero, then idle connections are not closedidle_timeout:240spassword:""# the number of the redis databasedatabase:0

Authentication

Gmqtt provides a simple username/password authentication mechanism. (Provided byauth plugin).It is not enabled in default configuration, you can change the configuration to enable it:

# plugin loading ordersplugin_order:  -auth  -prometheus  -admin

When auth plugin enabled, every clients need an account to get connected.You can add accounts through the HTTP API:

# Create: username = user1, password = user1pass$ curl -X POST -d'{"password":"user1pass"}' 127.0.0.1:8083/v1/accounts/user1{}# Query$ curl 127.0.0.1:8083/v1/accounts/user1{"account":{"username":"user1","password":"20a0db53bc1881a7f739cd956b740039"}}

API Docswagger

Docker

$ docker build -t gmqtt .$ docker run -p 1883:1883 -p 8883:8883 -p 8082:8082 -p 8083:8083  -p 8084:8084  gmqtt

Documentation

godoc

Hooks

Gmqtt implements the following hooks:

Namehooking pointpossible usages
OnAcceptWhen accepts a TCP connection.(Not supported in websocket)Connection rate limit, IP allow/block list.
OnStopWhen gmqtt stop
OnSubscribeWhen received a subscribe packetSubscribe access control, modifies subscriptions.
OnSubscribedWhen subscribe succeed
OnUnsubscribeWhen received a unsubscribe packetUnsubscribe access controls, modifies the topics that is going to unsubscribe.
OnUnsubscribedWhen unsubscribe succeed
OnMsgArrivedWhen received a publish packetPublish access control, modifies message before delivery.
OnBasicAuthWhen received a connect packet without AuthMethod propertyAuthentication
OnEnhancedAuthWhen received a connect packet with AuthMethod property (Only for v5 clients)Authentication
OnReAuthWhen received a auth packet (Only for v5 clients)Authentication
OnConnectedWhen the client connected succeed
OnSessionCreatedWhen creates a new session
OnSessionResumedWhen resumes from old session
OnSessionTerminatedWhen session terminated
OnDeliveredWhen a message is delivered to the client
OnClosedWhen the client is closed
OnMsgDroppedWhen a message is dropped for some reasons
OnWillPublishWhen the client is going to deliver a will messageModify or drop the will message
OnWillPublishedWhen a will message has been delivered

How to write plugins

How to write plugins

Contributing

Contributions are always welcome, seeContribution Guide for a complete contributing guide.

Test

Unit Test

$ go test -race ./...

Integration Test

paho.mqtt.testing.

About

Gmqtt is a flexible, high-performance MQTT broker library that fully implements the MQTT protocol V3.x and V5 in golang

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors13

Languages


[8]ページ先頭

©2009-2025 Movatter.jp