{"id":34197470,"url":"https://github.com/gw123/gmq","last_synced_at":"2026-03-10T08:31:25.831Z","repository":{"id":79393958,"uuid":"163495258","full_name":"gw123/gmq","owner":"gw123","description":"基于事件机制的多模块框架,支持动态库,grpc,websocket,mqtt等多种与后端通信组合方式. 模块动态替换,部分加载或者升级.","archived":false,"fork":false,"pushed_at":"2019-12-20T11:07:02.000Z","size":1787,"stargazers_count":32,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-16T03:23:39.662Z","etag":null,"topics":["event-loop","golang","modules"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gw123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-29T09:00:03.000Z","updated_at":"2024-06-06T15:02:37.000Z","dependencies_parsed_at":"2023-03-12T07:58:24.323Z","dependency_job_id":null,"html_url":"https://github.com/gw123/gmq","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/gw123/gmq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gw123%2Fgmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gw123%2Fgmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gw123%2Fgmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gw123%2Fgmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gw123","download_url":"https://codeload.github.com/gw123/gmq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gw123%2Fgmq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30328251,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["event-loop","golang","modules"],"created_at":"2025-12-15T17:39:22.707Z","updated_at":"2026-03-10T08:31:25.809Z","avatar_url":"https://github.com/gw123.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"#GMQ 消息模块组合架构\n##  功能特性\n  - 自动管理channel 实现配置变动后 模块重启\n  - 多模块按需编译,按配置加载\n  - 支持多种消息通信方式(mqtt,http,websocket,grpc)\n  - 模块之间通过消息之间通信相互独立解耦 \n  - 优雅的日志输出方式\n  - 多数据库支持,方便开发\n  - 支持读取yml中配置环境变量,方便容器化部署\n  - 全局的service获取方式,模块调用更加灵活\n  \n## 目录结构\n - bootstarp 引导启动目录, 加载配置, 按需加载需要的module(仅仅编译添加的文件) ,加载全局service\n - common 公共引用路径 \n - core 框架核心\n - modules 模块路径\n - resource 资源路径\n - storage 上传文件保存路径\n\n## 模块配置说明\n```\n   moduleName:\n      type : inner/exe/dll/so\n      enable: 1/ture\n```\n moduleName 模块名称\n - type 模块类型目前支持 内部模块(golang),可执行程序, dll/so windows,linux动态库方式\n - 通信方式支持 mqtt,http,grpc,websocket方式\n - enable 配置模块是否要启用\n\n## 如何新加一个model, 下面以debugmodel为例\n - 在modules 添加deubugModel 文件夹\n - 添加DebugModule.go 文件\n ```\nimport (\n\t\"github.com/gw123/GMQ/modules/base\"\n\t\"github.com/gw123/GMQ/core/interfaces\"\n\t\"fmt\"\n)\ntype DebugModule struct {\n\tbase.BaseModule\n}\n\nfunc NewDebugModule() *DebugModule {\n\tthis := new(DebugModule)\n\treturn this\n}\n\nfunc (this *DebugModule) Init(app interfaces.App, config interfaces.ModuleConfig) error {\n\tthis.BaseModule.Init(app, this, config)\n\t//订阅 debug 消息主题\n\tapp.Sub(\"debug\", this)\n\treturn nil\n}\n// 处理消息\nfunc (this *DebugModule) Handle(event interfaces.Event) error {\n\treturn nil\n}\n// 定时触发方法\nfunc (this *DebugModule) Watch(index int) {\n\n\treturn\n}\n```\n\n- 实现模块提供者 DebugModuleProvider.go\n```\npackage debugModule\n\nimport \"github.com/gw123/GMQ/core/interfaces\"\n\ntype DebugModuleProvider struct {\n\tmodule interfaces.Module\n}\n\nfunc NewDebugModuleProvider() *DebugModuleProvider {\n\tthis := new(DebugModuleProvider)\n\treturn this\n}\n\nfunc (this *DebugModuleProvider) GetModuleName() string {\n\treturn \"Debug\"\n}\n\nfunc (this *DebugModuleProvider) Register() {\n\n}\n\nfunc (this *DebugModuleProvider) GetModule() interfaces.Module {\n\tif this.module != nil {\n\t\treturn this.module\n\t}\n\tthis.module = NewDebugModule()\n\treturn this.module\n}\n\nfunc (this *DebugModuleProvider) GetNewModule() interfaces.Module {\n\tthis.module = NewDebugModule()\n\treturn this.module\n}\n\n```\n\n- 在bootstarp/moduleProvider.go 引入debugModuel\n\n```\nfunc LoadModuleProvider(app interfaces.App) {\n\tapp.LoadModuleProvider(debugModule.NewDebugModuleProvider())\n\treturn\n}\n```\n\n\n\n#数据库配置 支持多数据库配置\n```\ndbpool:\n   default: xyt\n   db1:\n      database: \"gateway\"\n      host: \"xytschool.com\"\n      username: \"dbuser\"\n      password: \"dbpwd\"\n      drive: \"mysql,pg,sqllite\"\n   db2:\n      database: \"gateway\"\n      host: \"xytschool.com\"\n      username: \"dbuser\"\n      password: \"dbpwd\"\n      drive: \"mysql,pg,sqllite\"    \n```\n\n#数据库使用\n  -  //获取数据库信息\n\tGetDb(dnname string) (*gorm.DB, error)\n  -\t//获取默认数据库\n\tGetDefaultDb() (*gorm.DB, error)\n\t\n \n## mqtt模块配置 (mqtt 目前使用的是阿里云IOT服务)\n```\n   mqtt:\n      type : inner\n      productKey : key\n      deviceSecret: secret\n      deviceName:  name\n```\n\n## web模块功能\n```\n  web:\n      type : inner\n      addr: 0.0.0.0\n      port: 8080\n      staticFileUrl: \"http://127.0.0.1:8080\"\n      staticFileVersion : \"1001\"\n      viewsRoot: \"./views\"\n      publicRoot: \"./public\"\n      sotragePath: \"./storage\"\n      allowOrigins:\n          - \"http://127.0.0.1:8080\"\n          - \"http://localhost:10086\"\n          - \"http://127.0.0.1:88\"\n```\n\n## docker服务化支持实现一个评论的服务,具体实现可以参考commentModuel \n\n### 这里我把编译好多程序命名为gatwway , 下面是gateway的配置文件\n```\napp:\n  logFilterCategories : \"EventQueue,Dispath\"\n  debugLevel:  debug\ndbpool:\n   default: xyt\n   xyt:\n      database: \"gateway\"\n      host: \"${DB_HOST}\"\n      username: \"${DB_USER}\"\n      password: \"${DB_PWD}\"\n      drive: \"mysql\"\nmodules:\n   comment:\n     type: inner\n     bindAddr: ${COMMENT_ADDR}\n```\n#### 上面的${var} 的配置是从程序运行的环境变量中读取, 例如 ${DB_HOST}\n\n- mv docker-compose.example.yml docker-compose.yml 修改内容为自己的配置\n- 修改 envoy.yaml 配置\n- 运行 docker-compose  up -d\n \n```\nStarting envoy   ... done\nStarting gateway ... done\n```\n\n## todo list\n- 模块停止\n- 清空模块队列中的任务\n- 平滑停止,主程序在所有模块的队列中的任务执行完毕后停止\n- 讲当前模块中的任务做磁盘持久化\n\n## 在线使用案例 httt://xytschool.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgw123%2Fgmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgw123%2Fgmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgw123%2Fgmq/lists"}