├── .gitignore
├── LICENSE
├── README.md
├── db
└── lzgyy-platform.sql
├── lzggy-config
├── lzggy-druid-config
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── lzgyy
│ │ │ └── config
│ │ │ └── druid
│ │ │ ├── DruidConfiguration.java
│ │ │ └── DruidPropertiesConfig.java
│ │ └── resources
│ │ └── application.yml
├── lzggy-dubbo-consumer-config
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── lzgyy
│ │ └── config
│ │ └── dubbo
│ │ └── consumer
│ │ ├── DubboConsumerConfiguration.java
│ │ └── DubboConsumerPropertiesConfig.java
├── lzggy-dubbo-provider-config
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── lzgyy
│ │ └── config
│ │ └── dubbo
│ │ └── provider
│ │ ├── DubboProviderConfiguration.java
│ │ └── DubboProviderPropertiesConfig.java
├── lzggy-swagger-config
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── lzgyy
│ │ │ └── config
│ │ │ └── swagger
│ │ │ └── SwaggerConfig.java
│ │ └── resources
│ │ └── application-swagger.yml
└── pom.xml
├── lzgyy-common
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── lzgyy
│ └── common
│ ├── codec
│ ├── DigestUtils.java
│ ├── EncodeUtils.java
│ └── Md5Utils.java
│ ├── idgen
│ ├── IdGenerate.java
│ └── IdWorker.java
│ ├── io
│ ├── FileUtils.java
│ ├── IOUtils.java
│ └── ResourceUtils.java
│ ├── lang
│ ├── DateUtils.java
│ ├── ExceptionUtils.java
│ ├── ObjectToMapUtils.java
│ ├── ObjectUtils.java
│ ├── StringUtils.java
│ └── TimeUtils.java
│ ├── network
│ ├── IpUtils.java
│ └── MacUtils.java
│ ├── utils
│ ├── AmountUtil.java
│ ├── ArithUtil.java
│ ├── FastJsonConvert.java
│ ├── HttpServletRequestReader.java
│ ├── JsonUtil.java
│ ├── RequestUtils.java
│ ├── ResponseUtils.java
│ ├── SortUtils.java
│ └── UserAgentUtils.java
│ ├── validator
│ └── bean
│ │ └── BeanValidators.java
│ └── web
│ ├── CookieUtils.java
│ └── http
│ ├── HttpClientUtils.java
│ └── SpingRequestContextHolder.java
├── lzgyy-core
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── lzgyy
│ └── core
│ ├── constant
│ └── Const.java
│ ├── dao
│ ├── CrudDao.java
│ └── jdbc
│ │ ├── BaseJdbcDao.java
│ │ └── JsonRowMapper.java
│ ├── entity
│ ├── PageQuery.java
│ ├── PageQueryHelp.java
│ └── PageResult.java
│ ├── io
│ └── PropertiesConfig.java
│ └── utils
│ └── PropertiesUtil.java
├── lzgyy-manage
├── lzggy-dubbo-admin-war
│ ├── .gitignore
│ └── dubbo-admin-2.6.0.war
└── pom.xml
├── lzgyy-plugins
├── lzgyy-elasticsearch-plugin
│ ├── .gitignore
│ └── pom.xml
├── lzgyy-iot-client
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── lzgyy
│ │ │ │ └── plugins
│ │ │ │ └── iot
│ │ │ │ └── client
│ │ │ │ ├── ClientApplication.java
│ │ │ │ ├── SubListener.java
│ │ │ │ └── mqtt
│ │ │ │ ├── auto
│ │ │ │ ├── MqttListener.java
│ │ │ │ ├── MqttMessageListener.java
│ │ │ │ └── MqttProducerConfigure.java
│ │ │ │ ├── bootstrap
│ │ │ │ ├── AbsMqttProducer.java
│ │ │ │ ├── AbstractBootstrapClient.java
│ │ │ │ ├── BootstrapClient.java
│ │ │ │ ├── MqttApi.java
│ │ │ │ ├── MqttProducer.java
│ │ │ │ ├── Producer.java
│ │ │ │ ├── bean
│ │ │ │ │ ├── SendMqttMessage.java
│ │ │ │ │ └── SubMessage.java
│ │ │ │ ├── cache
│ │ │ │ │ └── Cache.java
│ │ │ │ ├── channel
│ │ │ │ │ └── MqttHandlerServiceService.java
│ │ │ │ ├── handler
│ │ │ │ │ ├── ClientMqttHandlerService.java
│ │ │ │ │ ├── DefaultMqttHandler.java
│ │ │ │ │ ├── MqttHander.java
│ │ │ │ │ ├── MqttHandlerIntf.java
│ │ │ │ │ └── ServerMqttHandlerService.java
│ │ │ │ └── scan
│ │ │ │ │ ├── SacnScheduled.java
│ │ │ │ │ └── ScanRunnable.java
│ │ │ │ ├── config
│ │ │ │ └── ConnectOptions.java
│ │ │ │ ├── enums
│ │ │ │ ├── ConfirmStatus.java
│ │ │ │ ├── ProtocolEnum.java
│ │ │ │ ├── QosStatus.java
│ │ │ │ ├── SessionStatus.java
│ │ │ │ └── SubStatus.java
│ │ │ │ ├── ip
│ │ │ │ └── IpUtils.java
│ │ │ │ ├── pool
│ │ │ │ ├── DefaultThreadFactory.java
│ │ │ │ ├── ExecutorQueue.java
│ │ │ │ ├── Scheduled.java
│ │ │ │ └── StandardThreadExecutor.java
│ │ │ │ ├── ssl
│ │ │ │ ├── SecureSocketKeyStore.java
│ │ │ │ ├── SecureSocketSslContextFactory.java
│ │ │ │ ├── SecureSokcetTrustManagerFactory.java
│ │ │ │ ├── StreamReader.java
│ │ │ │ └── X509CertTool.java
│ │ │ │ └── util
│ │ │ │ ├── ByteBufUtil.java
│ │ │ │ ├── IdWorker.java
│ │ │ │ ├── MessageId.java
│ │ │ │ └── SpringBeanUtils.java
│ │ └── resources
│ │ │ ├── application.yml
│ │ │ ├── banner.txt
│ │ │ └── keystore
│ │ │ └── client.jks
│ │ └── test
│ │ └── java
│ │ └── example
│ │ └── MqttMain.java
├── lzgyy-iot-core
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── lzgyy
│ │ └── plugins
│ │ └── iot
│ │ └── core
│ │ ├── auth
│ │ └── service
│ │ │ └── IAuthService.java
│ │ ├── broker
│ │ ├── internal
│ │ │ ├── bean
│ │ │ │ └── InternalMessage.java
│ │ │ └── service
│ │ │ │ └── IInternalCommunication.java
│ │ └── protocol
│ │ │ └── abs
│ │ │ ├── AConnect.java
│ │ │ ├── ADisConnect.java
│ │ │ ├── APingReq.java
│ │ │ ├── APubAck.java
│ │ │ ├── APubComp.java
│ │ │ ├── APubRec.java
│ │ │ ├── APubRel.java
│ │ │ ├── APublish.java
│ │ │ ├── ASubscribe.java
│ │ │ └── AUnSubscribe.java
│ │ └── store
│ │ ├── message
│ │ ├── bean
│ │ │ ├── DupPubRelMessageStore.java
│ │ │ ├── DupPublishMessageStore.java
│ │ │ └── RetainMessageStore.java
│ │ └── service
│ │ │ ├── IDupPubRelMessageStoreService.java
│ │ │ ├── IDupPublishMessageStoreService.java
│ │ │ ├── IMessageIdService.java
│ │ │ └── IRetainMessageStoreService.java
│ │ ├── session
│ │ ├── bean
│ │ │ └── SessionStore.java
│ │ └── service
│ │ │ └── ISessionStoreService.java
│ │ └── subscribe
│ │ ├── bean
│ │ └── SubscribeStore.java
│ │ └── service
│ │ └── ISubscribeStoreService.java
├── lzgyy-iot-service
│ ├── .gitignore
│ ├── MQTT协议.docx
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── lzgyy
│ │ │ │ └── plugins
│ │ │ │ └── iot
│ │ │ │ ├── BrokerApplication.java
│ │ │ │ └── service
│ │ │ │ └── mqtt
│ │ │ │ ├── auth
│ │ │ │ ├── service
│ │ │ │ │ └── impl
│ │ │ │ │ │ └── AuthService.java
│ │ │ │ └── util
│ │ │ │ │ ├── PwdUtil.java
│ │ │ │ │ └── RsaKeyUtil.java
│ │ │ │ ├── broker
│ │ │ │ ├── codec
│ │ │ │ │ └── MqttWebSocketCodec.java
│ │ │ │ ├── config
│ │ │ │ │ └── BrokerProperties.java
│ │ │ │ ├── handler
│ │ │ │ │ └── MqttBrokerHandler.java
│ │ │ │ ├── internal
│ │ │ │ │ └── InternalCommunication.java
│ │ │ │ ├── protocol
│ │ │ │ │ ├── Connect.java
│ │ │ │ │ ├── DisConnect.java
│ │ │ │ │ ├── PingReq.java
│ │ │ │ │ ├── ProtocolProcess.java
│ │ │ │ │ ├── PubAck.java
│ │ │ │ │ ├── PubComp.java
│ │ │ │ │ ├── PubRec.java
│ │ │ │ │ ├── PubRel.java
│ │ │ │ │ ├── Publish.java
│ │ │ │ │ ├── Subscribe.java
│ │ │ │ │ └── UnSubscribe.java
│ │ │ │ └── service
│ │ │ │ │ └── MqttBrokerServer.java
│ │ │ │ └── store
│ │ │ │ ├── config
│ │ │ │ ├── IgniteAutoConfig.java
│ │ │ │ └── IgniteProperties.java
│ │ │ │ ├── message
│ │ │ │ └── service
│ │ │ │ │ └── impl
│ │ │ │ │ ├── DupPubRelMessageStoreService.java
│ │ │ │ │ ├── DupPublishMessageStoreService.java
│ │ │ │ │ ├── MessageIdService.java
│ │ │ │ │ └── RetainMessageStoreService.java
│ │ │ │ ├── session
│ │ │ │ └── service
│ │ │ │ │ └── impl
│ │ │ │ │ └── SessionStoreService.java
│ │ │ │ └── subscribe
│ │ │ │ └── service
│ │ │ │ └── impl
│ │ │ │ └── SubscribeStoreService.java
│ │ │ └── resources
│ │ │ ├── application.yml
│ │ │ ├── banner.txt
│ │ │ └── keystore
│ │ │ ├── auth-private.key
│ │ │ ├── client-cert.pem
│ │ │ ├── client-key.pem
│ │ │ ├── client-req.csr
│ │ │ ├── client.jks
│ │ │ ├── client.p12
│ │ │ ├── client_rsa.cer
│ │ │ ├── root-cert.jks
│ │ │ ├── root-cert.p12
│ │ │ ├── root-cert.pem
│ │ │ ├── root-cert.srl
│ │ │ ├── root-key.pem
│ │ │ ├── root-req.csr
│ │ │ ├── server-cert.pem
│ │ │ ├── server-key.pem
│ │ │ ├── server-req.csr
│ │ │ ├── server.jks
│ │ │ ├── server.p12
│ │ │ └── server_rsa.cer
│ └── 证书
│ │ ├── 参考
│ │ ├── keytool生成证书
│ │ ├── openssl 根证书 服务器证书 客户端证书
│ │ ├── 关于证书
│ │ └── 证书生成
│ │ ├── 证书介绍
│ │ ├── 证书制作
│ │ └── 证书格式
├── lzgyy-quartz-plugin
│ ├── .gitignore
│ ├── db
│ │ └── job_entity.sql
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── lzgyy
│ │ │ ├── config
│ │ │ └── quartz
│ │ │ │ └── QuartzConfiguration.java
│ │ │ └── plugins
│ │ │ └── quartz
│ │ │ ├── entity
│ │ │ └── JobEntity.java
│ │ │ ├── job
│ │ │ └── DynamicJob.java
│ │ │ ├── mapper
│ │ │ ├── JobMapper.java
│ │ │ └── xml
│ │ │ │ └── JobMapper.xml
│ │ │ └── service
│ │ │ └── JobService.java
│ │ └── resources
│ │ ├── application.yml
│ │ └── quartz.properties
├── lzgyy-redis-interf
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── lzgyy
│ │ └── plugins
│ │ └── redis
│ │ └── service
│ │ └── RedisService.java
├── lzgyy-redis-service
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── lzgyy
│ │ │ └── plugins
│ │ │ └── redis
│ │ │ ├── RedisServiceProviderApp.java
│ │ │ ├── config
│ │ │ ├── RedisCacheConfig.java
│ │ │ └── RedisSerializerConfig.java
│ │ │ └── service
│ │ │ └── impl
│ │ │ └── RedisServiceImpl.java
│ │ └── resources
│ │ └── application.properties
└── pom.xml
├── lzgyy-products
├── lzgyy-platform-api
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── lzgyy
│ │ │ └── platform
│ │ │ ├── PlatformApiConsumerApp.java
│ │ │ └── modules
│ │ │ └── demo
│ │ │ └── controller
│ │ │ └── DemoController.java
│ │ └── resources
│ │ ├── applicationContext-plug.xml
│ │ ├── banner.txt
│ │ ├── config
│ │ ├── application-dev.yml
│ │ └── application.yml
│ │ ├── log4j.properties
│ │ └── spring
│ │ └── dubbo-consumer.xml
├── lzgyy-platform-interf
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── lzgyy
│ │ └── platform
│ │ ├── modules
│ │ ├── demo
│ │ │ └── service
│ │ │ │ └── DemoService.java
│ │ └── test
│ │ │ ├── entity
│ │ │ └── Test.java
│ │ │ └── service
│ │ │ └── TestService.java
│ │ └── serial
│ │ └── SerializationOptimizerImpl.java
├── lzgyy-platform-service
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── lzgyy
│ │ │ └── platform
│ │ │ ├── PlatformServiceProviderApp.java
│ │ │ └── modules
│ │ │ ├── demo
│ │ │ ├── dao
│ │ │ │ └── DemoJdbcDao.java
│ │ │ └── service
│ │ │ │ └── imp
│ │ │ │ └── DemoServiceImpl.java
│ │ │ └── test
│ │ │ ├── mapper
│ │ │ ├── TestMapper.java
│ │ │ └── xml
│ │ │ │ └── TestMapper.xml
│ │ │ └── service
│ │ │ └── impl
│ │ │ └── TestServiceImpl.java
│ │ └── resources
│ │ ├── applicationContext-plug.xml
│ │ ├── banner.txt
│ │ ├── config
│ │ ├── application-dev.yml
│ │ ├── application.yml
│ │ └── cache.yml
│ │ ├── logback-spring.xml
│ │ ├── mybatis
│ │ ├── applicationContext-mybatis.xml
│ │ └── mybatis-config.xml
│ │ └── spring
│ │ ├── dubbo-provider.xml
│ │ └── spring-tx.xml
├── lzgyy-platform-sso
│ ├── .gitignore
│ └── pom.xml
├── lzgyy-platform-web
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── lzgyy
│ │ │ └── platform
│ │ │ ├── PlatformServiceConsumerApp.java
│ │ │ └── modules
│ │ │ └── test
│ │ │ └── controller
│ │ │ └── TestController.java
│ │ └── resources
│ │ ├── applicationContext-plug.xml
│ │ ├── banner.txt
│ │ ├── config
│ │ ├── application-dev.yml
│ │ └── application.yml
│ │ ├── log4j.properties
│ │ └── spring
│ │ └── dubbo-consumer.xml
└── pom.xml
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.settings/
3 | .classpath
4 | .project
5 | .settings
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # lzgyy
2 |
3 | #### 项目介绍
4 | **平台简介**
5 | 基于springboot容器,zokeeper分布式协调服务,dubbo分布式服务框架,redis缓存,spring jdbctemplate,mybatis持久层框架,mysql数据库等,加入netty+mqtt
6 |
7 | #### 软件架构
8 |
9 | ### 项目结构
10 | ```
11 | lzgyy
12 | ├── db 数据库文件存放目录
13 | ├── lzgyy-config 配置相关
14 | ├── lzgyy-druid-config 数据库连接池
15 | ├── lzgyy-dubbo-consumer-config dubbo消费者通用配置
16 | ├── lzgyy-dubbo-provider-config dubbo生产者通用配置
17 | ├── lzgyy-swagger-config swagger swagger接口文档生成配置
18 | ├── lzgyy-common 工具类
19 | ├── lzgyy-core 核心类
20 | ├── lzgyy-manage 管理服务
21 | ├── lzgyy-dubbo-admin-war dubbo管理平台war包
22 | ├── lzgyy-plugins 插件包
23 | ├── lzgyy-elasticsearch-plugin es搜索引擎
24 | ├── lzgyy-iot-client 物联网客户端
25 | ├── lzgyy-iot-core 物联网核心类
26 | ├── lzgyy-iot-service 物联网服务端
27 | ├── lzgyy-quartz-plugin 定时任务器
28 | ├── lzgyy-redis-interf 缓存接口
29 | ├── lzgyy-redis-service 缓存服务类(生产者)
30 | ├── lzgyy-products
31 | ├── lzgyy-platform-api 平台API接口
32 | ├── lzgyy-platform-interf 平台接口
33 | ├── lzgyy-platform-service 平台服务类(生产者)
34 | ├── lzgyy-platform-web 平台网页端(消费者)
35 | ```
36 | ### 项目备注
37 |
38 | 1. 具体项目结构后续或许会有所更新变动,仅供参考
39 | 2. “缓存服务类”、“lzgyy-platform-service”、“lzgyy-platform-web”启动方式配置有差异,后续以“缓存服务类”配置为准。
40 | 3. 关于dubbo问题请参考 http://dubbo.apache.org/zh-cn/
41 |
42 | #### 测试例子
43 |
44 | 1. 生成者消费者运行测试
45 | 1.1 运行平台服务端(生产者)项目lzgyy-platform-service,路径:com.lzgyy.platform.PlatformServiceProviderApp.java --> Run As
46 | 1.2 运行平台网页端(消费者)项目lzgyy-platform-web,路径:com.lzgyy.platform.PlatformServiceConsumerApp.java --> Run As
47 | 1.3 打开浏览器录入以下路径,即可测试
48 | http://localhost:9999/test/v1.0/getDemoList.json
49 | http://localhost:9999/test/v1.0/getDemoList2.json
50 | 2. swagger接口文档测试
51 | 2.1 运行平台API接口(消费者)项目lzgyy-platform-api,路径:com.lzgyy.platform.PlatformApiConsumerApp.java --> Run As
52 | 2.1 打开浏览器录入以下路径,即可测试
53 | http://localhost:9999/docs.html
54 | 3. netty mqtt运行测试
55 | 1.1 运行物联网服务器端,项目lzgyy-iot-service,路径:com.lzgyy.plugins.iot.ClientApplication.java --> Run As
56 | 或路径:example.MqttMain.java --> Run As
57 | 1.2 运行物联网客户端,项目lzgyy-iot-client,路径:com.lzgyy.plugins.iot.client.BrokerApplication.java --> Run As
58 |
--------------------------------------------------------------------------------
/db/lzgyy-platform.sql:
--------------------------------------------------------------------------------
1 | /*
2 | Navicat MySQL Data Transfer
3 |
4 | Source Server : 192.168.0.114
5 | Source Server Version : 50625
6 | Source Host : 192.168.0.114:3306
7 | Source Database : lzgyy-platform
8 |
9 | Target Server Type : MYSQL
10 | Target Server Version : 50625
11 | File Encoding : 65001
12 |
13 | Date: 2018-10-26 15:28:06
14 | */
15 |
16 | SET FOREIGN_KEY_CHECKS=0;
17 |
18 | -- ----------------------------
19 | -- Table structure for demo
20 | -- ----------------------------
21 | DROP TABLE IF EXISTS `demo`;
22 | CREATE TABLE `demo` (
23 | `id` bigint(40) NOT NULL COMMENT 'id',
24 | `name` varchar(80) DEFAULT NULL,
25 | `createUser` bigint(40) DEFAULT NULL,
26 | `createDate` datetime DEFAULT NULL,
27 | `updateUser` bigint(40) DEFAULT NULL,
28 | `updateDate` datetime DEFAULT NULL,
29 | `deleteState` char(1) NOT NULL,
30 | PRIMARY KEY (`id`)
31 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
32 |
33 | -- ----------------------------
34 | -- Records of demo
35 | -- ----------------------------
36 | INSERT INTO `demo` VALUES ('2', 'd1', '222', '2018-10-25 14:02:04', '2222', '2018-10-25 14:02:14', '1');
37 |
38 | -- ----------------------------
39 | -- Table structure for test
40 | -- ----------------------------
41 | DROP TABLE IF EXISTS `test`;
42 | CREATE TABLE `test` (
43 | `id` bigint(40) NOT NULL COMMENT 'id',
44 | `name` varchar(80) DEFAULT NULL,
45 | `createUser` bigint(40) DEFAULT NULL,
46 | `createDate` datetime DEFAULT NULL,
47 | `updateUser` bigint(40) DEFAULT NULL,
48 | `updateDate` datetime DEFAULT NULL,
49 | `deleteState` char(1) NOT NULL,
50 | PRIMARY KEY (`id`)
51 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
52 |
53 | -- ----------------------------
54 | -- Records of test
55 | -- ----------------------------
56 | INSERT INTO `test` VALUES ('1', 't1', '1111', '2018-10-25 14:02:04', '1111', '2018-10-25 14:02:14', '1');
57 | INSERT INTO `test` VALUES ('2', 't2', '2222', '2018-10-25 14:03:11', '2222', '2018-10-25 14:03:16', '1');
58 |
--------------------------------------------------------------------------------
/lzggy-config/lzggy-druid-config/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzggy-config/lzggy-druid-config/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.lzgyy
6 | lzgyy-config
7 | 0.0.1-SNAPSHOT
8 |
9 | lzgyy-druid-config
10 |
11 |
12 |
13 | ch.qos.logback
14 | logback-classic
15 |
16 |
17 |
18 | javax.servlet
19 | javax.servlet-api
20 | provided
21 |
22 |
23 |
24 | com.alibaba
25 | druid-spring-boot-starter
26 |
27 |
28 |
--------------------------------------------------------------------------------
/lzggy-config/lzggy-druid-config/src/main/java/com/lzgyy/config/druid/DruidPropertiesConfig.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.config.druid;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 |
5 | /**
6 | * druid配置
7 | */
8 | @ConfigurationProperties(prefix = "druid.access")
9 | public class DruidPropertiesConfig {
10 |
11 | private String whitelist;
12 | private String username;
13 | private String password;
14 | private String logSlowSql;
15 | private String resetEnable;
16 |
17 | public String getWhitelist() {
18 | return whitelist;
19 | }
20 | public void setWhitelist(String whitelist) {
21 | this.whitelist = whitelist;
22 | }
23 | public String getUsername() {
24 | return username;
25 | }
26 | public void setUsername(String username) {
27 | this.username = username;
28 | }
29 | public String getPassword() {
30 | return password;
31 | }
32 | public void setPassword(String password) {
33 | this.password = password;
34 | }
35 | public String getLogSlowSql() {
36 | return logSlowSql;
37 | }
38 | public void setLogSlowSql(String logSlowSql) {
39 | this.logSlowSql = logSlowSql;
40 | }
41 | public String getResetEnable() {
42 | return resetEnable;
43 | }
44 | public void setResetEnable(String resetEnable) {
45 | this.resetEnable = resetEnable;
46 | }
47 | }
--------------------------------------------------------------------------------
/lzggy-config/lzggy-druid-config/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | ########### druid ##########
2 | druid :
3 | access :
4 | whitelist :
5 | username : root
6 | password : root
7 | logSlowSql : true
8 | resetEnable : false
--------------------------------------------------------------------------------
/lzggy-config/lzggy-dubbo-consumer-config/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzggy-config/lzggy-dubbo-consumer-config/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.lzgyy
6 | lzgyy-config
7 | 0.0.1-SNAPSHOT
8 |
9 | lzgyy-dubbo-consumer-config
10 |
11 |
12 |
13 | org.springframework.boot
14 | spring-boot-starter-web
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-data-jpa
19 |
20 |
21 |
22 |
23 |
24 | ch.qos.logback
25 | logback-classic
26 |
27 |
28 |
29 | com.alibaba
30 | dubbo
31 |
32 |
33 | spring
34 | org.springframework
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/lzggy-config/lzggy-dubbo-consumer-config/src/main/java/com/lzgyy/config/dubbo/consumer/DubboConsumerConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.config.dubbo.consumer;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 |
10 | import com.alibaba.dubbo.config.ApplicationConfig;
11 | import com.alibaba.dubbo.config.ConsumerConfig;
12 | import com.alibaba.dubbo.config.RegistryConfig;
13 |
14 | /**
15 | * dubbo消费者初始化
16 | */
17 | @Configuration
18 | @EnableConfigurationProperties(DubboConsumerPropertiesConfig.class)
19 | public class DubboConsumerConfiguration {
20 |
21 | private static final Logger logger = LoggerFactory.getLogger(DubboConsumerConfiguration.class);
22 |
23 | @Autowired
24 | private DubboConsumerPropertiesConfig dubboPropertiesConfig;
25 |
26 | @Bean
27 | public ApplicationConfig applicationConfig() {
28 | logger.info("***** DubboConsumerConfiguration ApplicationConfig ...");
29 | ApplicationConfig applicationConfig = new ApplicationConfig();
30 | applicationConfig.setName(dubboPropertiesConfig.getApplicationName());
31 | applicationConfig.setOwner(dubboPropertiesConfig.getApplicationOwner());
32 | logger.info("***** DubboConsumerConfiguration ApplicationConfig finished ");
33 | return applicationConfig;
34 | }
35 |
36 | @Bean
37 | public ConsumerConfig consumerConfig() {
38 | logger.info("***** DubboConsumerConfiguration ConsumerConfig ...");
39 | ConsumerConfig consumerConfig = new ConsumerConfig();
40 | consumerConfig.setTimeout(dubboPropertiesConfig.getTimeout());
41 | consumerConfig.setCheck(dubboPropertiesConfig.isCheck());
42 | logger.info("***** DubboConsumerConfiguration ConsumerConfig finished");
43 | return consumerConfig;
44 | }
45 |
46 | @Bean
47 | public RegistryConfig registryConfig() {
48 | logger.info("***** DubboConsumerConfiguration RegistryConfig ...");
49 | RegistryConfig registryConfig = new RegistryConfig();
50 | registryConfig.setAddress(dubboPropertiesConfig.getRegistryAddress());
51 | registryConfig.setClient(dubboPropertiesConfig.getRegistryClient());
52 | registryConfig.setProtocol(dubboPropertiesConfig.getRegistryProtocol());
53 | logger.info("***** DubboConsumerConfiguration RegistryConfig finished");
54 | return registryConfig;
55 | }
56 | }
--------------------------------------------------------------------------------
/lzggy-config/lzggy-dubbo-consumer-config/src/main/java/com/lzgyy/config/dubbo/consumer/DubboConsumerPropertiesConfig.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.config.dubbo.consumer;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 |
5 | /**
6 | * dubbo消费者配置
7 | */
8 | @ConfigurationProperties(prefix = "dubbo")
9 | public class DubboConsumerPropertiesConfig {
10 |
11 | /**
12 | * 注册地址
13 | */
14 | private String registryAddress;
15 |
16 | /**
17 | * 注册客户端
18 | */
19 | private String registryClient;
20 |
21 | /**
22 | * 注册协议
23 | */
24 | private String registryProtocol;
25 |
26 | /**
27 | * 应用名称
28 | */
29 | private String applicationName;
30 |
31 | /**
32 | * 应用维护者
33 | */
34 | private String applicationOwner;
35 |
36 | /**
37 | * 超时
38 | */
39 | private Integer timeout;
40 |
41 | private boolean check;
42 |
43 |
44 | public String getRegistryAddress() {
45 | return registryAddress;
46 | }
47 | public void setRegistryAddress(String registryAddress) {
48 | this.registryAddress = registryAddress;
49 | }
50 | public String getRegistryClient() {
51 | return registryClient;
52 | }
53 | public void setRegistryClient(String registryClient) {
54 | this.registryClient = registryClient;
55 | }
56 | public String getRegistryProtocol() {
57 | return registryProtocol;
58 | }
59 | public void setRegistryProtocol(String registryProtocol) {
60 | this.registryProtocol = registryProtocol;
61 | }
62 | public String getApplicationName() {
63 | return applicationName;
64 | }
65 | public void setApplicationName(String applicationName) {
66 | this.applicationName = applicationName;
67 | }
68 | public String getApplicationOwner() {
69 | return applicationOwner;
70 | }
71 | public void setApplicationOwner(String applicationOwner) {
72 | this.applicationOwner = applicationOwner;
73 | }
74 | public Integer getTimeout() {
75 | return timeout;
76 | }
77 | public void setTimeout(Integer timeout) {
78 | this.timeout = timeout;
79 | }
80 | public boolean isCheck() {
81 | return check;
82 | }
83 | public void setCheck(boolean check) {
84 | this.check = check;
85 | }
86 | }
--------------------------------------------------------------------------------
/lzggy-config/lzggy-dubbo-provider-config/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzggy-config/lzggy-dubbo-provider-config/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.lzgyy
5 | lzgyy-config
6 | 0.0.1-SNAPSHOT
7 |
8 | lzgyy-dubbo-provider-config
9 |
10 |
11 | com.lzgyy
12 | lzgyy-druid-config
13 | 0.0.1-SNAPSHOT
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-data-jpa
23 |
24 |
25 |
26 |
27 |
28 | com.alibaba
29 | dubbo
30 |
31 |
32 | spring
33 | org.springframework
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/lzggy-config/lzggy-dubbo-provider-config/src/main/java/com/lzgyy/config/dubbo/provider/DubboProviderConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.config.dubbo.provider;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 |
10 | import com.alibaba.dubbo.common.utils.StringUtils;
11 | import com.alibaba.dubbo.config.ApplicationConfig;
12 | import com.alibaba.dubbo.config.RegistryConfig;
13 |
14 | /**
15 | * dubbo生产者初始化
16 | */
17 | @Configuration
18 | @EnableConfigurationProperties(DubboProviderPropertiesConfig.class)
19 | public class DubboProviderConfiguration {
20 |
21 | private static final Logger logger = LoggerFactory.getLogger(DubboProviderConfiguration.class);
22 |
23 | @Autowired
24 | private DubboProviderPropertiesConfig dubboPropertiesConfig;
25 |
26 | @Bean
27 | public ApplicationConfig applicationConfig() {
28 | logger.info("***** DubboProviderConfiguration ApplicationConfig ...");
29 | ApplicationConfig applicationConfig = new ApplicationConfig();
30 | applicationConfig.setName(dubboPropertiesConfig.getApplicationName());
31 | applicationConfig.setOwner(dubboPropertiesConfig.getApplicationOwner());
32 | logger.info("***** DubboProviderConfiguration ApplicationConfig finished");
33 | return applicationConfig;
34 | }
35 |
36 | @Bean
37 | public RegistryConfig registryConfig() {
38 | logger.info("***** DubboProviderConfiguration RegistryConfig ...");
39 | RegistryConfig registryConfig = new RegistryConfig();
40 | registryConfig.setAddress(dubboPropertiesConfig.getRegistryAddress());
41 | if(!StringUtils.isBlank(dubboPropertiesConfig.getRegistryClient())) {
42 | registryConfig.setClient(dubboPropertiesConfig.getRegistryClient());
43 | }
44 |
45 | if(!StringUtils.isBlank(dubboPropertiesConfig.getRegistryProtocol())) {
46 | registryConfig.setProtocol(dubboPropertiesConfig.getRegistryProtocol());
47 | }
48 |
49 | if(null != dubboPropertiesConfig.getPort()) {
50 | registryConfig.setPort(dubboPropertiesConfig.getPort());
51 | }
52 | logger.info("***** DubboProviderConfiguration RegistryConfig finished");
53 | return registryConfig;
54 | }
55 | }
--------------------------------------------------------------------------------
/lzggy-config/lzggy-dubbo-provider-config/src/main/java/com/lzgyy/config/dubbo/provider/DubboProviderPropertiesConfig.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.config.dubbo.provider;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 |
5 | /**
6 | * dubbo生产者配置
7 | */
8 | @ConfigurationProperties(prefix = "dubbo")
9 | public class DubboProviderPropertiesConfig {
10 |
11 | /**
12 | * 注册地址
13 | */
14 | private String registryAddress;
15 |
16 | /**
17 | * 注册客户端
18 | */
19 | private String registryClient;
20 |
21 | /**
22 | * 注册协议
23 | */
24 | private String registryProtocol;
25 |
26 | /**
27 | * 应用名称
28 | */
29 | private String applicationName;
30 |
31 | /**
32 | * 应用维护者
33 | */
34 | private String applicationOwner;
35 |
36 | /**
37 | * dubbo 绑定的端口号
38 | */
39 | private Integer port;
40 |
41 |
42 | public String getRegistryAddress() {
43 | return registryAddress;
44 | }
45 | public void setRegistryAddress(String registryAddress) {
46 | this.registryAddress = registryAddress;
47 | }
48 | public String getRegistryClient() {
49 | return registryClient;
50 | }
51 | public void setRegistryClient(String registryClient) {
52 | this.registryClient = registryClient;
53 | }
54 | public String getRegistryProtocol() {
55 | return registryProtocol;
56 | }
57 | public void setRegistryProtocol(String registryProtocol) {
58 | this.registryProtocol = registryProtocol;
59 | }
60 | public String getApplicationName() {
61 | return applicationName;
62 | }
63 | public void setApplicationName(String applicationName) {
64 | this.applicationName = applicationName;
65 | }
66 | public String getApplicationOwner() {
67 | return applicationOwner;
68 | }
69 | public void setApplicationOwner(String applicationOwner) {
70 | this.applicationOwner = applicationOwner;
71 | }
72 | public Integer getPort() {
73 | return port;
74 | }
75 | public void setPort(Integer port) {
76 | this.port = port;
77 | }
78 | }
--------------------------------------------------------------------------------
/lzggy-config/lzggy-swagger-config/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzggy-config/lzggy-swagger-config/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.lzgyy
5 | lzgyy-config
6 | 0.0.1-SNAPSHOT
7 |
8 | lzgyy-swagger-config
9 |
10 |
11 | org.springframework.boot
12 | spring-boot-starter-web
13 |
14 |
15 |
16 | io.springfox
17 | springfox-swagger2
18 |
19 |
20 | com.github.caspar-chen
21 | swagger-ui-layer
22 |
23 |
24 |
--------------------------------------------------------------------------------
/lzggy-config/lzggy-swagger-config/src/main/java/com/lzgyy/config/swagger/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.config.swagger;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.context.annotation.PropertySource;
8 | import org.springframework.web.context.request.async.DeferredResult;
9 |
10 | import springfox.documentation.service.ApiInfo;
11 | import springfox.documentation.spi.DocumentationType;
12 | import springfox.documentation.spring.web.plugins.Docket;
13 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
14 |
15 | @Configuration
16 | @EnableSwagger2
17 | @PropertySource(value = "classpath:application-swagger.yml", encoding = "utf-8")
18 | @ConfigurationProperties(prefix = "swagger")
19 | public class SwaggerConfig {
20 |
21 | //-------------swagger配置------------
22 | @Value("${title}")
23 | private String title;
24 | @Value("${description}")
25 | private String description;
26 | @Value("${version}")
27 | private String version;
28 | @Value("${termsOfServiceUrl}")
29 | private String termsOfServiceUrl;
30 | @Value("${contact}")
31 | private String contact;
32 | @Value("${license}")
33 | private String license;
34 | @Value("${licenseUrl}")
35 | private String licenseUrl;
36 |
37 | @Bean
38 | public Docket ProductApi() {
39 | return new Docket(DocumentationType.SWAGGER_2)
40 | .genericModelSubstitutes(DeferredResult.class)
41 | .useDefaultResponseMessages(false)
42 | .forCodeGeneration(false)
43 | .pathMapping("/")
44 | .select()
45 | .build()
46 | .apiInfo(productApiInfo());
47 | }
48 |
49 | private ApiInfo productApiInfo() {
50 | return new ApiInfo(title,
51 | description,
52 | version,
53 | termsOfServiceUrl,
54 | contact,
55 | license,
56 | licenseUrl);
57 | }
58 | }
--------------------------------------------------------------------------------
/lzggy-config/lzggy-swagger-config/src/main/resources/application-swagger.yml:
--------------------------------------------------------------------------------
1 | ########### swagger ##########
2 | swagger :
3 | title : 工业云平台数据接口文档
4 | description : 文档描述
5 | version : 1.0.0
6 | termsOfServiceUrl : API TERMS URL
7 | contact : 联系人邮箱
8 | license : license
9 | licenseUrl : license url
--------------------------------------------------------------------------------
/lzggy-config/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.lzgyy
6 | lzgyy
7 | 0.0.1-SNAPSHOT
8 |
9 | lzgyy-config
10 | pom
11 |
12 | lzgyy-druid-config
13 | lzgyy-dubbo-consumer-config
14 | lzgyy-dubbo-provider-config
15 | lzgyy-swagger-config
16 |
17 |
--------------------------------------------------------------------------------
/lzgyy-common/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzgyy-common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | com.lzgyy
6 | lzgyy
7 | 0.0.1-SNAPSHOT
8 |
9 | 4.0.0
10 | com.lzgyy
11 | lzgyy-common
12 | 0.0.1-SNAPSHOT
13 | lzgyy-common
14 | http://maven.apache.org
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter-web
20 |
21 |
22 |
23 | org.apache.commons
24 | commons-lang3
25 |
26 |
27 | commons-io
28 | commons-io
29 |
30 |
31 | commons-codec
32 | commons-codec
33 |
34 |
35 |
36 | ch.qos.logback
37 | logback-classic
38 |
39 |
40 |
41 | nl.bitwalker
42 | UserAgentUtils
43 |
44 |
45 |
46 | com.google.guava
47 | guava
48 |
49 |
50 |
51 | org.apache.httpcomponents
52 | httpclient
53 |
54 |
55 |
56 | com.alibaba
57 | fastjson
58 |
59 |
60 |
61 | de.ruedigermoeller
62 | fst
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/lzgyy-common/src/main/java/com/lzgyy/common/io/IOUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
3 | */
4 | package com.lzgyy.common.io;
5 |
6 | import java.io.File;
7 | import java.io.FileInputStream;
8 | import java.io.FileNotFoundException;
9 | import java.io.FileOutputStream;
10 |
11 | /**
12 | * 数据流工具类
13 | * @author ThinkGem
14 | */
15 | public class IOUtils extends org.apache.commons.io.IOUtils {
16 |
17 | /**
18 | * 根据文件路径创建文件输入流处理 以字节为单位(非 unicode )
19 | * @param path
20 | * @return
21 | */
22 | public static FileInputStream getFileInputStream(String filepath) {
23 | FileInputStream fileInputStream = null;
24 | try {
25 | fileInputStream = new FileInputStream(filepath);
26 | } catch (FileNotFoundException e) {
27 | System.out.println("错误信息:文件不存在");
28 | e.printStackTrace();
29 | }
30 | return fileInputStream;
31 | }
32 |
33 | /**
34 | * 根据文件对象创建文件输入流处理 以字节为单位(非 unicode )
35 | * @param path
36 | * @return
37 | */
38 | public static FileInputStream getFileInputStream(File file) {
39 | FileInputStream fileInputStream = null;
40 | try {
41 | fileInputStream = new FileInputStream(file);
42 | } catch (FileNotFoundException e) {
43 | System.out.println("错误信息:文件不存在");
44 | e.printStackTrace();
45 | }
46 | return fileInputStream;
47 | }
48 |
49 | /**
50 | * 根据文件对象创建文件输出流处理 以字节为单位(非 unicode )
51 | * @param file
52 | * @param append true:文件以追加方式打开,false:则覆盖原文件的内容
53 | * @return
54 | */
55 | public static FileOutputStream getFileOutputStream(File file, boolean append) {
56 | FileOutputStream fileOutputStream = null;
57 | try {
58 | fileOutputStream = new FileOutputStream(file, append);
59 | } catch (FileNotFoundException e) {
60 | System.out.println("错误信息:文件不存在");
61 | e.printStackTrace();
62 | }
63 | return fileOutputStream;
64 | }
65 |
66 | /**
67 | * 根据文件路径创建文件输出流处理 以字节为单位(非 unicode )
68 | * @param path
69 | * @param append true:文件以追加方式打开,false:则覆盖原文件的内容
70 | * @return
71 | */
72 | public static FileOutputStream getFileOutputStream(String filepath, boolean append) {
73 | FileOutputStream fileOutputStream = null;
74 | try {
75 | fileOutputStream = new FileOutputStream(filepath, append);
76 | } catch (FileNotFoundException e) {
77 | System.out.println("错误信息:文件不存在");
78 | e.printStackTrace();
79 | }
80 | return fileOutputStream;
81 | }
82 |
83 | }
--------------------------------------------------------------------------------
/lzgyy-common/src/main/java/com/lzgyy/common/lang/ExceptionUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2005-2012 springside.org.cn
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | */
6 | package com.lzgyy.common.lang;
7 |
8 | import java.io.PrintWriter;
9 | import java.io.StringWriter;
10 |
11 | import javax.servlet.http.HttpServletRequest;
12 |
13 | /**
14 | * 关于异常的工具类.
15 | * @author calvin
16 | * @version 2014-8-19
17 | */
18 | public class ExceptionUtils {
19 |
20 | /**
21 | * 在request中获取异常类
22 | * @param request
23 | * @return
24 | */
25 | public static Throwable getThrowable(HttpServletRequest request){
26 | Throwable ex = null;
27 | if (request.getAttribute("exception") != null) {
28 | ex = (Throwable) request.getAttribute("exception");
29 | } else if (request.getAttribute("javax.servlet.error.exception") != null) {
30 | ex = (Throwable) request.getAttribute("javax.servlet.error.exception");
31 | }
32 | return ex;
33 | }
34 |
35 | /**
36 | * 将ErrorStack转化为String.
37 | */
38 | public static String getStackTraceAsString(Throwable e) {
39 | if (e == null){
40 | return "";
41 | }
42 | StringWriter stringWriter = new StringWriter();
43 | e.printStackTrace(new PrintWriter(stringWriter));
44 | return stringWriter.toString();
45 | }
46 |
47 | /**
48 | * 判断异常是否由某些底层的异常引起.
49 | */
50 | @SuppressWarnings("unchecked")
51 | public static boolean isCausedBy(Exception ex, Class extends Exception>... causeExceptionClasses) {
52 | Throwable cause = ex.getCause();
53 | while (cause != null) {
54 | for (Class extends Exception> causeClass : causeExceptionClasses) {
55 | if (causeClass.isInstance(cause)) {
56 | return true;
57 | }
58 | }
59 | cause = cause.getCause();
60 | }
61 | return false;
62 | }
63 |
64 | /**
65 | * 将CheckedException转换为UncheckedException.
66 | */
67 | public static RuntimeException unchecked(Exception e) {
68 | if (e instanceof RuntimeException) {
69 | return (RuntimeException) e;
70 | } else {
71 | return new RuntimeException(e);
72 | }
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/lzgyy-common/src/main/java/com/lzgyy/common/utils/HttpServletRequestReader.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.common.utils;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 |
7 | import javax.servlet.ServletInputStream;
8 | import javax.servlet.http.HttpServletRequest;
9 |
10 | /**
11 | * 获取HttpServletRequest请求Body中的内容
12 | */
13 | public class HttpServletRequestReader {
14 |
15 | // 字符串读取
16 | // 方法一
17 | public static String ReadAsChars(HttpServletRequest request) {
18 |
19 | BufferedReader br = null;
20 | StringBuilder sb = new StringBuilder("");
21 | try {
22 | br = request.getReader();
23 | String str;
24 | while ((str = br.readLine()) != null)
25 | {
26 | sb.append(str);
27 | }
28 | br.close();
29 | } catch (IOException e) {
30 | e.printStackTrace();
31 | } finally {
32 | if (null != br) {
33 | try {
34 | br.close();
35 | } catch (IOException e) {
36 | e.printStackTrace();
37 | }
38 | }
39 | }
40 | return sb.toString();
41 | }
42 |
43 | // 方法二
44 | public static void ReadAsChars2(HttpServletRequest request) {
45 | InputStream is = null;
46 | try {
47 | is = request.getInputStream();
48 | StringBuilder sb = new StringBuilder();
49 | byte[] b = new byte[4096];
50 | for (int n; (n = is.read(b)) != -1;) {
51 | sb.append(new String(b, 0, n));
52 | }
53 | }
54 | catch (IOException e) {
55 | e.printStackTrace();
56 | } finally {
57 | if (null != is) {
58 | try {
59 | is.close();
60 | } catch (IOException e) {
61 | e.printStackTrace();
62 | }
63 | }
64 | }
65 |
66 | }
67 |
68 | // 二进制读取
69 | public static byte[] readAsBytes(HttpServletRequest request) {
70 |
71 | int len = request.getContentLength();
72 | byte[] buffer = new byte[len];
73 | ServletInputStream in = null;
74 |
75 | try {
76 | in = request.getInputStream();
77 | in.read(buffer, 0, len);
78 | in.close();
79 | } catch (IOException e) {
80 | e.printStackTrace();
81 | } finally {
82 | if (null != in) {
83 | try {
84 | in.close();
85 | } catch (IOException e) {
86 | e.printStackTrace();
87 | }
88 | }
89 | }
90 | return buffer;
91 | }
92 |
93 | }
--------------------------------------------------------------------------------
/lzgyy-common/src/main/java/com/lzgyy/common/web/http/SpingRequestContextHolder.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.common.web.http;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletResponse;
5 | import javax.servlet.http.HttpSession;
6 |
7 | import org.springframework.web.context.request.RequestContextHolder;
8 | import org.springframework.web.context.request.ServletRequestAttributes;
9 |
10 | public class SpingRequestContextHolder extends RequestContextHolder{
11 |
12 | /**
13 | * 获取应用上下文HttpSession
14 | * @Title: getSession
15 | * @param @return 设定文件
16 | * @return HttpSession 返回类型
17 | * @throws
18 | */
19 | public static HttpSession getHttpSession(){
20 | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
21 | return request.getSession();
22 | }
23 |
24 | /**
25 | * 获取应用上下文HttpServletRequest
26 | * @Title: getHttpRequest
27 | * @param @return 设定文件
28 | * @return HttpServletRequest 返回类型
29 | * @throws
30 | */
31 | public static HttpServletRequest getHttpRequest(){
32 | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
33 | return request;
34 | }
35 |
36 | /**
37 | * 获取应用上下文HttpServletResponse
38 | * @Title: getHttpResponse
39 | * @param @return 设定文件
40 | * @return HttpServletResponse 返回类型
41 | * @throws
42 | */
43 | public static HttpServletResponse getHttpResponse(){
44 | HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
45 | return response;
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/lzgyy-core/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzgyy-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.lzgyy
7 | lzgyy
8 | 0.0.1-SNAPSHOT
9 |
10 | com.lzgyy
11 | lzgyy-core
12 | 0.0.1-SNAPSHOT
13 | lzgyy-core
14 | http://maven.apache.org
15 |
16 |
17 | com.lzgyy
18 | lzgyy-common
19 | 0.0.1-SNAPSHOT
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-jdbc
25 |
26 |
27 |
28 | org.apache.commons
29 | commons-lang3
30 |
31 |
32 |
33 | com.alibaba
34 | fastjson
35 |
36 |
37 |
38 | org.projectlombok
39 | lombok
40 | provided
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/lzgyy-core/src/main/java/com/lzgyy/core/constant/Const.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.core.constant;
2 |
3 | public final class Const {
4 |
5 | /**
6 | * 构造方法
7 | */
8 | private Const() {
9 | }
10 |
11 | /** 判断代码:是 */
12 | public static final String TRUE = "1";
13 |
14 | /** 判断代码:否 */
15 | public static final String FALSE = "0";
16 |
17 | /** 0数字 */
18 | public static final Integer ZERO = 0;
19 |
20 | /** 通用字符集编码 */
21 | public static final String CHARSET_UTF8 = "UTF-8";
22 |
23 | /** 中文字符集编码 */
24 | public static final String CHARSET_CHINESE = "GBK";
25 |
26 | /** 英文字符集编码 */
27 | public static final String CHARSET_LATIN = "ISO-8859-1";
28 |
29 | /** NULL字符串 */
30 | public static final String NULL = "null";
31 |
32 | /** 日期格式 */
33 | public static final String FORMAT_DATE = "yyyy-MM-dd";
34 |
35 | /** 日期时间格式 */
36 | public static final String FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss";
37 |
38 | /** 时间戳格式 */
39 | public static final String FORMAT_TIMESTAMP = "yyyy-MM-dd HH:mm:ss.SSS";
40 |
41 | /** 数据库默认方言 */
42 | public static final String DB_NAME = "mysql";
43 |
44 | /** 分页 */
45 | /** 开始记录页数 **/
46 | public static final String PAGE_STARTPAGE = "startPage";
47 |
48 | /** 每页限制记录数 **/
49 | public static final String PAGE_LIMITSIZE = "limitSize";
50 |
51 | /** 开始记录行数 */
52 | public static final String PAGE_STARTSIZE = "startSize";
53 |
54 | /** 记录总页数 */
55 | public static final String PAGE_TOTALPAGE = "totalPage";
56 |
57 | /** 记录总数 */
58 | public static final String PAGE_TOTAL = "total";
59 |
60 | }
--------------------------------------------------------------------------------
/lzgyy-core/src/main/java/com/lzgyy/core/dao/CrudDao.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.core.dao;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Dao支持类实现
7 | * @ClassName: CrudDao
8 | * @author yuezx
9 | * @date 2016-08-13 下午2:59:48
10 | * @param
11 | */
12 | public interface CrudDao{
13 |
14 | /**
15 | * 新增数据
16 | * @param entity
17 | * @return
18 | */
19 | public int insert(T entity);
20 |
21 | /**
22 | * 批量新增
23 | * @param entitys
24 | * @return
25 | */
26 | public int insertBatch(List entitys);
27 |
28 | /**
29 | * 更新数据
30 | * @param entity
31 | * @return
32 | */
33 | public int update(T entity);
34 |
35 | /**
36 | * 批量更新
37 | * @param entitys
38 | * @return
39 | */
40 | public int updateBatch(List entitys);
41 |
42 | /**
43 | * 恢复数据
44 | * @param idsList
45 | * @return
46 | */
47 | public int updateIdsRestore(List idsList);
48 |
49 | /**
50 | * 获取单条数据
51 | * @param id
52 | * @return
53 | */
54 | public T get(String id);
55 |
56 | /**
57 | * 获取单条数据
58 | * @param entity
59 | * @return
60 | */
61 | public T get(T entity);
62 |
63 | /**
64 | * 查询所有数据列表
65 | * @param entity
66 | * @return
67 | */
68 | public List findList(T entity);
69 |
70 |
71 | /**
72 | * 删除单条数据(逻辑删除)
73 | * @param id
74 | * @return
75 | */
76 | public int delete(String id);
77 |
78 | /**
79 | * 删除单条数据(逻辑删除)
80 | * @param entity
81 | * @return
82 | */
83 | public int delete(T entity);
84 |
85 | /**
86 | * 删除多条数据(逻辑删除)
87 | * @param idsList
88 | * @return
89 | */
90 | public int deleteIds(List idsList);
91 |
92 | /**
93 | * 物理删除多条数据
94 | * @param idsList
95 | * @return
96 | */
97 | public int deleteIdsPhysical(List idsList);
98 |
99 | }
--------------------------------------------------------------------------------
/lzgyy-core/src/main/java/com/lzgyy/core/dao/jdbc/JsonRowMapper.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.core.dao.jdbc;
2 |
3 | import java.sql.ResultSet;
4 | import java.sql.ResultSetMetaData;
5 | import java.sql.SQLException;
6 |
7 | import org.springframework.jdbc.core.RowMapper;
8 | import org.springframework.jdbc.support.JdbcUtils;
9 |
10 | import com.alibaba.fastjson.JSONException;
11 | import com.alibaba.fastjson.JSONObject;
12 |
13 | /**
14 | * 系统名称:通用系统功能
15 | * 模块名称:数据访问通用功能
16 | * 中文类名:JSON数据行映射器
17 | * 概要说明:
18 | */
19 | public class JsonRowMapper implements RowMapper {
20 |
21 | /**
22 | * 方法名称:映射行数据
23 | * 概要说明:
24 | *
25 | * @param rs 结果集
26 | * @param row 行号
27 | * @return JSONObject 数据
28 | * @throws SQLException SQL异常错误
29 | * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet,
30 | * int)
31 | */
32 | public JSONObject mapRow(ResultSet rs, int row) throws SQLException {
33 | String key = null;
34 | Object obj = null;
35 | JSONObject json = new JSONObject();
36 | ResultSetMetaData rsmd = rs.getMetaData();
37 | int count = rsmd.getColumnCount();
38 | for (int i = 1; i <= count; i++) {
39 | key = JdbcUtils.lookupColumnName(rsmd, i);
40 | obj = JdbcUtils.getResultSetValue(rs, i);
41 | try {
42 | json.put(key, obj);
43 | }
44 | catch (JSONException e) {
45 | e.printStackTrace();
46 | }
47 | }
48 | return json;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/lzgyy-core/src/main/java/com/lzgyy/core/entity/PageQuery.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.core.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.EqualsAndHashCode;
6 | import lombok.ToString;
7 |
8 | /**
9 | * 分页查询工具类
10 | * @param
11 | */
12 | @ToString
13 | @EqualsAndHashCode
14 | public class PageQuery implements Serializable{
15 |
16 | private static final long serialVersionUID = 1L;
17 |
18 | public PageQuery(){}
19 |
20 | public PageQuery(T queryParamObj){
21 | if (queryParamObj != null){
22 | this.setQueryParamObj(queryParamObj);
23 | }
24 | }
25 |
26 | /**
27 | * 构造器
28 | * @param queryParamObj 对象
29 | * @param paramInt int数组,0位置对应currPage当前页,1位置对应pageSize每页显示条数,默认0.10
30 | */
31 | public PageQuery(T queryParamObj, int... paramInt){
32 | if (queryParamObj != null){
33 | this.setQueryParamObj(queryParamObj);
34 | }
35 |
36 | if (paramInt != null){
37 | if (paramInt[0] < 0){
38 | paramInt[0] = 0;
39 | }
40 | this.startPage = paramInt[0];
41 | if(paramInt.length == 2){
42 | if (paramInt[1] < 0){
43 | paramInt[1] = 0;
44 | }
45 | this.limitSize = paramInt[1];
46 | }
47 | }
48 | }
49 |
50 | /** 开始记录页数 **/
51 | public int startPage = 0;
52 |
53 | /** 每页限制记录数 **/
54 | private int limitSize = 10;
55 |
56 | /** 查询条件对象 **/
57 | private T queryParamObj;
58 |
59 | public int getStartPage() {
60 | return startPage;
61 | }
62 |
63 | public void setStartPage(int startPage) {
64 | this.startPage = startPage;
65 | }
66 |
67 | public int getLimitSize() {
68 | return limitSize;
69 | }
70 |
71 | public void setLimitSize(int limitSize) {
72 | this.limitSize = limitSize;
73 | }
74 |
75 | public void setQueryParamObj(T queryParamObj) {
76 | this.queryParamObj = queryParamObj;
77 | }
78 |
79 | public T getQueryParamObj() {
80 | return queryParamObj;
81 | }
82 |
83 | }
--------------------------------------------------------------------------------
/lzgyy-core/src/main/java/com/lzgyy/core/entity/PageQueryHelp.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.core.entity;
2 |
3 | import java.util.Map;
4 | import com.alibaba.fastjson.JSONObject;
5 | import com.lzgyy.common.lang.ObjectToMapUtils;
6 | import com.lzgyy.core.constant.Const;
7 |
8 | /**
9 | * 分页查询帮助工具类
10 | * @param
11 | */
12 | public class PageQueryHelp{
13 |
14 | public static Map getParamMap(PageQuery> pageQuery) {
15 |
16 | if (pageQuery == null){
17 | return null;
18 | }
19 |
20 | Map paramMap = null;
21 | try {
22 | paramMap = ObjectToMapUtils.objectToIgnorNullMergeMap(pageQuery.getQueryParamObj());
23 | if (paramMap != null){
24 | // 开始记录行数
25 | paramMap.put(Const.PAGE_STARTSIZE, (pageQuery.getStartPage()== 0?0:pageQuery.getStartPage()-1)*pageQuery.getLimitSize());
26 | // 每页限制记录数
27 | paramMap.put(Const.PAGE_LIMITSIZE, pageQuery.getLimitSize());
28 | }
29 | } catch (IllegalAccessException e) {
30 | e.printStackTrace();
31 | }
32 | return paramMap;
33 | }
34 |
35 | public static Integer[] getArrStartLimitSize(JSONObject json) {
36 |
37 | Integer[] intArr = new Integer[]{0,10};
38 |
39 | if (json != null){
40 | if (json.get(Const.PAGE_STARTPAGE) != null && json.get(Const.PAGE_STARTPAGE) instanceof Integer &&
41 | json.get(Const.PAGE_LIMITSIZE) != null && json.get(Const.PAGE_LIMITSIZE) instanceof Integer){
42 |
43 | intArr[0] = (json.getInteger(Const.PAGE_STARTPAGE)==0?0:json.getInteger(Const.PAGE_STARTPAGE)-1)*json.getInteger(Const.PAGE_LIMITSIZE);
44 | intArr[1] = json.getInteger(Const.PAGE_LIMITSIZE);
45 | }
46 |
47 | json.remove(Const.PAGE_STARTPAGE);
48 | json.remove(Const.PAGE_LIMITSIZE);
49 | }
50 | return intArr;
51 | }
52 |
53 | public static Integer getStartSize(Integer startPage, Integer limitSize){
54 | if (startPage != null && limitSize != null){
55 | return startPage == 0 ? startPage : (startPage -1) * limitSize;
56 | }
57 | return 0;
58 | }
59 | }
--------------------------------------------------------------------------------
/lzgyy-core/src/main/java/com/lzgyy/core/entity/PageResult.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.core.entity;
2 |
3 | import lombok.EqualsAndHashCode;
4 | import lombok.ToString;
5 |
6 | /**
7 | * 分页结果工具类
8 | * @param
9 | */
10 | @ToString
11 | @EqualsAndHashCode
12 | public class PageResult {
13 |
14 | public PageResult(){}
15 |
16 | public PageResult(T data){
17 |
18 | if (data != null){
19 | this.setData(data);;
20 | }
21 | }
22 |
23 | /** 开始记录页数 **/
24 | public int startPage;
25 |
26 | /** 每页限制记录数 **/
27 | public int limitSize;
28 |
29 | /** 记录总页数 */
30 | public int totalPage;
31 |
32 | /** 记录总数 */
33 | public int total;
34 |
35 | /** 返回数据 */
36 | public T data;
37 |
38 | public int getStartPage() {
39 | return startPage;
40 | }
41 |
42 | public void setStartPage(int startPage) {
43 | this.startPage = startPage;
44 | }
45 |
46 | public int getLimitSize() {
47 | return limitSize;
48 | }
49 |
50 | public void setLimitSize(int limitSize) {
51 | this.limitSize = limitSize;
52 | }
53 |
54 | public int getTotalPage() {
55 |
56 | if (this.limitSize == 0 || this.total == 0){
57 | return 0;
58 | }
59 | if (this.total % limitSize == 0){
60 | this.totalPage = this.total / this.limitSize;
61 | } else {
62 | this.totalPage = this.total / this.limitSize + 1;
63 | }
64 | return this.totalPage;
65 | }
66 |
67 | public void setTotalPage(int totalPage) {
68 | this.totalPage = totalPage;
69 | }
70 |
71 | public int getTotal() {
72 | return total;
73 | }
74 |
75 | public void setTotal(int total) {
76 | this.total = total;
77 | }
78 |
79 | public T getData() {
80 | return data;
81 | }
82 |
83 | public void setData(T data) {
84 | this.data = data;
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/lzgyy-core/src/main/java/com/lzgyy/core/utils/PropertiesUtil.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.core.utils;
2 |
3 | import com.lzgyy.core.io.PropertiesConfig;
4 |
5 | /**
6 | * 配置工具类
7 | */
8 | public class PropertiesUtil {
9 |
10 | /**
11 | * 公共配置文件
12 | */
13 | private static PropertiesConfig propertiesLoader = null;
14 |
15 | // 此地方后续改动
16 | public static void setPropertiesConfig (PropertiesConfig propertiesLoader) {
17 | PropertiesUtil.propertiesLoader = propertiesLoader;
18 | }
19 |
20 | public static String getProperty(String key) {
21 | return propertiesLoader.getProperty(key);
22 | }
23 |
24 | public static Integer getInteger(String key) {
25 | return Integer.valueOf(propertiesLoader.getProperty(key));
26 | }
27 |
28 | public static long getLong(String key) {
29 | return Long.valueOf(propertiesLoader.getProperty(key));
30 | }
31 | }
--------------------------------------------------------------------------------
/lzgyy-manage/lzggy-dubbo-admin-war/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/lzgyy-manage/lzggy-dubbo-admin-war/dubbo-admin-2.6.0.war:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-manage/lzggy-dubbo-admin-war/dubbo-admin-2.6.0.war
--------------------------------------------------------------------------------
/lzgyy-manage/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.lzgyy
5 | lzgyy
6 | 0.0.1-SNAPSHOT
7 |
8 | lzgyy-manage
9 | pom
10 |
11 | lzgyy-dubbo-admin-war
12 |
13 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-elasticsearch-plugin/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-elasticsearch-plugin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.lzgyy
5 | lzgyy-plugins
6 | 0.0.1-SNAPSHOT
7 |
8 | lzgyy-elasticsearch-plugin
9 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.lzgyy
5 | lzgyy-plugins
6 | 0.0.1-SNAPSHOT
7 |
8 | lzgyy-iot-client
9 |
10 |
11 | org.springframework.boot
12 | spring-boot-starter-web
13 |
14 |
15 |
16 | io.netty
17 | netty-handler
18 |
19 |
20 | io.netty
21 | netty-codec-mqtt
22 |
23 |
24 | io.netty
25 | netty-codec-http
26 |
27 |
28 |
29 | org.projectlombok
30 | lombok
31 | provided
32 |
33 |
34 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/ClientApplication.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client;
2 |
3 | import org.springframework.boot.autoconfigure.SpringBootApplication;
4 |
5 | import static org.springframework.boot.SpringApplication.run;
6 |
7 | @SpringBootApplication(scanBasePackages = {"com.lzgyy.plugins.iot"})
8 | public class ClientApplication {
9 |
10 | public static void main( String[] args ){
11 | run(ClientApplication.class, args);
12 | }
13 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/SubListener.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client;
2 |
3 | import io.netty.handler.codec.mqtt.MqttQoS;
4 | import lombok.extern.slf4j.Slf4j;
5 |
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.stereotype.Service;
9 |
10 | import com.lzgyy.plugins.iot.client.mqtt.auto.MqttListener;
11 | import com.lzgyy.plugins.iot.client.mqtt.auto.MqttMessageListener;
12 |
13 | @Slf4j
14 | @Service
15 | @MqttMessageListener(qos = MqttQoS.AT_LEAST_ONCE, topic = "/t1/t2")
16 | public class SubListener implements MqttListener {
17 |
18 | private static final Logger LOGGER = LoggerFactory.getLogger(SubListener.class);
19 |
20 | @Override
21 | public void callBack(String topic, String msg) {
22 | LOGGER.debug("============================="+topic+msg);
23 | }
24 |
25 | @Override
26 | public void callThrowable(Throwable e) {
27 | LOGGER.debug("exception",e);
28 | }
29 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/auto/MqttListener.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.auto;
2 |
3 | /**
4 | * call scan
5 | * mqtt监听,返回
6 | **/
7 | public interface MqttListener{
8 |
9 | /**
10 | * 返回
11 | * @param topic 主题
12 | * @param msg 消息
13 | */
14 | void callBack(String topic,String msg);
15 |
16 | /**
17 | * 返回错误
18 | * @param e
19 | */
20 | void callThrowable(Throwable e);
21 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/auto/MqttMessageListener.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.auto;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | import io.netty.handler.codec.mqtt.MqttQoS;
10 |
11 | /**
12 | * 消费者配置注解类
13 | */
14 | @Target(ElementType.TYPE)
15 | @Retention(RetentionPolicy.RUNTIME)
16 | @Documented
17 | public @interface MqttMessageListener {
18 |
19 | String topic() ;
20 |
21 | MqttQoS qos() default MqttQoS.AT_MOST_ONCE;
22 |
23 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/bootstrap/BootstrapClient.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.bootstrap;
2 |
3 | import io.netty.channel.Channel;
4 |
5 | /**
6 | * 启动类接口
7 | **/
8 | public interface BootstrapClient {
9 |
10 | // 关闭
11 | void shutdown();
12 |
13 | // 初始化事件
14 | void initEventPool();
15 |
16 | // 开始
17 | Channel start();
18 |
19 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/bootstrap/Producer.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.bootstrap;
2 |
3 | import io.netty.channel.Channel;
4 | import java.util.List;
5 |
6 | import com.lzgyy.plugins.iot.client.mqtt.auto.MqttListener;
7 | import com.lzgyy.plugins.iot.client.mqtt.bootstrap.bean.SubMessage;
8 | import com.lzgyy.plugins.iot.client.mqtt.config.ConnectOptions;
9 |
10 | /**
11 | * 生产者接口定义
12 | * 发布/订阅消息接口
13 | **/
14 | public interface Producer {
15 |
16 | Channel getChannel();
17 |
18 | Producer connect(ConnectOptions connectOptions);
19 |
20 | void close();
21 |
22 | void setMqttListener(MqttListener mqttListener);
23 |
24 | void pub(String topic,String message,boolean retained,int qos);
25 |
26 | void pub(String topic,String message);
27 |
28 | void pub(String topic,String message,int qos);
29 |
30 | void pub(String topic,String message,boolean retained);
31 |
32 | void sub(SubMessage... subMessages);
33 |
34 | void unsub(List topics);
35 |
36 | void unsub();
37 |
38 | void disConnect();
39 |
40 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/bootstrap/bean/SendMqttMessage.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.bootstrap.bean;
2 |
3 | import com.lzgyy.plugins.iot.client.mqtt.enums.ConfirmStatus;
4 |
5 | import lombok.Builder;
6 | import lombok.Data;
7 |
8 | /**
9 | * 发送MQTT消息对象
10 | **/
11 | @Data
12 | @Builder
13 | public class SendMqttMessage {
14 |
15 | // 主题
16 | private String Topic;
17 |
18 | // 息体(Payload),存在于部分MQTT数据包中,表示客户端收到的具体内容
19 | private byte[] payload;
20 |
21 | /**
22 | * qos 服务质量等级 主要用于PUBLISH(发布态)消息的,保证消息传递的次数
23 | * 00表示最多一次 即<=1 发送者只发送一次消息,不进行重试,Broker不会返回确认消息
24 | 01表示至少一次 即>=1
25 | 10表示一次,即==1
26 | 11保留后用
27 | */
28 | private int qos;
29 |
30 | /**
31 | * 主要用于PUBLISH(发布态)的消息,表示服务器要保留这次推送的信息,
32 | * 如果有新的订阅者出现,就把这消息推送给它。如果不设那么推送至当前订阅的就释放了。
33 | */
34 | private boolean retained;
35 |
36 | /**
37 | * 其是用来在保证消息传输可靠的,如果设置为1,则在下面的变长头部里多加MessageId,并需要回复确认,
38 | * 保证消息传输完成,但不能用于检测消息重复发送
39 | */
40 | private boolean dup;
41 |
42 | private int messageId;
43 |
44 | private long timestamp;
45 |
46 | private volatile ConfirmStatus confirmStatus;
47 |
48 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/bootstrap/bean/SubMessage.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.bootstrap.bean;
2 |
3 | import io.netty.handler.codec.mqtt.MqttQoS;
4 | import lombok.Builder;
5 | import lombok.Data;
6 |
7 | /**
8 | * 订阅消息
9 | **/
10 | @Builder
11 | @Data
12 | public class SubMessage {
13 |
14 | // 标题
15 | private String topic;
16 |
17 | /**服务质量等级 主要用于PUBLISH(发布态)消息的,保证消息传递的次数
18 | * 00表示最多一次 即<=1 发送者只发送一次消息,不进行重试,Broker不会返回确认消息
19 | 01表示至少一次 即>=1
20 | 10表示一次,即==1
21 | 11保留后用
22 | */
23 | private MqttQoS qos;
24 |
25 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/bootstrap/cache/Cache.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.bootstrap.cache;
2 |
3 | import java.util.concurrent.ConcurrentHashMap;
4 |
5 | import com.lzgyy.plugins.iot.client.mqtt.bootstrap.bean.SendMqttMessage;
6 |
7 | /**
8 | * 缓存
9 | **/
10 | public class Cache {
11 |
12 | private static ConcurrentHashMap message = new ConcurrentHashMap<>();
13 |
14 |
15 | public static boolean put(Integer messageId,SendMqttMessage mqttMessage){
16 |
17 | return message.put(messageId,mqttMessage)==null;
18 |
19 | }
20 |
21 | public static SendMqttMessage get(Integer messageId){
22 |
23 | return message.get(messageId);
24 |
25 | }
26 |
27 | public static SendMqttMessage del(Integer messageId){
28 | return message.remove(messageId);
29 | }
30 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/bootstrap/handler/ClientMqttHandlerService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.bootstrap.handler;
2 |
3 | import io.netty.channel.Channel;
4 | import io.netty.handler.codec.mqtt.MqttMessage;
5 | import io.netty.handler.codec.mqtt.MqttSubAckMessage;
6 | import io.netty.handler.timeout.IdleStateEvent;
7 |
8 | /**
9 | * 抽象出服务端事件
10 | **/
11 | public abstract class ClientMqttHandlerService implements MqttHandlerIntf {
12 |
13 | @Override
14 | public void doTimeOut(Channel channel, IdleStateEvent evt) {
15 | heart(channel,evt);
16 | }
17 |
18 | public abstract void heart(Channel channel, IdleStateEvent evt);
19 |
20 | public abstract void suback(Channel channel,MqttSubAckMessage mqttMessage) ;
21 |
22 | public abstract void pubBackMessage(Channel channel, int i);
23 |
24 | public abstract void unsubBack(Channel channel, MqttMessage mqttMessage);
25 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/bootstrap/handler/MqttHandlerIntf.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.bootstrap.handler;
2 |
3 | import io.netty.channel.Channel;
4 | import io.netty.handler.codec.mqtt.*;
5 | import io.netty.handler.timeout.IdleStateEvent;
6 |
7 | /**
8 | * 自定义 对外暴露 消息处理api
9 | **/
10 | public interface MqttHandlerIntf {
11 |
12 | // 关闭
13 | void close(Channel channel);
14 | // 发送应答
15 | void puback(Channel channel, MqttMessage mqttMessage);
16 |
17 | void pubrec(Channel channel, MqttMessage mqttMessage);
18 |
19 | void pubrel(Channel channel, MqttMessage mqttMessage);
20 |
21 | void pubcomp(Channel channel, MqttMessage mqttMessage);
22 | // 超时
23 | void doTimeOut(Channel channel, IdleStateEvent evt);
24 |
25 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/bootstrap/handler/ServerMqttHandlerService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.bootstrap.handler;
2 |
3 | import io.netty.channel.Channel;
4 | import io.netty.handler.codec.mqtt.*;
5 | import io.netty.handler.timeout.IdleStateEvent;
6 |
7 | /**
8 | * 抽象出服务端事件
9 | **/
10 | public abstract class ServerMqttHandlerService implements MqttHandlerIntf {
11 |
12 | public abstract boolean login(Channel channel, MqttConnectMessage mqttConnectMessage);
13 |
14 | public abstract void publish(Channel channel, MqttPublishMessage mqttPublishMessage);
15 |
16 | public abstract void subscribe(Channel channel, MqttSubscribeMessage mqttSubscribeMessage);
17 |
18 | public abstract void pong(Channel channel);
19 |
20 | public abstract void unsubscribe(Channel channel, MqttUnsubscribeMessage mqttMessage);
21 |
22 | public abstract void disconnect(Channel channel);
23 |
24 | public abstract void doTimeOut(Channel channel, IdleStateEvent evt);
25 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/bootstrap/scan/ScanRunnable.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.bootstrap.scan;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 |
5 | import java.util.LinkedList;
6 | import java.util.List;
7 | import java.util.concurrent.ConcurrentLinkedQueue;
8 |
9 | import com.lzgyy.plugins.iot.client.mqtt.bootstrap.MqttApi;
10 | import com.lzgyy.plugins.iot.client.mqtt.bootstrap.bean.SendMqttMessage;
11 | import com.lzgyy.plugins.iot.client.mqtt.enums.ConfirmStatus;
12 |
13 | /**
14 | * 扫描未确认信息
15 | **/
16 | @Slf4j
17 | public abstract class ScanRunnable extends MqttApi implements Runnable {
18 |
19 | private ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue<>();
20 |
21 | public boolean addQueue(SendMqttMessage t){
22 | return queue.add(t);
23 | }
24 |
25 | public boolean addQueues(List ts){
26 | return queue.addAll(ts);
27 | }
28 |
29 | @Override
30 | public void run() {
31 | if(!queue.isEmpty()) {
32 | SendMqttMessage poll;
33 | List list = new LinkedList<>();
34 | for (; (poll = queue.poll()) != null; ) {
35 | if (poll.getConfirmStatus() != ConfirmStatus.COMPLETE) {
36 | list.add(poll);
37 | doInfo(poll);
38 | }
39 | break;
40 | }
41 | addQueues(list);
42 | }
43 | }
44 |
45 | public abstract void doInfo( SendMqttMessage poll);
46 |
47 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/enums/ConfirmStatus.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.enums;
2 |
3 | /**
4 | * 确认状态
5 | **/
6 | public enum ConfirmStatus {
7 | PUB,
8 | PUBREC,
9 | PUBREL,
10 | COMPLETE,
11 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/enums/ProtocolEnum.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.enums;
2 |
3 | /**
4 | * 协议枚举
5 | **/
6 | public enum ProtocolEnum {
7 | MQTT,
8 | MQTT_WS_MQTT,
9 | MQTT_WS_PAHO,
10 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/enums/QosStatus.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.enums;
2 |
3 | /**
4 | * Qos确认状态
5 | **/
6 | public enum QosStatus {
7 | PUBD, // 已发送 没收到RECD (发送)
8 | RECD, //publish 推送回复过(发送)
9 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/enums/SessionStatus.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.enums;
2 |
3 | /**
4 | * Channel 会话状态
5 | **/
6 | public enum SessionStatus {
7 | OPEN,
8 | CLOSE
9 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/enums/SubStatus.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.enums;
2 |
3 | /**
4 | * 是否订阅过主题
5 | **/
6 | public enum SubStatus {
7 | YES,
8 | NO
9 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/ip/IpUtils.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.ip;
2 |
3 | import java.net.Inet4Address;
4 | import java.net.InetAddress;
5 | import java.net.NetworkInterface;
6 | import java.util.Enumeration;
7 |
8 | /**
9 | * ip操作
10 | **/
11 | public class IpUtils {
12 |
13 | /***
14 | * 获取外网IP
15 | * @return
16 | */
17 | public static String internetIp() {
18 | try {
19 |
20 | Enumeration networks = NetworkInterface.getNetworkInterfaces();
21 | InetAddress inetAddress = null;
22 | Enumeration inetAddresses = null;
23 | while (networks.hasMoreElements()) {
24 | inetAddresses = networks.nextElement().getInetAddresses();
25 | while (inetAddresses.hasMoreElements()) {
26 | inetAddress = inetAddresses.nextElement();
27 | if (inetAddress != null
28 | && inetAddress instanceof Inet4Address
29 | && !inetAddress.isSiteLocalAddress()
30 | && !inetAddress.isLoopbackAddress()
31 | && inetAddress.getHostAddress().indexOf(":") == -1) {
32 | return inetAddress.getHostAddress();
33 | }
34 | }
35 | }
36 |
37 | return null;
38 |
39 | } catch (Exception e) {
40 |
41 | throw new RuntimeException(e);
42 | }
43 | }
44 |
45 | /**
46 | * 获取内网IP
47 | *
48 | * @return
49 | */
50 | public static String intranetIp() {
51 | try {
52 | return InetAddress.getLocalHost().getHostAddress();
53 | } catch (Exception e) {
54 | throw new RuntimeException(e);
55 | }
56 | }
57 |
58 | /**
59 | * 获取服务启动host
60 | * @return
61 | */
62 | public static String getHost(){
63 | return internetIp()==null?intranetIp():internetIp();
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/pool/DefaultThreadFactory.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.pool;
2 |
3 | import java.util.concurrent.ThreadFactory;
4 | import java.util.concurrent.atomic.AtomicInteger;
5 |
6 | /**
7 | * 线程池
8 | **/
9 | public class DefaultThreadFactory implements ThreadFactory {
10 |
11 | private static final AtomicInteger poolNumber = new AtomicInteger(1);
12 | private final ThreadGroup threadGroup;
13 | private final AtomicInteger currentThreadNumber = new AtomicInteger(1);
14 | private final String namePrefix;
15 | private int priority = Thread.NORM_PRIORITY;
16 | private boolean isDaemon = false;
17 |
18 | public DefaultThreadFactory(String prefix) {
19 | this(prefix, false);
20 | }
21 |
22 | public DefaultThreadFactory(String prefix, boolean isDaemon) {
23 | this(prefix, isDaemon, Thread.NORM_PRIORITY);
24 | }
25 |
26 | public DefaultThreadFactory(String prefix, boolean isDaemon, int priority) {
27 | SecurityManager s = System.getSecurityManager();
28 | this.threadGroup = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
29 | this.namePrefix = prefix + "-" + poolNumber.getAndIncrement() + "-thread-";
30 | this.isDaemon = isDaemon;
31 | this.priority = priority;
32 | }
33 |
34 | @Override
35 | public Thread newThread(Runnable r) {
36 | Thread thread = new Thread(threadGroup, r, namePrefix + currentThreadNumber.getAndIncrement(), 0);
37 | thread.setDaemon(isDaemon);
38 | thread.setPriority(priority);
39 | return thread;
40 | }
41 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/pool/ExecutorQueue.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.pool;
2 |
3 | import java.util.concurrent.LinkedTransferQueue;
4 | import java.util.concurrent.RejectedExecutionException;
5 |
6 | /**
7 | * LinkedTransferQueue 能保证更高性能,相比与LinkedBlockingQueue有明显提升
8 | * 不过LinkedTransferQueue的缺点是没有队列长度控制,需要在外层协助控制
9 | */
10 | public class ExecutorQueue extends LinkedTransferQueue {
11 | private static final long serialVersionUID = -265236426751004839L;
12 | private StandardThreadExecutor threadPoolExecutor;
13 |
14 | public ExecutorQueue() {
15 | super();
16 | }
17 |
18 | public void setStandardThreadExecutor(StandardThreadExecutor threadPoolExecutor) {
19 | this.threadPoolExecutor = threadPoolExecutor;
20 | }
21 |
22 | // 注:代码来源于 tomcat
23 | public boolean force(Runnable o) {
24 | if (threadPoolExecutor.isShutdown()) {
25 | throw new RejectedExecutionException("Executor not running, can't force a command into the queue");
26 | }
27 | // forces the item onto the queue, to be used if the task is rejected
28 | return super.offer(o);
29 | }
30 |
31 | // 注:tomcat的代码进行一些小变更
32 | public boolean offer(Runnable o) {
33 | int poolSize = threadPoolExecutor.getPoolSize();
34 |
35 | // we are maxed out on threads, simply queue the object
36 | if (poolSize == threadPoolExecutor.getMaximumPoolSize()) {
37 | return super.offer(o);
38 | }
39 | // we have idle threads, just add it to the queue
40 | // note that we don't use getActiveCount(), see BZ 49730
41 | if (poolSize >= threadPoolExecutor.getSubmittedTasksCount()) {
42 | return super.offer(o);
43 | }
44 | // if we have less threads than maximum force creation of a new
45 | // thread
46 | if (poolSize < threadPoolExecutor.getMaximumPoolSize()) {
47 | return false;
48 | }
49 | // if we reached here, we need to add it to the queue
50 | return super.offer(o);
51 | }
52 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/pool/Scheduled.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.pool;
2 |
3 | import java.util.concurrent.ScheduledFuture;
4 |
5 | /**
6 | * 接口
7 | **/
8 | @FunctionalInterface
9 | public interface Scheduled {
10 |
11 | /**
12 | * ScheduledFuture只是在Future基础上还集成了Comparable和Delayed的接口。使其具有延迟、排序、获得异步计算结果的特性。
13 | 它用于表示ScheduledExecutorService中提交了任务的返回结果。我们通过Delayed的接口getDelay()方法知道该任务还有多久才会被执行。
14 | JDK中并没提供ScheduledFuture的实现类。只有在ScheduledExecutorService中提交了任务,才能返回一个实现了ScheduledFuture接口的对象。
15 | * @param runnable
16 | * @return
17 | */
18 | ScheduledFuture> submit(Runnable runnable);
19 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/ssl/SecureSokcetTrustManagerFactory.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.ssl;
2 |
3 | import javax.net.ssl.ManagerFactoryParameters;
4 | import javax.net.ssl.TrustManager;
5 | import javax.net.ssl.TrustManagerFactorySpi;
6 | import javax.net.ssl.X509TrustManager;
7 | import java.security.InvalidAlgorithmParameterException;
8 | import java.security.KeyStore;
9 | import java.security.KeyStoreException;
10 | import java.security.cert.X509Certificate;
11 |
12 | /**
13 | * Bogus {@link TrustManagerFactorySpi} which accepts any certificate
14 | * even if it is invalid.
15 | */
16 | public class SecureSokcetTrustManagerFactory extends TrustManagerFactorySpi {
17 |
18 | private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() {
19 | @Override
20 | public X509Certificate[] getAcceptedIssuers() {
21 | return new X509Certificate[0];
22 | }
23 |
24 | @Override
25 | public void checkClientTrusted(X509Certificate[] chain, String authType) {
26 | // Always trust - it is an example.
27 | // You should do something in the real world.
28 | // You will reach here only if you enabled client certificate auth,
29 | // as described in SecureChatSslContextFactory.
30 | System.err.println(
31 | "UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN());
32 | }
33 |
34 | @Override
35 | public void checkServerTrusted(X509Certificate[] chain, String authType) {
36 | // Always trust - it is an example.
37 | // You should do something in the real world.
38 | System.err.println(
39 | "UNKNOWN SERVER CERTIFICATE: " + chain[0].getSubjectDN());
40 | }
41 | };
42 |
43 | public static TrustManager[] getTrustManagers() {
44 | return new TrustManager[] { DUMMY_TRUST_MANAGER };
45 | }
46 |
47 | @Override
48 | protected TrustManager[] engineGetTrustManagers() {
49 | return getTrustManagers();
50 | }
51 |
52 | @Override
53 | protected void engineInit(KeyStore keystore) throws KeyStoreException {
54 | // Unused
55 | }
56 |
57 | @Override
58 | protected void engineInit(ManagerFactoryParameters managerFactoryParameters)
59 | throws InvalidAlgorithmParameterException {
60 | // Unused
61 | }
62 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/ssl/StreamReader.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.ssl;
2 |
3 | import java.io.InputStream;
4 |
5 | public class StreamReader {
6 |
7 |
8 | public String toByteArray(InputStream fin)
9 | {
10 | int i = -1;
11 | StringBuilder buf = new StringBuilder();
12 | try{
13 | while((i=fin.read())!=-1){
14 | if(buf.length()>0) buf.append(",");
15 | buf.append("(byte)");
16 | buf.append(i);
17 | }
18 |
19 | }catch(Throwable e){
20 | ;
21 | }
22 |
23 | return buf.toString();
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/ssl/X509CertTool.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.ssl;
2 |
3 | import sun.security.x509.*;
4 |
5 | import java.io.IOException;
6 | import java.math.BigInteger;
7 | import java.security.GeneralSecurityException;
8 | import java.security.KeyPair;
9 | import java.security.PrivateKey;
10 | import java.security.SecureRandom;
11 | import java.security.cert.X509Certificate;
12 | import java.util.Date;
13 |
14 |
15 | /*
16 | * This class would require rt.jar in the class path in order to
17 | * generated it alternative is using keytool.
18 | */
19 | public class X509CertTool {
20 |
21 | /**
22 | * Create a self-signed X.509 Certificate
23 | * @param dn the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"
24 | * @param pair the KeyPair
25 | * @param days how many days from now the Certificate is valid for
26 | * @param algorithm the signing algorithm, eg "SHA1withRSA"
27 | */
28 | @SuppressWarnings("restriction")
29 | X509Certificate generateCertificate(String dn, KeyPair pair, int days,
30 | String algorithm) throws GeneralSecurityException, IOException {
31 | PrivateKey privkey = pair.getPrivate();
32 | X509CertInfo info = new X509CertInfo();
33 | Date from = new Date();
34 | Date to = new Date(from.getTime() + days * 86400000l);
35 | CertificateValidity interval = new CertificateValidity(from, to);
36 | BigInteger sn = new BigInteger(64, new SecureRandom());
37 | X500Name owner = new X500Name(dn);
38 |
39 | info.set(X509CertInfo.VALIDITY, interval);
40 | info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(sn));
41 | info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner));
42 | info.set(X509CertInfo.ISSUER, new CertificateIssuerName(owner));
43 | info.set(X509CertInfo.KEY, new CertificateX509Key(pair.getPublic()));
44 | info.set(X509CertInfo.VERSION, new CertificateVersion(
45 | CertificateVersion.V3));
46 | AlgorithmId algo = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid);
47 | info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algo));
48 |
49 | // Sign the cert to identify the algorithm that's used.
50 | X509CertImpl cert = new X509CertImpl(info);
51 | cert.sign(privkey, algorithm);
52 |
53 | // Update the algorith, and resign.
54 | algo = (AlgorithmId) cert.get(X509CertImpl.SIG_ALG);
55 | info.set(CertificateAlgorithmId.NAME + "."
56 | + CertificateAlgorithmId.ALGORITHM, algo);
57 | cert = new X509CertImpl(info);
58 | cert.sign(privkey, algorithm);
59 | return cert;
60 | }
61 |
62 | public static void main(String[] args) {
63 |
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/util/ByteBufUtil.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.util;
2 |
3 | import io.netty.buffer.ByteBuf;
4 |
5 | /**
6 | * 跨线程情况下 byteBuf 需要转换成byte[]
7 | **/
8 | public class ByteBufUtil {
9 |
10 | public static byte[] copyByteBuf(ByteBuf byteBuf){
11 | byte[] bytes = new byte[byteBuf.readableBytes()];
12 | byteBuf.readBytes(bytes);
13 | return bytes;
14 | }
15 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/util/MessageId.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.util;
2 |
3 | import java.util.concurrent.atomic.AtomicInteger;
4 |
5 | /**
6 | * 生成messgaeId
7 | **/
8 | public class MessageId {
9 |
10 | private static AtomicInteger index = new AtomicInteger(1);
11 |
12 | /**
13 | * 获取messageId
14 | * @return id
15 | */
16 | public static int messageId(){
17 | for (;;) {
18 | int current = index.get();
19 | int next = (current >= Integer.MAX_VALUE ? 0: current + 1);
20 | if (index.compareAndSet(current, next)) {
21 | return current;
22 | }
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/java/com/lzgyy/plugins/iot/client/mqtt/util/SpringBeanUtils.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.client.mqtt.util;
2 |
3 | import org.springframework.beans.BeansException;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.ApplicationContextAware;
6 | import org.springframework.stereotype.Component;
7 |
8 | /**
9 | * 获取 spring当前bean
10 | **/
11 | @Component
12 | public class SpringBeanUtils implements ApplicationContextAware {
13 |
14 | private static ApplicationContext applicationContext;
15 |
16 | @Override
17 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
18 | if(SpringBeanUtils.applicationContext == null) {
19 | SpringBeanUtils.applicationContext = applicationContext;
20 | }
21 | }
22 |
23 | //获取applicationContext
24 | public static ApplicationContext getApplicationContext() {
25 | return applicationContext;
26 | }
27 |
28 | //通过name获取 Bean.
29 | public static Object getBean(String name){
30 | return getApplicationContext().getBean(name);
31 | }
32 |
33 | //通过class获取Bean.
34 | public static T getBean(Class clazz){
35 | return getApplicationContext().getBean(clazz);
36 | }
37 |
38 | //通过name,以及Clazz返回指定的Bean
39 | public static T getBean(String name,Class clazz){
40 | return getApplicationContext().getBean(name, clazz);
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 |
2 | lzgyy:
3 | iot:
4 | client:
5 | # 其它配置
6 | connect-time: 10 # 线程连接超时,单位秒
7 | min-period: 10 # 定时任务最小超时时间,单位秒
8 | # netty客户端配置
9 | server-ip: 127.0.0.1 # [netty] 服务器IP
10 | server-port: 8883 # [netty] 服务器端口号
11 | client-port: 8980 # [netty] 客户端端口号
12 | is-so-keepalive: true # [netty] 是否保持连接检测对方主机是否崩溃
13 | is-so-reuseaddr: true # [netty] 地址复用,默认值False。有四种情况可以使用:(1).当有一个有相同本地地址和端口的socket1处于TIME_WAIT状态时,而你希望启动的程序的socket2要占用该地址和端口,比如重启服务且保持先前端口。(2).有多块网卡或用IP Alias技术的机器在同一端口启动多个进程,但每个进程绑定的本地IP地址不能相同。(3).单个进程绑定相同的端口到多个socket上,但每个socket绑定的ip地址不同。(4).完全相同的地址和端口的重复绑定。但这只用于UDP的多播,不用于TCP。
14 | is-tcp-nodelay: true # [netty] TCP参数,立即发送数据,默认值为Ture(Netty默认为True而操作系统默认为False)。该值设置Nagle算法的启用,改算法将小的碎片数据连接成更大的报文来最小化所发送的报文的数量,如果需要发送一些较小的报文,则需要禁用该算法。Netty默认禁用该算法,从而最小化报文传输延时。
15 | so-sndbuf: 10485760 # [netty] Socket参数,TCP数据发送缓冲区大小。
16 | so-revbuf: 10485760 # [netty] Socket参数,TCP数据接收缓冲区大小。
17 | connect-time-out-millis: 30000 # [netty] 连接超时毫秒数,默认值30000毫秒即30秒。
18 | writer-idle-time-seconds: 60 # [netty] IdleStateHandler心跳检测器,写超时时间,单位秒
19 | # ssl配置
20 | is-ssl: true # [ssl]使用ssl加密
21 | jks-file: keystore/client.jks # [ssl] 加密 jks文件地址
22 | jks-store-pass: 112233445566 # [ssl] 加密jks目标源存储库口令,storepass指定密钥库的密码
23 | jks-key-pass: 1122334455668 # [ssl] 加密jks目标密钥库口令
24 | # mqtt配置
25 | mqtt:
26 | is-will-flag: false # [mqtt] 是否连接标识
27 | client-identifier: lzgyy-iot-client-01 # [mqtt] 客户端标识符
28 | will-topic: /t1/t2 # [mqtt] 连接主题(isWillFlag为true时配置)
29 | will-message: # [mqtt] 连接消息(isWillFlag为true时配置)
30 | is-has-user-name: true # [mqtt] 是否有用户名
31 | is-has-password: true # [mqtt] 是否有密码
32 | user-name: root # [mqtt] 用户名(isHasUserName为true时配置)
33 | password: 7228788B19B1C983A10D20CB8E87749F0B7EFDD63D119B86693C85409FED1F5C345156305BD52B196962A01927EC0807553BDD05510EA1798AB7927CEF8BF63A # [mqtt]密码(isHasPassword为true时配置)
34 | is-will-retain: true # [mqtt] 是否保留遗嘱标志(isWillFlag为true时配置)
35 | will-qos: 0 # [mqtt] 连接服务质量等级(isWillFlag为true时配置)
36 | is-clean-session: true # [mqtt] 是否清除session
37 | keep-alive-time: 60 # [mqtt] 保持连接时间,连接允许的最大空闲时间,超过该时间服务端断开连接,单位秒
38 |
39 | server:
40 | port: 8989
41 |
42 | logging:
43 | level:
44 | root: info
45 | com.lzgyy.plugins.iot: debug
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ${AnsiColor.BRIGHT_GREEN}====================${AnsiColor.BRIGHT_RED} lzgyy-iot-client ${AnsiColor.BRIGHT_GREEN}====================
2 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-client/src/main/resources/keystore/client.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-client/src/main/resources/keystore/client.jks
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.lzgyy
5 | lzgyy-plugins
6 | 0.0.1-SNAPSHOT
7 |
8 | lzgyy-iot-core
9 |
10 |
11 | org.springframework.boot
12 | spring-boot-starter-web
13 |
14 |
15 |
16 | org.projectlombok
17 | lombok
18 | provided
19 |
20 |
21 |
22 | io.netty
23 | netty-handler
24 |
25 |
26 | io.netty
27 | netty-codec-mqtt
28 |
29 |
30 | io.netty
31 | netty-codec-http
32 |
33 |
34 | org.apache.ignite
35 | ignite-core
36 | 2.6.0
37 |
38 |
39 | org.apache.ignite
40 | ignite-slf4j
41 | 2.6.0
42 |
43 |
44 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/auth/service/IAuthService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.auth.service;
2 |
3 | /**
4 | * 用户和密码认证服务接口
5 | */
6 | public interface IAuthService {
7 |
8 | /**
9 | * 验证用户名和密码是否正确
10 | */
11 | boolean checkValid(String username, String password);
12 |
13 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/internal/bean/InternalMessage.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.internal.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * 内部消息
7 | */
8 | public class InternalMessage implements Serializable {
9 |
10 | private static final long serialVersionUID = 3631755468947273083L;
11 |
12 | private String topic;
13 |
14 | private int mqttQoS;
15 |
16 | private byte[] messageBytes;
17 |
18 | private boolean retain;
19 |
20 | private boolean dup;
21 |
22 | public String getTopic() {
23 | return topic;
24 | }
25 |
26 | public InternalMessage setTopic(String topic) {
27 | this.topic = topic;
28 | return this;
29 | }
30 |
31 | public int getMqttQoS() {
32 | return mqttQoS;
33 | }
34 |
35 | public InternalMessage setMqttQoS(int mqttQoS) {
36 | this.mqttQoS = mqttQoS;
37 | return this;
38 | }
39 |
40 | public byte[] getMessageBytes() {
41 | return messageBytes;
42 | }
43 |
44 | public InternalMessage setMessageBytes(byte[] messageBytes) {
45 | this.messageBytes = messageBytes;
46 | return this;
47 | }
48 |
49 | public boolean isRetain() {
50 | return retain;
51 | }
52 |
53 | public InternalMessage setRetain(boolean retain) {
54 | this.retain = retain;
55 | return this;
56 | }
57 |
58 | public boolean isDup() {
59 | return dup;
60 | }
61 |
62 | public InternalMessage setDup(boolean dup) {
63 | this.dup = dup;
64 | return this;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/internal/service/IInternalCommunication.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.internal.service;
2 |
3 | import com.lzgyy.plugins.iot.core.broker.internal.bean.InternalMessage;
4 |
5 | /**
6 | * 内部通信, 基于发布-订阅范式
7 | */
8 | public interface IInternalCommunication {
9 |
10 | public void internalListen();
11 |
12 | public void internalSend(InternalMessage internalMessage);
13 |
14 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/AConnect.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import com.lzgyy.plugins.iot.core.auth.service.IAuthService;
4 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPubRelMessageStoreService;
5 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPublishMessageStoreService;
6 | import com.lzgyy.plugins.iot.core.store.session.service.ISessionStoreService;
7 | import com.lzgyy.plugins.iot.core.store.subscribe.service.ISubscribeStoreService;
8 |
9 | import io.netty.channel.Channel;
10 |
11 | /**
12 | * 发起连接处理抽象类
13 | */
14 | public abstract class AConnect {
15 |
16 | /**
17 | * 会话存储服务接口
18 | */
19 | protected ISessionStoreService sessionStoreService;
20 |
21 | /**
22 | * 订阅存储服务接口
23 | */
24 | protected ISubscribeStoreService subscribeStoreService;
25 |
26 | /**
27 | * 重发publish消息存储服务接口
28 | */
29 | protected IDupPublishMessageStoreService dupPublishMessageStoreService;
30 |
31 | /**
32 | * 重发pubrel消息存储服务接口
33 | */
34 | protected IDupPubRelMessageStoreService dupPubRelMessageStoreService;
35 |
36 | /**
37 | * 用户和密码认证服务接口
38 | */
39 | protected IAuthService authService;
40 |
41 | protected AConnect(ISessionStoreService sessionStoreService, ISubscribeStoreService subscribeStoreService, IDupPublishMessageStoreService dupPublishMessageStoreService, IDupPubRelMessageStoreService dupPubRelMessageStoreService, IAuthService authService) {
42 | this.sessionStoreService = sessionStoreService;
43 | this.subscribeStoreService = subscribeStoreService;
44 | this.dupPublishMessageStoreService = dupPublishMessageStoreService;
45 | this.dupPubRelMessageStoreService = dupPubRelMessageStoreService;
46 | this.authService = authService;
47 | }
48 |
49 | /**
50 | * 处理发起连接
51 | * @param
52 | * @param channel
53 | * @param msg
54 | */
55 | protected void processConnect(Channel channel, T msg){};
56 |
57 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/ADisConnect.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import io.netty.channel.Channel;
4 |
5 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPubRelMessageStoreService;
6 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPublishMessageStoreService;
7 | import com.lzgyy.plugins.iot.core.store.session.service.ISessionStoreService;
8 | import com.lzgyy.plugins.iot.core.store.subscribe.service.ISubscribeStoreService;
9 |
10 | /**
11 | * 断开连接处理抽象类
12 | */
13 | public abstract class ADisConnect {
14 |
15 | /**
16 | * 会话存储服务接口
17 | */
18 | protected ISessionStoreService sessionStoreService;
19 |
20 | /**
21 | * 订阅存储服务接口
22 | */
23 | protected ISubscribeStoreService subscribeStoreService;
24 |
25 | /**
26 | * 重发publish消息存储服务接口
27 | */
28 | protected IDupPublishMessageStoreService dupPublishMessageStoreService;
29 |
30 | /**
31 | * 重发pubrel消息存储服务接口
32 | */
33 | protected IDupPubRelMessageStoreService dupPubRelMessageStoreService;
34 |
35 | protected ADisConnect(ISessionStoreService sessionStoreService, ISubscribeStoreService subscribeStoreService, IDupPublishMessageStoreService dupPublishMessageStoreService, IDupPubRelMessageStoreService dupPubRelMessageStoreService) {
36 | this.sessionStoreService = sessionStoreService;
37 | this.subscribeStoreService = subscribeStoreService;
38 | this.dupPublishMessageStoreService = dupPublishMessageStoreService;
39 | this.dupPubRelMessageStoreService = dupPubRelMessageStoreService;
40 | }
41 |
42 | /**
43 | * 处理断开连接
44 | * @param channel
45 | * @param msg
46 | */
47 | protected abstract void processDisConnect(Channel channel, T msg);
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/APingReq.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import io.netty.channel.Channel;
4 |
5 | /**
6 | * PING请求连接处理
7 | */
8 | public abstract class APingReq {
9 |
10 | /**
11 | * 处理PING请求
12 | * @param channel
13 | * @param msg
14 | */
15 | protected abstract void processPingReq(Channel channel, T msg);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/APubAck.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import io.netty.channel.Channel;
4 |
5 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPublishMessageStoreService;
6 | import com.lzgyy.plugins.iot.core.store.message.service.IMessageIdService;
7 |
8 | /**
9 | * 发布回执处理抽象类
10 | */
11 | public abstract class APubAck {
12 |
13 | /**
14 | * 分布式生成报文标识符
15 | */
16 | protected IMessageIdService messageIdService;
17 |
18 | /**
19 | * PUBLISH重发消息存储服务接口, 当QoS=1和QoS=2时存在该重发机制
20 | */
21 | protected IDupPublishMessageStoreService dupPublishMessageStoreService;
22 |
23 | public APubAck(IMessageIdService messageIdService, IDupPublishMessageStoreService dupPublishMessageStoreService) {
24 | this.messageIdService = messageIdService;
25 | this.dupPublishMessageStoreService = dupPublishMessageStoreService;
26 | }
27 |
28 | /**
29 | * 发布回执
30 | * @param channel
31 | * @param variableHeader
32 | */
33 | protected abstract void processPubAck(Channel channel, T variableHeader);
34 |
35 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/APubComp.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import io.netty.channel.Channel;
4 |
5 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPubRelMessageStoreService;
6 | import com.lzgyy.plugins.iot.core.store.message.service.IMessageIdService;
7 |
8 | /**
9 | * QoS2消息完成处理抽象类
10 | */
11 | public abstract class APubComp {
12 |
13 | /**
14 | * 分布式生成报文标识符接口
15 | */
16 | protected IMessageIdService messageIdService;
17 |
18 | /**
19 | * 重发pubrel消息存储服务接口, 当QoS=2时存在该重发机制
20 | */
21 | protected IDupPubRelMessageStoreService dupPubRelMessageStoreService;
22 |
23 | public APubComp(IMessageIdService messageIdService, IDupPubRelMessageStoreService dupPubRelMessageStoreService) {
24 | this.messageIdService = messageIdService;
25 | this.dupPubRelMessageStoreService = dupPubRelMessageStoreService;
26 | }
27 |
28 | /**
29 | * QoS2消息完成处理
30 | * @param channel
31 | * @param variableHeader
32 | */
33 | protected abstract void processPubComp(Channel channel, T variableHeader);
34 | }
35 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/APubRec.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import io.netty.channel.Channel;
4 |
5 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPubRelMessageStoreService;
6 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPublishMessageStoreService;
7 |
8 |
9 | /**
10 | * QoS2消息回执处理抽象类
11 | */
12 | public abstract class APubRec {
13 |
14 | /**
15 | * 重发publish消息存储服务接口, 当QoS=1和QoS=2时存在该重发机制
16 | */
17 | protected IDupPublishMessageStoreService dupPublishMessageStoreService;
18 |
19 | /**
20 | * 重发pubrel消息存储服务接口, 当QoS=2时存在该重发机制
21 | */
22 | protected IDupPubRelMessageStoreService dupPubRelMessageStoreService;
23 |
24 | protected APubRec(IDupPublishMessageStoreService dupPublishMessageStoreService, IDupPubRelMessageStoreService dupPubRelMessageStoreService) {
25 | this.dupPublishMessageStoreService = dupPublishMessageStoreService;
26 | this.dupPubRelMessageStoreService = dupPubRelMessageStoreService;
27 | }
28 |
29 | /**
30 | * QoS2消息回执
31 | * @param channel
32 | * @param variableHeader
33 | */
34 | protected abstract void processPubRec(Channel channel, T variableHeader);
35 |
36 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/APubRel.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import io.netty.channel.Channel;
4 |
5 | /**
6 | * QoS2消息释放连接处理抽象类
7 | */
8 | public abstract class APubRel {
9 |
10 | /**
11 | * 处理QoS2消息释放
12 | * @param channel
13 | * @param variableHeader
14 | */
15 | protected abstract void processPubRel(Channel channel, T variableHeader);
16 |
17 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/APublish.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import io.netty.channel.Channel;
4 |
5 | import com.lzgyy.plugins.iot.core.broker.internal.service.IInternalCommunication;
6 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPublishMessageStoreService;
7 | import com.lzgyy.plugins.iot.core.store.message.service.IMessageIdService;
8 | import com.lzgyy.plugins.iot.core.store.message.service.IRetainMessageStoreService;
9 | import com.lzgyy.plugins.iot.core.store.session.service.ISessionStoreService;
10 | import com.lzgyy.plugins.iot.core.store.subscribe.service.ISubscribeStoreService;
11 |
12 | /**
13 | * 发布消息处理抽象类
14 | */
15 | public abstract class APublish {
16 |
17 | /**
18 | * 会话存储服务接口
19 | */
20 | protected ISessionStoreService sessionStoreService;
21 |
22 | /**
23 | * 订阅存储服务接口
24 | */
25 | protected ISubscribeStoreService subscribeStoreService;
26 |
27 | /**
28 | * 分布式生成报文标识符接口
29 | */
30 | protected IMessageIdService messageIdService;
31 |
32 | /**
33 | * 消息存储服务接口
34 | */
35 | protected IRetainMessageStoreService retainMessageStoreService;
36 |
37 | /**
38 | * 重发publish消息存储服务接口
39 | */
40 | protected IDupPublishMessageStoreService dupPublishMessageStoreService;
41 |
42 | /**
43 | * 内部通信, 基于发布-订阅范式
44 | */
45 | protected IInternalCommunication iinternalCommunication;
46 |
47 | public APublish(ISessionStoreService sessionStoreService, ISubscribeStoreService subscribeStoreService, IMessageIdService messageIdService, IRetainMessageStoreService retainMessageStoreService, IDupPublishMessageStoreService dupPublishMessageStoreService, IInternalCommunication iinternalCommunication) {
48 | this.sessionStoreService = sessionStoreService;
49 | this.subscribeStoreService = subscribeStoreService;
50 | this.messageIdService = messageIdService;
51 | this.retainMessageStoreService = retainMessageStoreService;
52 | this.dupPublishMessageStoreService = dupPublishMessageStoreService;
53 | this.iinternalCommunication = iinternalCommunication;
54 | }
55 |
56 | /**
57 | * 处理发布消息
58 | * @param channel
59 | * @param msg
60 | */
61 | protected abstract void processPublish(Channel channel, T msg);
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/ASubscribe.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import io.netty.channel.Channel;
4 | import com.lzgyy.plugins.iot.core.store.message.service.IMessageIdService;
5 | import com.lzgyy.plugins.iot.core.store.message.service.IRetainMessageStoreService;
6 | import com.lzgyy.plugins.iot.core.store.subscribe.service.ISubscribeStoreService;
7 |
8 | /**
9 | * 订阅主题处理抽象类
10 | */
11 | public abstract class ASubscribe {
12 |
13 | /**
14 | * 订阅存储服务接口
15 | */
16 | protected ISubscribeStoreService subscribeStoreService;
17 |
18 | /**
19 | * 分布式生成报文标识符接口
20 | */
21 | protected IMessageIdService messageIdService;
22 |
23 | /**
24 | * 消息存储服务接口
25 | */
26 | protected IRetainMessageStoreService retainMessageStoreService;
27 |
28 | public ASubscribe(ISubscribeStoreService subscribeStoreService, IMessageIdService messageIdService, IRetainMessageStoreService retainMessageStoreService) {
29 | this.subscribeStoreService = subscribeStoreService;
30 | this.messageIdService = messageIdService;
31 | this.retainMessageStoreService = retainMessageStoreService;
32 | }
33 |
34 | /**
35 | * 处理订阅主题
36 | * @param channel
37 | * @param msg
38 | */
39 | protected abstract void processSubscribe(Channel channel, T msg);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/broker/protocol/abs/AUnSubscribe.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.broker.protocol.abs;
2 |
3 | import io.netty.channel.Channel;
4 | import com.lzgyy.plugins.iot.core.store.subscribe.service.ISubscribeStoreService;
5 |
6 | /**
7 | * 取消订阅处理抽象类
8 | */
9 | public abstract class AUnSubscribe {
10 |
11 | /**
12 | * 订阅存储服务接口
13 | */
14 | protected ISubscribeStoreService subscribeStoreService;
15 |
16 | public AUnSubscribe(ISubscribeStoreService subscribeStoreService) {
17 | this.subscribeStoreService = subscribeStoreService;
18 | }
19 |
20 | /**
21 | * 处理取消订阅
22 | * @param channel
23 | * @param msg
24 | */
25 | protected abstract void processUnSubscribe(Channel channel, T msg);
26 |
27 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/message/bean/DupPubRelMessageStore.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.message.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * 重发pubrel消息存储
7 | */
8 | public class DupPubRelMessageStore implements Serializable {
9 |
10 | private static final long serialVersionUID = -4111642532532950980L;
11 |
12 | private String clientId;
13 |
14 | private int messageId;
15 |
16 | public String getClientId() {
17 | return clientId;
18 | }
19 |
20 | public DupPubRelMessageStore setClientId(String clientId) {
21 | this.clientId = clientId;
22 | return this;
23 | }
24 |
25 | public int getMessageId() {
26 | return messageId;
27 | }
28 |
29 | public DupPubRelMessageStore setMessageId(int messageId) {
30 | this.messageId = messageId;
31 | return this;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/message/bean/DupPublishMessageStore.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.message.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * 重发publish消息存储
7 | */
8 | public class DupPublishMessageStore implements Serializable {
9 |
10 | private static final long serialVersionUID = -8112511377194421600L;
11 |
12 | private String clientId;
13 |
14 | private String topic;
15 |
16 | private int mqttQoS;
17 |
18 | private int messageId;
19 |
20 | private byte[] messageBytes;
21 |
22 |
23 | public String getClientId() {
24 | return clientId;
25 | }
26 |
27 | public DupPublishMessageStore setClientId(String clientId) {
28 | this.clientId = clientId;
29 | return this;
30 | }
31 |
32 | public String getTopic() {
33 | return topic;
34 | }
35 |
36 | public DupPublishMessageStore setTopic(String topic) {
37 | this.topic = topic;
38 | return this;
39 | }
40 |
41 | public int getMqttQoS() {
42 | return mqttQoS;
43 | }
44 |
45 | public DupPublishMessageStore setMqttQoS(int mqttQoS) {
46 | this.mqttQoS = mqttQoS;
47 | return this;
48 | }
49 |
50 | public int getMessageId() {
51 | return messageId;
52 | }
53 |
54 | public DupPublishMessageStore setMessageId(int messageId) {
55 | this.messageId = messageId;
56 | return this;
57 | }
58 |
59 | public byte[] getMessageBytes() {
60 | return messageBytes;
61 | }
62 |
63 | public DupPublishMessageStore setMessageBytes(byte[] messageBytes) {
64 | this.messageBytes = messageBytes;
65 | return this;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/message/bean/RetainMessageStore.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.message.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Retain标志消息存储
7 | */
8 | public class RetainMessageStore implements Serializable {
9 |
10 | private static final long serialVersionUID = -7548204047370972779L;
11 |
12 | private String topic;
13 |
14 | private byte[] messageBytes;
15 |
16 | private int mqttQoS;
17 |
18 | public String getTopic() {
19 | return topic;
20 | }
21 |
22 | public RetainMessageStore setTopic(String topic) {
23 | this.topic = topic;
24 | return this;
25 | }
26 |
27 | public byte[] getMessageBytes() {
28 | return messageBytes;
29 | }
30 |
31 | public RetainMessageStore setMessageBytes(byte[] messageBytes) {
32 | this.messageBytes = messageBytes;
33 | return this;
34 | }
35 |
36 | public int getMqttQoS() {
37 | return mqttQoS;
38 | }
39 |
40 | public RetainMessageStore setMqttQoS(int mqttQoS) {
41 | this.mqttQoS = mqttQoS;
42 | return this;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/message/service/IDupPubRelMessageStoreService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.message.service;
2 |
3 | import java.util.List;
4 |
5 | import com.lzgyy.plugins.iot.core.store.message.bean.DupPubRelMessageStore;
6 |
7 | /**
8 | * 重发pubrel消息存储服务接口, 当QoS=2时存在该重发机制
9 | */
10 | public interface IDupPubRelMessageStoreService {
11 |
12 | /**
13 | * 存储消息
14 | */
15 | void put(String clientId, DupPubRelMessageStore dupPubRelMessageStore);
16 |
17 | /**
18 | * 获取消息集合
19 | */
20 | List get(String clientId);
21 |
22 | /**
23 | * 删除消息
24 | */
25 | void remove(String clientId, int messageId);
26 |
27 | /**
28 | * 删除消息
29 | */
30 | void removeByClient(String clientId);
31 |
32 | /**
33 | * 销毁
34 | */
35 | void destroy();
36 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/message/service/IDupPublishMessageStoreService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.message.service;
2 |
3 | import java.util.List;
4 |
5 | import com.lzgyy.plugins.iot.core.store.message.bean.DupPublishMessageStore;
6 |
7 | /**
8 | * 重发publish消息存储服务接口, 当QoS=1和QoS=2时存在该重发机制
9 | */
10 | public interface IDupPublishMessageStoreService {
11 |
12 | /**
13 | * 存储消息
14 | */
15 | void put(String clientId, DupPublishMessageStore dupPublishMessageStore);
16 |
17 | /**
18 | * 获取消息集合
19 | */
20 | List get(String clientId);
21 |
22 | /**
23 | * 删除消息
24 | */
25 | void remove(String clientId, int messageId);
26 |
27 | /**
28 | * 删除消息
29 | */
30 | void removeByClient(String clientId);
31 |
32 | /**
33 | * 销毁
34 | */
35 | void destroy();
36 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/message/service/IMessageIdService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.message.service;
2 |
3 | /**
4 | * 分布式生成报文标识符接口
5 | */
6 | public interface IMessageIdService {
7 |
8 | /**
9 | * 获取报文标识符
10 | */
11 | int getNextMessageId();
12 |
13 | /**
14 | * 释放报文标识符
15 | */
16 | void releaseMessageId(int messageId);
17 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/message/service/IRetainMessageStoreService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.message.service;
2 |
3 | import java.util.List;
4 |
5 | import com.lzgyy.plugins.iot.core.store.message.bean.RetainMessageStore;
6 |
7 | /**
8 | * 消息存储服务接口
9 | */
10 | public interface IRetainMessageStoreService {
11 |
12 | /**
13 | * 存储retain标志消息
14 | */
15 | void put(String topic, RetainMessageStore retainMessageStore);
16 |
17 | /**
18 | * 获取retain消息
19 | */
20 | RetainMessageStore get(String topic);
21 |
22 | /**
23 | * 删除retain标志消息
24 | */
25 | void remove(String topic);
26 |
27 | /**
28 | * 销毁
29 | */
30 | void destroy();
31 |
32 | /**
33 | * 判断指定topic的retain消息是否存在
34 | */
35 | boolean containsKey(String topic);
36 |
37 | /**
38 | * 获取retain消息集合
39 | */
40 | List search(String topicFilter);
41 |
42 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/session/bean/SessionStore.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.session.bean;
2 |
3 | import io.netty.channel.Channel;
4 | //import io.netty.handler.codec.mqtt.MqttPublishMessage;
5 | import io.netty.handler.codec.mqtt.MqttPublishMessage;
6 |
7 | import java.io.Serializable;
8 |
9 | /**
10 | * 会话存储
11 | */
12 | public class SessionStore implements Serializable {
13 |
14 | private static final long serialVersionUID = 5209539791996944490L;
15 |
16 | private String clientId;
17 |
18 | private Channel channel;
19 |
20 | private boolean cleanSession;
21 |
22 | private MqttPublishMessage willMessage;
23 |
24 | public SessionStore(String clientId, Channel channel, boolean cleanSession, MqttPublishMessage willMessage) {
25 | this.clientId = clientId;
26 | this.channel = channel;
27 | this.cleanSession = cleanSession;
28 | this.willMessage = willMessage;
29 | }
30 |
31 | public String getClientId() {
32 | return clientId;
33 | }
34 |
35 | public SessionStore setClientId(String clientId) {
36 | this.clientId = clientId;
37 | return this;
38 | }
39 |
40 | public Channel getChannel() {
41 | return channel;
42 | }
43 |
44 | public SessionStore setChannel(Channel channel) {
45 | this.channel = channel;
46 | return this;
47 | }
48 |
49 | public boolean isCleanSession() {
50 | return cleanSession;
51 | }
52 |
53 | public SessionStore setCleanSession(boolean cleanSession) {
54 | this.cleanSession = cleanSession;
55 | return this;
56 | }
57 |
58 | public MqttPublishMessage getWillMessage() {
59 | return willMessage;
60 | }
61 |
62 | public SessionStore setWillMessage(MqttPublishMessage willMessage) {
63 | this.willMessage = willMessage;
64 | return this;
65 | }
66 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/session/service/ISessionStoreService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.session.service;
2 |
3 | import com.lzgyy.plugins.iot.core.store.session.bean.SessionStore;
4 |
5 | /**
6 | * 会话存储服务接口
7 | */
8 | public interface ISessionStoreService {
9 |
10 | /**
11 | * 存储会话
12 | */
13 | void put(String clientId, SessionStore sessionStore);
14 |
15 | /**
16 | * 获取会话
17 | */
18 | SessionStore get(String clientId);
19 |
20 | /**
21 | * clientId的会话是否存在
22 | */
23 | boolean containsKey(String clientId);
24 |
25 | /**
26 | * 删除会话
27 | */
28 | void remove(String clientId);
29 |
30 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/subscribe/bean/SubscribeStore.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.subscribe.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * 订阅存储
7 | */
8 | public class SubscribeStore implements Serializable {
9 |
10 | private static final long serialVersionUID = 1276156087085594264L;
11 |
12 | private String clientId;
13 |
14 | private String topicFilter;
15 |
16 | private int mqttQoS;
17 |
18 | public SubscribeStore(String clientId, String topicFilter, int mqttQoS) {
19 | this.clientId = clientId;
20 | this.topicFilter = topicFilter;
21 | this.mqttQoS = mqttQoS;
22 | }
23 |
24 | public String getClientId() {
25 | return clientId;
26 | }
27 |
28 | public SubscribeStore setClientId(String clientId) {
29 | this.clientId = clientId;
30 | return this;
31 | }
32 |
33 | public String getTopicFilter() {
34 | return topicFilter;
35 | }
36 |
37 | public SubscribeStore setTopicFilter(String topicFilter) {
38 | this.topicFilter = topicFilter;
39 | return this;
40 | }
41 |
42 | public int getMqttQoS() {
43 | return mqttQoS;
44 | }
45 |
46 | public SubscribeStore setMqttQoS(int mqttQoS) {
47 | this.mqttQoS = mqttQoS;
48 | return this;
49 | }
50 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-core/src/main/java/com/lzgyy/plugins/iot/core/store/subscribe/service/ISubscribeStoreService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.core.store.subscribe.service;
2 |
3 | import java.util.List;
4 |
5 | import com.lzgyy.plugins.iot.core.store.subscribe.bean.SubscribeStore;
6 |
7 | /**
8 | * 订阅存储服务接口
9 | */
10 | public interface ISubscribeStoreService {
11 |
12 | /**
13 | * 存储订阅
14 | */
15 | void put(String topicFilter, SubscribeStore subscribeStore);
16 |
17 | /**
18 | * 删除订阅
19 | */
20 | void remove(String topicFilter, String clientId);
21 |
22 | /**
23 | * 删除clientId的订阅
24 | */
25 | void removeForClient(String clientId);
26 |
27 | /**
28 | * 销毁
29 | */
30 | void destroy();
31 |
32 | /**
33 | * 获取订阅存储集
34 | */
35 | List search(String topic);
36 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-service/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-service/MQTT协议.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/MQTT协议.docx
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.lzgyy
5 | lzgyy-plugins
6 | 0.0.1-SNAPSHOT
7 |
8 | lzgyy-iot-service
9 |
10 |
11 | org.springframework.boot
12 | spring-boot-starter-web
13 |
14 |
15 |
16 | com.lzgyy
17 | lzgyy-iot-core
18 | 0.0.1-SNAPSHOT
19 |
20 |
21 |
22 | io.netty
23 | netty-transport-native-epoll
24 | linux-x86_64
25 |
26 |
27 |
28 | org.projectlombok
29 | lombok
30 | provided
31 |
32 |
33 | cn.hutool
34 | hutool-core
35 | 4.1.6
36 |
37 |
38 | cn.hutool
39 | hutool-crypto
40 | 4.1.6
41 |
42 |
43 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/BrokerApplication.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.WebApplicationType;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.annotation.Bean;
7 |
8 | import com.lzgyy.plugins.iot.service.mqtt.broker.config.BrokerProperties;
9 |
10 | @SpringBootApplication(scanBasePackages = {"com.lzgyy.plugins.iot"})
11 | public class BrokerApplication {
12 |
13 | @Bean
14 | public BrokerProperties brokerProperties() {
15 | return new BrokerProperties();
16 | }
17 |
18 | public static void main(String[] args) {
19 | SpringApplication application = new SpringApplication(BrokerApplication.class);
20 | System.setProperty("user.timezone","Asia/Shanghai"); //设置时区
21 | //System.setProperty("https.protocols", "TLSv1");
22 | application.setWebApplicationType(WebApplicationType.NONE);
23 | application.run(args);
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/auth/service/impl/AuthService.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.service.mqtt.auth.service.impl;
2 |
3 | import cn.hutool.core.io.IoUtil;
4 | import cn.hutool.core.util.StrUtil;
5 | import cn.hutool.crypto.asymmetric.KeyType;
6 | import cn.hutool.crypto.asymmetric.RSA;
7 |
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Service;
10 |
11 | import com.lzgyy.plugins.iot.core.auth.service.IAuthService;
12 | import com.lzgyy.plugins.iot.service.mqtt.broker.config.BrokerProperties;
13 |
14 | import javax.annotation.PostConstruct;
15 | import java.security.interfaces.RSAPrivateKey;
16 |
17 | /**
18 | * 用户名和密码认证服务
19 | */
20 | @Service
21 | public class AuthService implements IAuthService {
22 |
23 | private RSAPrivateKey privateKey;
24 |
25 | /**
26 | * 服务配置
27 | */
28 | @Autowired
29 | private BrokerProperties brokerProperties;
30 |
31 | @Override
32 | public boolean checkValid(String username, String password) {
33 | if (StrUtil.isBlank(username)) return false;
34 | if (StrUtil.isBlank(password)) return false;
35 | RSA rsa = new RSA(privateKey, null);
36 | String value = rsa.encryptBcd(username, KeyType.PrivateKey);
37 | return value.equals(password) ? true : false;
38 | }
39 |
40 | @PostConstruct
41 | public void init() {
42 | privateKey = IoUtil.readObj(AuthService.class.getClassLoader().getResourceAsStream(brokerProperties.getAuthPrivateKeyFile()));
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/auth/util/PwdUtil.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.service.mqtt.auth.util;
2 |
3 | import cn.hutool.core.io.IoUtil;
4 | import cn.hutool.crypto.asymmetric.KeyType;
5 | import cn.hutool.crypto.asymmetric.RSA;
6 |
7 | import java.io.InputStream;
8 | import java.security.PrivateKey;
9 | import java.util.Scanner;
10 |
11 | /**
12 | * 密码
13 | */
14 | public class PwdUtil {
15 |
16 | /**
17 | * 通过用户名和私钥生成密码
18 | */
19 | public static void main(String[] args) {
20 | System.out.println();
21 | System.out.print("输入需要获取密码的用户名: ");
22 | @SuppressWarnings("resource")
23 | Scanner scanner = new Scanner(System.in);
24 | String value = scanner.nextLine();
25 | InputStream is = PwdUtil.class.getClassLoader().getResourceAsStream("keystore/auth-private.key");
26 | PrivateKey privateKey = IoUtil.readObj(is);
27 | RSA rsa = new RSA(privateKey, null);
28 | System.out.println("用户名: " + value + " 对应生成的密码为: " + rsa.encryptBcd(value, KeyType.PrivateKey));
29 |
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/auth/util/RsaKeyUtil.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.service.mqtt.auth.util;
2 |
3 | import cn.hutool.core.io.FileUtil;
4 | import cn.hutool.core.io.IoUtil;
5 | import cn.hutool.crypto.SecureUtil;
6 |
7 | import java.security.KeyPair;
8 | import java.security.interfaces.RSAPrivateKey;
9 | import java.time.LocalDateTime;
10 | import java.util.Scanner;
11 |
12 | /**
13 | * 私钥
14 | */
15 | public class RsaKeyUtil {
16 |
17 | /**
18 | * 生成私钥文件
19 | */
20 | public static void main(String[] args) {
21 | System.out.println();
22 | System.out.print("输入保存密钥文件的路径(如: e:/): ");
23 | @SuppressWarnings("resource")
24 | Scanner scanner = new Scanner(System.in);
25 | String path = scanner.nextLine();
26 | KeyPair keyPair = SecureUtil.generateKeyPair("RSA", 512, LocalDateTime.now().toString().getBytes());
27 | RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
28 | String privatePath = path + "/auth-private.key";
29 | IoUtil.writeObjects(FileUtil.getOutputStream(privatePath), true, privateKey);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/broker/codec/MqttWebSocketCodec.java:
--------------------------------------------------------------------------------
1 | package com.lzgyy.plugins.iot.service.mqtt.broker.codec;
2 |
3 | import java.util.List;
4 |
5 | import io.netty.buffer.ByteBuf;
6 | import io.netty.channel.ChannelHandlerContext;
7 | import io.netty.handler.codec.MessageToMessageCodec;
8 | import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
9 |
10 | /**
11 | * WebSocket Mqtt消息编解码器
12 | */
13 | public class MqttWebSocketCodec extends MessageToMessageCodec {
14 |
15 | @Override
16 | protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List