├── .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... causeExceptionClasses) { 52 | Throwable cause = ex.getCause(); 53 | while (cause != null) { 54 | for (Class 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 out) throws Exception { 17 | out.add(new BinaryWebSocketFrame(msg.retain())); 18 | } 19 | 20 | @Override 21 | protected void decode(ChannelHandlerContext ctx, BinaryWebSocketFrame msg, List out) throws Exception { 22 | out.add(msg.retain().content()); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/broker/config/BrokerProperties.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.broker.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | import lombok.Data; 6 | 7 | /** 8 | * 服务配置 9 | */ 10 | @ConfigurationProperties(prefix = "spring.mqtt.broker") 11 | @Data 12 | public class BrokerProperties { 13 | 14 | // Broker唯一标识 15 | private String id; 16 | 17 | // [netty]服务器端口号 18 | private int serverPort = 8883; 19 | 20 | // [netty]WebSocket服务器端口号 21 | private int websocketServerPort = 9993; 22 | 23 | // [netty]WebSocket Path值, 默认值 /mqtt 24 | private String websocketPath = "/mqtt"; 25 | 26 | // [netty] IdleStateHandler心跳检测器,读超时时间,单位秒,当一个写操作不能在一定的时间内完成时,抛出此异常,并关闭连接。你同样可以在 exceptionCaught 方法中处理这个异常 27 | private int readerIdleTimeSeconds = 60; 28 | 29 | // [netty] 是否开启Epoll模式, 默认关闭 30 | private boolean useEpoll = false; 31 | 32 | // [netty] Sokcet参数, 存放已完成三次握手请求的队列最大长度, 默认511长度 33 | private int soBacklog = 511; 34 | 35 | // [netty] Socket参数, 是否开启心跳保活机制, 默认开启 36 | private boolean soKeepAlive = true; 37 | 38 | // [ssl] 使用ssl加密 39 | private boolean isSsl; 40 | 41 | // [ssl] 加密 jks文件地址 42 | private String jksFile; 43 | 44 | // [ssl] 加密jks目标源存储库口令,storepass指定密钥库的密码 45 | private String jksStorePass; 46 | 47 | // [ssl] 加密jks目标密钥库口令 48 | private String jksKeyPass; 49 | 50 | // [ssl] 权限私钥加密路径(供加密用户密码使用) 51 | private String authPrivateKeyFile; 52 | 53 | public boolean getIsSsl(){ 54 | return isSsl; 55 | } 56 | public void setIsSsl(boolean isSsl){ 57 | this.isSsl = isSsl; 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/broker/protocol/PingReq.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.broker.protocol; 2 | 3 | import io.netty.channel.Channel; 4 | import io.netty.handler.codec.mqtt.MqttFixedHeader; 5 | import io.netty.handler.codec.mqtt.MqttMessage; 6 | import io.netty.handler.codec.mqtt.MqttMessageFactory; 7 | import io.netty.handler.codec.mqtt.MqttMessageType; 8 | import io.netty.handler.codec.mqtt.MqttQoS; 9 | import io.netty.util.AttributeKey; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import com.lzgyy.plugins.iot.core.broker.protocol.abs.APingReq; 14 | 15 | /** 16 | * PING请求连接处理 17 | */ 18 | public class PingReq extends APingReq{ 19 | 20 | private static final Logger LOGGER = LoggerFactory.getLogger(PingReq.class); 21 | 22 | @Override 23 | public void processPingReq(Channel channel, MqttMessage msg) { 24 | 25 | if (channel.isOpen() && channel.isActive() && channel.isWritable()) { 26 | MqttMessage pingRespMessage = MqttMessageFactory.newMessage( 27 | new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0), null, null); 28 | LOGGER.debug("PINGREQ - clientIp: {}, clientId: {}", channel.remoteAddress().toString(), (String) channel.attr(AttributeKey.valueOf("clientId")).get()); 29 | channel.writeAndFlush(pingRespMessage); 30 | } 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/broker/protocol/PubAck.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.broker.protocol; 2 | 3 | import io.netty.channel.Channel; 4 | import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader; 5 | import io.netty.util.AttributeKey; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import com.lzgyy.plugins.iot.core.broker.protocol.abs.APubAck; 10 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPublishMessageStoreService; 11 | import com.lzgyy.plugins.iot.core.store.message.service.IMessageIdService; 12 | 13 | /** 14 | * 发布回执 15 | */ 16 | public class PubAck extends APubAck{ 17 | 18 | private static final Logger LOGGER = LoggerFactory.getLogger(PubAck.class); 19 | 20 | public PubAck(IMessageIdService messageIdService, IDupPublishMessageStoreService dupPublishMessageStoreService) { 21 | super(messageIdService, dupPublishMessageStoreService); 22 | } 23 | 24 | @Override 25 | public void processPubAck(Channel channel, MqttMessageIdVariableHeader variableHeader) { 26 | int messageId = variableHeader.messageId(); 27 | LOGGER.debug("PUBACK - clientIp: {}, clientId: {}, messageId: {}",channel.remoteAddress().toString(), (String) channel.attr(AttributeKey.valueOf("clientId")).get(), messageId); 28 | dupPublishMessageStoreService.remove((String) channel.attr(AttributeKey.valueOf("clientId")).get(), messageId); 29 | messageIdService.releaseMessageId(messageId); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/broker/protocol/PubComp.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.broker.protocol; 2 | 3 | import io.netty.channel.Channel; 4 | import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader; 5 | import io.netty.util.AttributeKey; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import com.lzgyy.plugins.iot.core.broker.protocol.abs.APubComp; 10 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPubRelMessageStoreService; 11 | import com.lzgyy.plugins.iot.core.store.message.service.IMessageIdService; 12 | 13 | /** 14 | * QoS2消息完成处理 15 | */ 16 | public class PubComp extends APubComp{ 17 | 18 | private static final Logger LOGGER = LoggerFactory.getLogger(PubComp.class); 19 | 20 | public PubComp(IMessageIdService messageIdService, IDupPubRelMessageStoreService dupPubRelMessageStoreService) { 21 | super(messageIdService, dupPubRelMessageStoreService); 22 | } 23 | 24 | @Override 25 | public void processPubComp(Channel channel, MqttMessageIdVariableHeader variableHeader) { 26 | int messageId = variableHeader.messageId(); 27 | LOGGER.debug("PUBCOMP - clientIp: {}, clientId: {}, messageId: {}",channel.remoteAddress().toString(), (String) channel.attr(AttributeKey.valueOf("clientId")).get(), messageId); 28 | dupPubRelMessageStoreService.remove((String) channel.attr(AttributeKey.valueOf("clientId")).get(), variableHeader.messageId()); 29 | messageIdService.releaseMessageId(messageId); 30 | } 31 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/broker/protocol/PubRec.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.broker.protocol; 2 | 3 | import io.netty.channel.Channel; 4 | import io.netty.handler.codec.mqtt.MqttFixedHeader; 5 | import io.netty.handler.codec.mqtt.MqttMessage; 6 | import io.netty.handler.codec.mqtt.MqttMessageFactory; 7 | import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader; 8 | import io.netty.handler.codec.mqtt.MqttMessageType; 9 | import io.netty.handler.codec.mqtt.MqttQoS; 10 | import io.netty.util.AttributeKey; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | import com.lzgyy.plugins.iot.core.broker.protocol.abs.APubRec; 15 | import com.lzgyy.plugins.iot.core.store.message.bean.DupPubRelMessageStore; 16 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPubRelMessageStoreService; 17 | import com.lzgyy.plugins.iot.core.store.message.service.IDupPublishMessageStoreService; 18 | 19 | /** 20 | * QoS2消息回执处理 21 | */ 22 | public class PubRec extends APubRec{ 23 | 24 | private static final Logger LOGGER = LoggerFactory.getLogger(PubRel.class); 25 | 26 | protected PubRec(IDupPublishMessageStoreService dupPublishMessageStoreService, IDupPubRelMessageStoreService dupPubRelMessageStoreService) { 27 | super(dupPublishMessageStoreService, dupPubRelMessageStoreService); 28 | } 29 | 30 | @Override 31 | public void processPubRec(Channel channel, MqttMessageIdVariableHeader variableHeader) { 32 | MqttMessage pubRelMessage = MqttMessageFactory.newMessage( 33 | new MqttFixedHeader(MqttMessageType.PUBREL, false, MqttQoS.AT_MOST_ONCE, false, 0), 34 | MqttMessageIdVariableHeader.from(variableHeader.messageId()), null); 35 | LOGGER.debug("PUBREC - clientIp: {}, clientId: {}, messageId: {}",channel.remoteAddress().toString(), (String) channel.attr(AttributeKey.valueOf("clientId")).get(), variableHeader.messageId()); 36 | dupPublishMessageStoreService.remove((String) channel.attr(AttributeKey.valueOf("clientId")).get(), variableHeader.messageId()); 37 | DupPubRelMessageStore dupPubRelMessageStore = new DupPubRelMessageStore().setClientId((String) channel.attr(AttributeKey.valueOf("clientId")).get()) 38 | .setMessageId(variableHeader.messageId()); 39 | dupPubRelMessageStoreService.put((String) channel.attr(AttributeKey.valueOf("clientId")).get(), dupPubRelMessageStore); 40 | channel.writeAndFlush(pubRelMessage); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/broker/protocol/PubRel.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.broker.protocol; 2 | 3 | import io.netty.channel.Channel; 4 | import io.netty.handler.codec.mqtt.MqttFixedHeader; 5 | import io.netty.handler.codec.mqtt.MqttMessage; 6 | import io.netty.handler.codec.mqtt.MqttMessageFactory; 7 | import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader; 8 | import io.netty.handler.codec.mqtt.MqttMessageType; 9 | import io.netty.handler.codec.mqtt.MqttQoS; 10 | import io.netty.util.AttributeKey; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | import com.lzgyy.plugins.iot.core.broker.protocol.abs.APubRel; 15 | 16 | /** 17 | * QoS2消息释放连接处理 18 | */ 19 | public class PubRel extends APubRel{ 20 | 21 | private static final Logger LOGGER = LoggerFactory.getLogger(PubRel.class); 22 | 23 | @Override 24 | public void processPubRel(Channel channel, MqttMessageIdVariableHeader variableHeader) { 25 | MqttMessage pubCompMessage = MqttMessageFactory.newMessage( 26 | new MqttFixedHeader(MqttMessageType.PUBCOMP, false, MqttQoS.AT_MOST_ONCE, false, 0), 27 | MqttMessageIdVariableHeader.from(variableHeader.messageId()), null); 28 | LOGGER.debug("PUBREL - clentIp: {}, clientId: {}, messageId: {}",channel.remoteAddress().toString(), (String) channel.attr(AttributeKey.valueOf("clientId")).get(), variableHeader.messageId()); 29 | channel.writeAndFlush(pubCompMessage); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/broker/protocol/UnSubscribe.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.broker.protocol; 2 | 3 | import io.netty.channel.Channel; 4 | import io.netty.handler.codec.mqtt.MqttFixedHeader; 5 | import io.netty.handler.codec.mqtt.MqttMessageFactory; 6 | import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader; 7 | import io.netty.handler.codec.mqtt.MqttMessageType; 8 | import io.netty.handler.codec.mqtt.MqttQoS; 9 | import io.netty.handler.codec.mqtt.MqttUnsubAckMessage; 10 | import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage; 11 | import io.netty.util.AttributeKey; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import com.lzgyy.plugins.iot.core.broker.protocol.abs.AUnSubscribe; 16 | import com.lzgyy.plugins.iot.core.store.subscribe.service.ISubscribeStoreService; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * 取消订阅 22 | */ 23 | public class UnSubscribe extends AUnSubscribe{ 24 | 25 | private static final Logger LOGGER = LoggerFactory.getLogger(UnSubscribe.class); 26 | 27 | public UnSubscribe(ISubscribeStoreService subscribeStoreService) { 28 | super(subscribeStoreService); 29 | } 30 | 31 | @Override 32 | public void processUnSubscribe(Channel channel, MqttUnsubscribeMessage msg) { 33 | List topicFilters = msg.payload().topics(); 34 | String clinetId = (String) channel.attr(AttributeKey.valueOf("clientId")).get(); 35 | topicFilters.forEach(topicFilter -> { 36 | subscribeStoreService.remove(topicFilter, clinetId); 37 | LOGGER.debug("UNSUBSCRIBE - clientIp: {}, clientId: {}, topicFilter: {}",channel.remoteAddress().toString(), clinetId, topicFilter); 38 | }); 39 | MqttUnsubAckMessage unsubAckMessage = (MqttUnsubAckMessage) MqttMessageFactory.newMessage( 40 | new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0), 41 | MqttMessageIdVariableHeader.from(msg.variableHeader().messageId()), null); 42 | channel.writeAndFlush(unsubAckMessage); 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/store/config/IgniteProperties.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.store.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | /** 6 | * ignite属性配置 7 | */ 8 | @ConfigurationProperties(prefix = "spring.mqtt.broker.cache") 9 | public class IgniteProperties { 10 | 11 | /** 12 | * [apache ignite] 持久化缓存内存初始化大小(MB), 默认值: 64 13 | */ 14 | private int persistenceInitialSize = 64; 15 | 16 | /** 17 | * [apache ignite] 持久化缓存占用内存最大值(MB), 默认值: 128 18 | */ 19 | private int persistenceMaxSize = 128; 20 | 21 | /** 22 | * [apache ignite] 持久化磁盘存储路径 23 | */ 24 | private String persistenceStorePath; 25 | 26 | /** 27 | * [apache ignite] 非持久化缓存内存初始化大小(MB), 默认值: 64 28 | */ 29 | private int NotPersistenceInitialSize = 64; 30 | 31 | /** 32 | * [apache ignite] 非持久化缓存占用内存最大值(MB), 默认值: 128 33 | */ 34 | private int NotPersistenceMaxSize = 128; 35 | 36 | public int getPersistenceInitialSize() { 37 | return persistenceInitialSize; 38 | } 39 | 40 | public IgniteProperties setPersistenceInitialSize(int persistenceInitialSize) { 41 | this.persistenceInitialSize = persistenceInitialSize; 42 | return this; 43 | } 44 | 45 | public int getPersistenceMaxSize() { 46 | return persistenceMaxSize; 47 | } 48 | 49 | public IgniteProperties setPersistenceMaxSize(int persistenceMaxSize) { 50 | this.persistenceMaxSize = persistenceMaxSize; 51 | return this; 52 | } 53 | 54 | public String getPersistenceStorePath() { 55 | return persistenceStorePath; 56 | } 57 | 58 | public IgniteProperties setPersistenceStorePath(String persistenceStorePath) { 59 | this.persistenceStorePath = persistenceStorePath; 60 | return this; 61 | } 62 | 63 | public int getNotPersistenceInitialSize() { 64 | return NotPersistenceInitialSize; 65 | } 66 | 67 | public IgniteProperties setNotPersistenceInitialSize(int notPersistenceInitialSize) { 68 | NotPersistenceInitialSize = notPersistenceInitialSize; 69 | return this; 70 | } 71 | 72 | public int getNotPersistenceMaxSize() { 73 | return NotPersistenceMaxSize; 74 | } 75 | 76 | public IgniteProperties setNotPersistenceMaxSize(int notPersistenceMaxSize) { 77 | NotPersistenceMaxSize = notPersistenceMaxSize; 78 | return this; 79 | } 80 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/store/message/service/impl/MessageIdService.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.store.message.service.impl; 2 | 3 | import org.apache.ignite.IgniteCache; 4 | import org.springframework.stereotype.Service; 5 | 6 | import com.lzgyy.plugins.iot.core.store.message.service.IMessageIdService; 7 | 8 | import javax.annotation.Resource; 9 | import java.util.concurrent.locks.Lock; 10 | 11 | @Service 12 | public class MessageIdService implements IMessageIdService { 13 | 14 | private final int MIN_MSG_ID = 1; 15 | 16 | private final int MAX_MSG_ID = 65535; 17 | 18 | private final int lock = 0; 19 | 20 | @Resource 21 | private IgniteCache messageIdCache; 22 | 23 | private int nextMsgId = MIN_MSG_ID - 1; 24 | 25 | @Override 26 | public int getNextMessageId() { 27 | Lock lock = messageIdCache.lock(this.lock); 28 | lock.lock(); 29 | try { 30 | do { 31 | nextMsgId++; 32 | if (nextMsgId > MAX_MSG_ID) { 33 | nextMsgId = MIN_MSG_ID; 34 | } 35 | } while (messageIdCache.containsKey(nextMsgId)); 36 | messageIdCache.put(nextMsgId, nextMsgId); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } finally { 40 | lock.unlock(); 41 | } 42 | return nextMsgId; 43 | } 44 | 45 | @Override 46 | public void releaseMessageId(int messageId) { 47 | Lock lock = messageIdCache.lock(this.lock); 48 | lock.lock(); 49 | try { 50 | messageIdCache.remove(messageId); 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } finally { 54 | lock.unlock(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/java/com/lzgyy/plugins/iot/service/mqtt/store/session/service/impl/SessionStoreService.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.iot.service.mqtt.store.session.service.impl; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import com.lzgyy.plugins.iot.core.store.session.bean.SessionStore; 6 | import com.lzgyy.plugins.iot.core.store.session.service.ISessionStoreService; 7 | 8 | import java.util.Map; 9 | import java.util.concurrent.ConcurrentHashMap; 10 | 11 | /** 12 | * 会话存储服务 13 | */ 14 | @Service 15 | public class SessionStoreService implements ISessionStoreService { 16 | 17 | private Map sessionCache = new ConcurrentHashMap(); 18 | 19 | @Override 20 | public void put(String clientId, SessionStore sessionStore) { 21 | sessionCache.put(clientId, sessionStore); 22 | } 23 | 24 | @Override 25 | public SessionStore get(String clientId) { 26 | return sessionCache.get(clientId); 27 | } 28 | 29 | @Override 30 | public boolean containsKey(String clientId) { 31 | return sessionCache.containsKey(clientId); 32 | } 33 | 34 | @Override 35 | public void remove(String clientId) { 36 | sessionCache.remove(clientId); 37 | } 38 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: test 4 | 5 | logging: 6 | level: 7 | root: info 8 | com.lzgyy.plugins.iot: debug 9 | --- 10 | # 测试环境 11 | spring: 12 | profiles: test 13 | mqtt: 14 | broker: 15 | # 其它配置 16 | id: lzgyy-iot-broker-1 # Broker唯一标识 17 | # netty 服务器端配置 18 | server-port: 8883 # [netty]服务器端口号 19 | websocket-server-port: 9995 # [netty]WebSocket服务器端口号 20 | websocket-path: /mqtt # [netty]WebSocket Path值, 默认值/mqtt 21 | reader-idle-time-seconds: 60 # [netty] IdleStateHandler心跳检测器,读超时时间,单位秒 22 | use-epoll: false # [netty] 是否开启Epoll模式, 默认关闭 23 | so-backlog: 511 # [netty] Sokcet参数, 存放已完成三次握手请求的队列最大长度, 默认511长度 24 | so-keep-alive: true # [netty] Socket参数, 是否开启心跳保活机制, 默认开启 25 | # ssl配置 26 | is-ssl: true # [ssl]使用ssl加密 27 | jks-file: keystore/server.jks # [ssl] 加密 jks文件地址 28 | jks-store-pass: 6655443322119 # [ssl] 加密jks目标源存储库口令,storepass指定密钥库的密码 29 | jks-key-pass: 6655443322118 # [ssl] 加密jks目标密钥库口令 30 | auth-private-key-file: keystore/auth-private.key # [ssl] 权限私钥加密路径(供加密用户密码使用) 31 | # apache ignite缓存配置 32 | enable-multicast-group: false # [apache ignite] 集群配置, 是否基于组播发现, 默认开启 33 | multicast-group: 127.0.0.1 # [apache ignite] 集群配置, 基于组播发现 34 | static-ip-addresses: 127.0.0.1 # [apache ignite] 集群配置, 当组播模式禁用时, 使用静态IP开启配置集群 35 | cache: 36 | persistence-initial-size: 64 # [apache ignite](非必输)持久化缓存内存初始化大小(MB), 默认值: 64 37 | persistence-max-size: 128 # [apache ignite](非必输)持久化缓存占用内存最大值(MB), 默认值: 128 38 | persistence-store-path: /opt/lzgyy-iot-broker/persistence # [apache ignite] 持久化磁盘存储路径 39 | not-persistence-initial-size: 64 # [apache ignite](非必输)非持久化缓存内存初始化大小(MB), 默认值: 64 40 | not-persistence-max-size: 128 # [apache ignite](非必输)非持久化缓存占用内存最大值(MB), 默认值: 128 -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ${AnsiColor.BRIGHT_GREEN}====================${AnsiColor.BRIGHT_RED} lzgyy-iot-service ${AnsiColor.BRIGHT_GREEN}==================== 2 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/auth-private.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/auth-private.key -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/client-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDYjCCAkoCCQCjQNHT2cYfyDANBgkqhkiG9w0BAQUFADBxMQswCQYDVQQGEwJD 3 | TjELMAkGA1UECAwCR0QxCzAJBgNVBAcMAlNaMQwwCgYDVQQKDANDT00xDDAKBgNV 4 | BAsMA05TUDELMAkGA1UEAwwCQ0ExHzAdBgkqhkiG9w0BCQEWEDU2NDI2MzgyMEBx 5 | cS5jb20wHhcNMTgxMjAzMjIwODQ5WhcNMjgxMTMwMjIwODQ5WjB1MQswCQYDVQQG 6 | EwJDTjELMAkGA1UECAwCR0QxCzAJBgNVBAcMAlNaMQwwCgYDVQQKDANDT00xDDAK 7 | BgNVBAsMA05TUDEPMA0GA1UEAwwGQ0xJRU5UMR8wHQYJKoZIhvcNAQkBFhA1NjQy 8 | NjM4MjBAcXEuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3/xq 9 | j17EuBMFMSKR0yveLdQMTNOyr8rkGNf2G+hG9ytUxUh0nk4UK+jBzpHIOidFs15p 10 | kl0hZaUKAZZXEm1UW2GaxZARrW4UbUW8zaj1SOYu5twIVWGltjgfkIT4x2iDHR9m 11 | xYKIa6q5hGoR8nGI0IEb7cFuewdYhH8O1CGvB6jqsOPWAMDALDaBeemex6L/Ga/4 12 | zNnAxzM3/MSVjDfw3bkVccqWU1ET5a+JiWGx5/teDvlmrabdtHjDzAoZKSVDWKUd 13 | BDlz8qrwzqtxbkGbuFuWGf6JuH1aagYbyoJhA5AjJx2PC5gtepnmZ3wOP2097ym+ 14 | NImW9tSYWKbPa+m36QIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQArs15yTIRiPI76 15 | rKh/WW16N/Mt869rLQfDKtHt8ga+pMruCnFteIrSN91mafdVP17jwB2Jnex5gDcX 16 | 8Ufl2bi2qfPNh3pQlg0n5QHN3GUiw6RCJVReQ6w427dA/SoRX+Z3kbJoNdu2mEJK 17 | eav/J/vC+uOJz28N5WaMp2QI1HDoqQGqYXmgy743iXX6XKmP9CBsFGOLynBIDDD4 18 | L6e9mRrx89QVzLl6cJCPIJeP0EyBEgLH6WKFI1B2tl1UbtPSwziqgVUCHQ86bY29 19 | mfqQtGZBTKhBfwEP6blYa33knHMQqDEfFo0BjvrZl/14M4UpuEcPh+trekR95G+0 20 | TQRgYYUR 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/client-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEA3/xqj17EuBMFMSKR0yveLdQMTNOyr8rkGNf2G+hG9ytUxUh0 3 | nk4UK+jBzpHIOidFs15pkl0hZaUKAZZXEm1UW2GaxZARrW4UbUW8zaj1SOYu5twI 4 | VWGltjgfkIT4x2iDHR9mxYKIa6q5hGoR8nGI0IEb7cFuewdYhH8O1CGvB6jqsOPW 5 | AMDALDaBeemex6L/Ga/4zNnAxzM3/MSVjDfw3bkVccqWU1ET5a+JiWGx5/teDvlm 6 | rabdtHjDzAoZKSVDWKUdBDlz8qrwzqtxbkGbuFuWGf6JuH1aagYbyoJhA5AjJx2P 7 | C5gtepnmZ3wOP2097ym+NImW9tSYWKbPa+m36QIDAQABAoIBAQCOt2i2XW3+06+1 8 | NQ+xe/wfO0NzGFh8hkx8P+7CrWe6SdPDuH0F+T4FFFOY6W6pDyjsNzYRWmHTQCt2 9 | A3MLfLoJV9GkHD4HQWKmlY7Ng+B2SKSN2Jk+ve82geAq128kr8ULI1z6cEe4Qpne 10 | cy9oSUshf4JqJZvdrDqMgeDS7Xt25sqT0RWqUYsr41uEyyP8Y29r8ThLC+sq88lW 11 | tvJnLkokODBJWK5QY7W4PT+x0bylnR0tC41NvdLAQlFi3fV/FUYoJJi8Ff4QPOTB 12 | fmo+EPi+Sf4Erln2L9N5nQLkHFsZXHmOWUDD28Xx6RNuMvgP0oSHWDvD5TD/wj+O 13 | eRa82715AoGBAP7dSQk1jGSo3paANY552Cyla8QXFJSZmWygkVQyZXq/T7jd2X4e 14 | WAow+C48PQZwzKEWsYsnhtHvbzF3m6wuV+u2PKbq2YW2ZAVgZOU2A1bfgTQ6pj36 15 | +l6OFPBRiM7ToT8BqWsnPfamI94TvgLo2ShErSyL6HeOr8cQ++7Idg+bAoGBAOD7 16 | 6Lj7w2+G1ajJ936+IdpK949naHcDwoxu2P6KCnZMsf5RNfelpwKk0ePfF0P5MFCk 17 | T+Lr9YvAMzAirgJ5ItG798a2OhE9U1vNNM64mPWh6zDAEIPq3eoVfihKQJrFkg59 18 | vbZea7yNOt1IYtguEGwrRdQZ172RyYZ+tCbYk4jLAoGBAJL8wpOaG4cuUXmRJdIu 19 | +Xr+SIHGIet2DqM0k7xweFBrp6nh4P64t2PhTDE2MqfVRF8ffHPZ7wqCwalQ5ypN 20 | bA2Yg7Bsv9k7EMJ9DpOXLCPdMWIS9S/H4L/Jx8+15mYKbfOtnK0c68KlnQgGcM6y 21 | xhNQUGPhqMfTNhNj+ziCynxDAoGADIs/EIFJBkDYTM7l87UaIhen8eDsHCajhDzx 22 | 8E82Ah6IlgtlHOephiY2ZaQcofeU0Ao5Qgex6xbOQ9LLLOwgGt2GFRg36JoouaeZ 23 | WCVGsftTJ6atxQ0lTlXgcNKjA34chJ5SI4bkLuEY9RmCGVeIJt/Kxuah9rnYKJ2L 24 | 4daVcz0CgYB7zB5Cr+ueH8VQJ6yVIEJFZJgzliI+ROuBu2p4Ph2fKjG5OKC8ZZRg 25 | RwUq0z4ANe5e/XAYDiiyOGRyej4mU2w2W4UxOZ3hjdLkqb2KWJIOndW5qLEMdRep 26 | w9zioSkwyG2pEgwlylA6Uec9bqI3NEsYpwjDSmRfdMONxttW5N2sfw== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/client-req.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICujCCAaICAQAwdTELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkdEMQswCQYDVQQH 3 | DAJTWjEMMAoGA1UECgwDQ09NMQwwCgYDVQQLDANOU1AxDzANBgNVBAMMBkNMSUVO 4 | VDEfMB0GCSqGSIb3DQEJARYQNTY0MjYzODIwQHFxLmNvbTCCASIwDQYJKoZIhvcN 5 | AQEBBQADggEPADCCAQoCggEBAN/8ao9exLgTBTEikdMr3i3UDEzTsq/K5BjX9hvo 6 | RvcrVMVIdJ5OFCvowc6RyDonRbNeaZJdIWWlCgGWVxJtVFthmsWQEa1uFG1FvM2o 7 | 9UjmLubcCFVhpbY4H5CE+Mdogx0fZsWCiGuquYRqEfJxiNCBG+3BbnsHWIR/DtQh 8 | rweo6rDj1gDAwCw2gXnpnsei/xmv+MzZwMczN/zElYw38N25FXHKllNRE+WviYlh 9 | sef7Xg75Zq2m3bR4w8wKGSklQ1ilHQQ5c/Kq8M6rcW5Bm7hblhn+ibh9WmoGG8qC 10 | YQOQIycdjwuYLXqZ5md8Dj9tPe8pvjSJlvbUmFimz2vpt+kCAwEAAaAAMA0GCSqG 11 | SIb3DQEBBQUAA4IBAQAxI9KVg51WQi37YHl6LNO2lf7G7742UQ+l6mnsMzSX5+3s 12 | 083CkK30GOl1SRCtneEEdrpJRHNS3yA4lQI8okCgV8vgyh4EgvKfaOmJScO67R/Y 13 | rECWZ6HDSBCwzwhCCWFUVWUQPzs5hs0/eUgX/cs4F4hg6SaVHHxE/FWN6Sdgmaes 14 | Dwwmfzb6Yjqkjqe4qeGekc2fdCRKKKjVDCQhqDnoTU+verkst53QST3KwWjfLRkb 15 | EexAH2cDwr9JE2ylflxf2GjNlVf0hA1hiAGM9Cs0oVi5M9rnqaFe+SVisWTveXbe 16 | yrf9Iwv+PZE58VAOo+Ou4ugxfRTFW43VMvZIjZb9 17 | -----END CERTIFICATE REQUEST----- 18 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/client.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/client.jks -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/client.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/client.p12 -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/client_rsa.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/client_rsa.cer -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/root-cert.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/root-cert.jks -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/root-cert.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/root-cert.p12 -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/root-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDXjCCAkYCCQC7NLJYjwwW3DANBgkqhkiG9w0BAQUFADBxMQswCQYDVQQGEwJD 3 | TjELMAkGA1UECAwCR0QxCzAJBgNVBAcMAlNaMQwwCgYDVQQKDANDT00xDDAKBgNV 4 | BAsMA05TUDELMAkGA1UEAwwCQ0ExHzAdBgkqhkiG9w0BCQEWEDU2NDI2MzgyMEBx 5 | cS5jb20wHhcNMTgxMjAzMjE0MzIyWhcNMjgxMTMwMjE0MzIyWjBxMQswCQYDVQQG 6 | EwJDTjELMAkGA1UECAwCR0QxCzAJBgNVBAcMAlNaMQwwCgYDVQQKDANDT00xDDAK 7 | BgNVBAsMA05TUDELMAkGA1UEAwwCQ0ExHzAdBgkqhkiG9w0BCQEWEDU2NDI2Mzgy 8 | MEBxcS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCcjDb33xZ2 9 | 5/wVnbxd1eaqn8+cxu6ZHX4FbNUqySCh52mL+efJRUP1DpRBhOf0zxHIg+XT3Wdr 10 | xSJLN35FsXHJ/xP8ftIV3peHbv5mi34mViDeHJZmTyetvPryuI7DeRApYcVQl2t3 11 | pYSQUKGAZUQ6pyA3EnkrgZ3ZitlyK4EQMthY/20d/B73t1BVt/OVRenvDfTWbZcz 12 | WGbhkTlsYOVXzNugM0Ky+uTP7sTG0SooBCD94ae6mTCgmLNeuz0TVhtcHScl4MY5 13 | SuTcCj2+0GR2JK/ID/HKYf5CGHK70NjgOCOMipIlpilZAWMOA1u8MS3Aj2QSNzbX 14 | 9kLakR4zvyUxAgMBAAEwDQYJKoZIhvcNAQEFBQADggEBABmou3ANwAFscNQmyjBS 15 | csUjafzkNePhFRHAURRfQWz8KhAZWOE7eErOHT1J71+lMA+erTlLOZ1Z4pihZQCi 16 | Uq2xro3Ult+bL9bov0RIZKbrh0HWFGBjOEI7hyljDnq4yrGr/BYFFlgr+j4f/pzi 17 | toZeuc88CSTdI6yo/XQ0QoK1sFnPOCLchwvmN5HsFk8WJRhzRfeWM8cas3w71Tuu 18 | FRXrQEcm1ioEYJef6IVkCCA/3dPnEutdQG9QNHIpdtE9Szn0qrxwH6gEQNeAACAk 19 | mgk/qr1Pk69IaNFRKxds0TJy7TnmncElYxKkaOua0uAslkssn5vGbbDjYMOyK2RL 20 | 1WE= 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/root-cert.srl: -------------------------------------------------------------------------------- 1 | A340D1D3D9C61FC8 2 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/root-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIytobz81FFuYCAggA 3 | MBQGCCqGSIb3DQMHBAj3Y9QZTQYgSQSCBMhe4ZVhOfxtdsC6U2rlKqnZ76x5fZoz 4 | 0BcDuOujueHaVD9GmXSyJnITuj2UqJRWzlu1ZZSANcXRa55rU3Vl+ybC7uGHU9eH 5 | ADGEe3/RywkNyJ6LDK/r4Z7cAa5UEVQdoX7oCX3VuRSmcb4bokcrsCyTTexFaAA/ 6 | 4RzEkJeWpLS0wvQpruJ4h9MABdtvX3i0dnrJyVXqcIkD8Sx1i5DfEZQ2OIj85BfW 7 | 9rkqYzVIXSiXTG5eue56WBTF0fLApzYLxEcG/Yyl3m8ngkOemjznLSMnxM2Aw6u8 8 | 58pLsa6JFXBffFuOgmj3R0TZ30TKhxYbbWGLzbhbtkcf8UtQWX0HwEMw4px3rvgC 9 | EIJ70E3HwM0X8cViZGkD+XcwnpUyQhrOdaOCchqgkry0y+Oc2k/W40Yb2OJ9OL8O 10 | 92KxLqY8iNYYOyuQbte3tITDToq5kQ/rVwJYf62TvnwsUKklfKATEOMVXk27/zuS 11 | CPRyK988g9UDwOth2hnUD7nw58uj64L9hv7l8okPQBm7T9fYx2W+CQ9FclUyIUKB 12 | DgNOx8Bz2HZkK7dVCBYJH6MpTgemqWZy7jONwFpL3ty+WDCxdLhchsXRlkJryOFZ 13 | Tx7QNzYCms+vcf26iyyILJf5UUMF1XfbyGs+k4gKFvnDhNoeOSnm0Pnz34JQlosX 14 | 5cnjcyaydmkr8NbCWo+MMVd1NAcPyzaEVQju6HpCgZYn1wYoQsDylJvm3FDIbNes 15 | 0svq4G7AhfrUj1k8j2sq3AHDGccpYcs4+csRO7PGlcDN5u3ZtF8CiHVN3wXIY0YW 16 | mA3kSeIcoRP4VtmTfUjOFfkTUE4SdHtAkJaaAU2t99zTx0dg/skKPhM/JkUJ0dJi 17 | pMaxLbsEzStVHRB7oFXPe4f5sjIWAxzCc17kElbWzlcuJofhFMWvvZ2jtfZGhItd 18 | UHe0Pfjn5sE2LNxF5Mwfm/rMELsNOJWSXnxNaAkACAFEORD/yUp0ngYz3H0oYP7c 19 | 34d6sKyC77ebNoXf3/HhAmwSsXzq0ctEN7pfewgOicwn+OSVs0XLIDC0lQ1VRDtf 20 | m4Yv+FRs67UMIOPP2jrbfQtoRygL8g6vp7TQ6hnsyW0a4Ln3VDUk251X0OuN9Fml 21 | z9ofmLFU3QM+7IAYhEvWdXKWih3wxiXYF8U9IH1nhbOLk98ELbTH7UEwcFXosdAd 22 | irAusud81itwhEx8HMdC4/46110+NiF4oIeYglMCn10oV4tKFlQXVhwFhmSXrAfo 23 | NqqkBuO1K/EITw7mRfM3PQbyf6U+o9O3vYtYDNBMIvR31TQcZ/6rAlQ1xteT6H0M 24 | SH5vNqBgNhNZq2w5iYUs4kEytiCfTHLpAwJeW1f8aNuH393uaYL6Jf9wh2K3Vdi1 25 | lmtyy52T0rNZLIRD+zeebwcIjrDDgl6k0kHA/tlTZjsVgjuBVB9N8YRC7nAWTY82 26 | F1uYmHNg4OFL6zT5wvkEz+k/ZQ7b428GZ/EwPAheUvnKQLPk2tzZMcbVEDcIYRWi 27 | 5yE+YCxu221/7/VZdp5LzDxYpBZKHkUC7NFi+fxh7FN/8e2JDcng+egdKXPOtF6u 28 | 1GbHU20fUV1AAcDR81BZOg5JM4UDQReCkc/IMUmehpo01nrbcU7E7MzlnplOdJl8 29 | eWo= 30 | -----END ENCRYPTED PRIVATE KEY----- 31 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/root-req.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICtjCCAZ4CAQAwcTELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkdEMQswCQYDVQQH 3 | DAJTWjEMMAoGA1UECgwDQ09NMQwwCgYDVQQLDANOU1AxCzAJBgNVBAMMAkNBMR8w 4 | HQYJKoZIhvcNAQkBFhA1NjQyNjM4MjBAcXEuY29tMIIBIjANBgkqhkiG9w0BAQEF 5 | AAOCAQ8AMIIBCgKCAQEAnIw2998Wduf8FZ28XdXmqp/PnMbumR1+BWzVKskgoedp 6 | i/nnyUVD9Q6UQYTn9M8RyIPl091na8UiSzd+RbFxyf8T/H7SFd6Xh27+Zot+JlYg 7 | 3hyWZk8nrbz68riOw3kQKWHFUJdrd6WEkFChgGVEOqcgNxJ5K4Gd2YrZciuBEDLY 8 | WP9tHfwe97dQVbfzlUXp7w301m2XM1hm4ZE5bGDlV8zboDNCsvrkz+7ExtEqKAQg 9 | /eGnupkwoJizXrs9E1YbXB0nJeDGOUrk3Ao9vtBkdiSvyA/xymH+Qhhyu9DY4Dgj 10 | jIqSJaYpWQFjDgNbvDEtwI9kEjc21/ZC2pEeM78lMQIDAQABoAAwDQYJKoZIhvcN 11 | AQEFBQADggEBAFzjvho6QTcC9f6VtUSNoAObQvyklhxRbPE5FPSoOcfeK7QVsdV6 12 | WE2Yn7VEUQWGTEV+Jq1uDpk/p/9lM9LIKeE8icumMCwfiDBXCREnkhiYSIvYy9lT 13 | ocFTSCmx7ISV5F1oMkucRxtr3OJE6q5WumlzMjMzGDe9HJjkfYiXT6pFAVy8UyoJ 14 | MBEAsXaMTitX3Lgim1CyJJj1zkrAuHONwlBhIbPqDZTt8xhdA0JZPrVrxMX+zclk 15 | HPns+00GC7N00BbRxMH+iuGMd0E4YpHIIhgG1W+uOSMcjhgnkZ4BqFAKZq/wlsUB 16 | A9JuhMmpcqS019rLmW4HSgLUiOCi598TZVg= 17 | -----END CERTIFICATE REQUEST----- 18 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/server-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDYjCCAkoCCQCjQNHT2cYfxzANBgkqhkiG9w0BAQUFADBxMQswCQYDVQQGEwJD 3 | TjELMAkGA1UECAwCR0QxCzAJBgNVBAcMAlNaMQwwCgYDVQQKDANDT00xDDAKBgNV 4 | BAsMA05TUDELMAkGA1UEAwwCQ0ExHzAdBgkqhkiG9w0BCQEWEDU2NDI2MzgyMEBx 5 | cS5jb20wHhcNMTgxMjAzMjE1NjUxWhcNMjgxMTMwMjE1NjUxWjB1MQswCQYDVQQG 6 | EwJDTjELMAkGA1UECAwCR0QxCzAJBgNVBAcMAlNaMQwwCgYDVQQKDANDT00xDDAK 7 | BgNVBAsMA05TUDEPMA0GA1UEAwwGU0VSVkVSMR8wHQYJKoZIhvcNAQkBFhA1NjQy 8 | NjM4MjBAcXEuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3Bfc 9 | mrIc19C7bOzZaA7Di/G8flWTk9spMK+7a6MoWgAnsWVRNgHT1H00fdMgfIDMFGnt 10 | OEyCphrqoOERQufqYiJ/ph6kNe1Ks1vAQsED/czptg5uyS20zKDXx1Ufzs7vINZI 11 | UGsTUf+6G3/SblrFhk9wfcZ9Vp/uuiOH19rVYZdjT0BlOeqAeKg7TorhN4GnAHCP 12 | kwOkiBXQkOePqMqP8rlj9oxuXeow8VC/mbzLzOjPcQXp6hKHqk55A8zU1C/3OECa 13 | DIj78/d4J4rLTO1BdJ4aN8st7up63CBfSpBhmAMxLND98HcK5upQCDjIrET82pNd 14 | SIVLEDYrY7GbcvBHSwIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQAFLk5eeI1V40Rr 15 | ldpvMbcbAOARHyRxyThogBF2p6r7NQsAigXH1oFFulYtrREcYI4hlezxtT/TemhM 16 | SQORMjR8Om+Xnu6iTWT+PLYllDAE7Kvx+pgfiflHtVKG4BtgUAD26PAS5+Uk8Mul 17 | qPmu34HBziJS2Vwv5nkcNe/sJJtVstNXDyqRVm+0NQQ1izxDSThEY2NSyw0bvAGh 18 | sFVDCK25hsEmbdDgFCnuCzqnQondW4usfamCuMclGLn/FxtwSWZ6gvA5hylVbiP+ 19 | d8sjXRui7lOvj0HORPx+dLsLx3tUqfJ1x7v4ead3t+e/9KygiqQuFW6j3g34ZHsj 20 | 7VD7fPhK 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/server-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQI4vvHgg33g3cCAggA 3 | MBQGCCqGSIb3DQMHBAidPFSisCLjTASCBMgHR06Jz+25y3enbb/QEyXBDw+EgD1B 4 | lU8vv9v95hg15k8DtqyCd47FOr0wjaXMY4wsI2Bw7J+kZMNrb3RHq1QxmRiOOAXa 5 | DPNSJWwGN5jX2Oty343Nc1bvWyoFtEWRabJeZzSBEypWUMbSiBWfTrZO4W9s3r8j 6 | OkF8F4y/PZKSO8NSzajFrc4saJ6AjopIgHhf3TPFB8AJgTesodH7U/TNrIieuJ7b 7 | vBExILmEsTtqunf6JGThH6rkVe1BByFRN5dF1mVIdC5NVQmmdxih3J6GIEiE1BWq 8 | 4HQoLYAplCIw4J3GIYXjpMo5Y4aJTTTvlg+7u9UTAzUG9GZuQMvIAFGK7lVSlTdM 9 | 6QHvxrKxwdPa+jzErMGiLjH5PzO19C8bHvqlCP+Zy4shrZSUuZZ9/d6LwlCK3lGP 10 | tS6nnZF4iyyVx2iW5aHiupneyVSng/8UN3lGAVdc7cLp3qTz0VyoSTpFaOp1fCUL 11 | t/FdBhIoGQ+iN8p3iRvGAestNXA8uIHegsl7qNqrGlME2hlNgvEDfrqXGXyQhVW9 12 | 0Ax+ApRB5isPGwcelUYZgwKPu+fGnj1ocJlivrOd0Pb/Cry8HUE9m9NUp3L/13vF 13 | uanTFH/VrASaZXe8DiXmWNhWTz7Q7uTyTkSUUgcS5hF+/nVwJBaN/+/Bno50o//p 14 | kYlqCAJVCqSifXGnWJC9+RVZ1wLYybOQgt2fk6MYhdBNxARX4bzL6kOryrkZ4I5L 15 | 9RmPLugxt2hNcFUayx54Z3bwt46WHHUNFUnV9gsJ2AWxRnEnhvTvUpXrwI5SkSrC 16 | gNvJlV4V1IFncc6eHFj0ukkhylwF3sh+H7WDeRdRY0yVqs5ynVAzAhlahIIjmPbv 17 | nRKNwIqPBIhod2h2AjtMMl0trqmBnzrk//q1yHi5ws/A3RrLsrwtafkKU/QyinAy 18 | GiyDu6sgjwSq5OrehSPhntH67RCF2h70MUBOmR1bjWJRSRwOAkUGxME3RfwgmCPi 19 | BxJ4Q8xW7jEnaNFpl3wATQUyxZdsDXmDLZES84v7uG4Wqpf8SQoTlhqLa++R7Og9 20 | osy+exUKVN5S8eUseFcXTkw1U/wcAUwPjiV1s5Jlfe0lKNhJf/4t3V6LzZYpEvbc 21 | GUU5iDLAiUz+WnDp9oKWwLwY2EVWXU75PLzhFjE5jPY7MF4tG1m21qHSXYzyihbT 22 | hOc6j4u37jw95dTTRrhXsSSbRiD3EyO23FIFXEhWDDhaQEtup6akRjxBzdwGpxhp 23 | sQUe2CIBcmu2C4047jJfwsLCyV8v+biH8Wt7H+RI73wZrLca+1TBw7kbrs0X2yn2 24 | 69eTvTU/0UEFf90fmOY3FVOLTG4EoWXkymqmBFTLViFsKTZiZlpJhKqAz8hkfdHq 25 | NuQdxcGGV0D3F+DTZGJ8V1x5kf2jayhRNpy5aaCVfaKBhCs/Rl7dJgmGjio3m0j4 26 | 2UeXac3teQGfdttH56bi/P1O9J9/q63OihIKZ8nBPuPrT7Yf6Inpx/OcgFpUZuqF 27 | SqzUQ2TkrVKbRHL/7qd1vERGqHeBmgpq1HZjgpwtZvdvCUexAXajRiV2awEcU9WY 28 | dlltkmsNuWqocfNqzv27ZwE8v5dU+XDbwHqgRyelwQp/JH7gGPeeXdE8haLFbRlt 29 | m2U= 30 | -----END ENCRYPTED PRIVATE KEY----- 31 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/server-req.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICujCCAaICAQAwdTELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkdEMQswCQYDVQQH 3 | DAJTWjEMMAoGA1UECgwDQ09NMQwwCgYDVQQLDANOU1AxDzANBgNVBAMMBlNFUlZF 4 | UjEfMB0GCSqGSIb3DQEJARYQNTY0MjYzODIwQHFxLmNvbTCCASIwDQYJKoZIhvcN 5 | AQEBBQADggEPADCCAQoCggEBANwX3JqyHNfQu2zs2WgOw4vxvH5Vk5PbKTCvu2uj 6 | KFoAJ7FlUTYB09R9NH3TIHyAzBRp7ThMgqYa6qDhEULn6mIif6YepDXtSrNbwELB 7 | A/3M6bYObskttMyg18dVH87O7yDWSFBrE1H/uht/0m5axYZPcH3GfVaf7rojh9fa 8 | 1WGXY09AZTnqgHioO06K4TeBpwBwj5MDpIgV0JDnj6jKj/K5Y/aMbl3qMPFQv5m8 9 | y8zoz3EF6eoSh6pOeQPM1NQv9zhAmgyI+/P3eCeKy0ztQXSeGjfLLe7qetwgX0qQ 10 | YZgDMSzQ/fB3CubqUAg4yKxE/NqTXUiFSxA2K2Oxm3LwR0sCAwEAAaAAMA0GCSqG 11 | SIb3DQEBBQUAA4IBAQDJnkTF8SW9zHXZheLLBm4UErpVUT7rOLha9OkU+q8gopTw 12 | VHzilkwlxjJiazbTdd7YYpdZA+/CcCDyIdhWYe+DU+a50RND6WTE3GBte53S1Hj0 13 | U86SMHTKmiIH6ZB9N9jPzEZ9yjqKavk4/rtfnZ8lRjzq3QuNEEwQmQgOhkNMgII9 14 | fLEn8HgAkh0suAqgq6EwsaXMbud5s4DY6jbB16/Nnd+yHnGZEiGkBeSZ0mEr834R 15 | RDR8GXaGYFP+RHQoY/QZzjmYKsCZN8mTJTPWq9aG+0dAXv2eoieYT96dGRo3eLHd 16 | XjNC+ADmxpRje3o/2IM53Rixe+KR/et2SX9Pa9J8 17 | -----END CERTIFICATE REQUEST----- 18 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/server.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/server.jks -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/server.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/server.p12 -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/server_rsa.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cxks1/lzgyy/98a8923d755b29d108578306285a224dfc76075c/lzgyy-plugins/lzgyy-iot-service/src/main/resources/keystore/server_rsa.cer -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/证书/参考/keytool生成证书: -------------------------------------------------------------------------------- 1 | 1)生成服务端证书 2 | 为服务器生成自签名证书 3 | keytool -genkey -alias securechat -keysize 2048 -validity 365 -keyalg RSA -dname "CN=localhost" -keypass sNetty -storepass sNetty -keystore sChat.jks 4 | 5 | keytool -export -alias securechat -keystore sChat.jks -storepass sNetty -file sChat.cer 6 | 7 | 2)生成客户端证书 8 | keytool -genkey -alias smcc -keysize 2048 -validity 365 -keyalg RSA -dname "CN=localhost" -keypass cNetty -storepass cNetty -keystore cChat.jks 9 | 10 | keytool -import -trustcacerts -alias securechat -file ../server\sChat.cer -storepass cNetty -keystore cChat.jks 11 | 12 | 所有者: CN=localhost 13 | 发布者: CN=localhost -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/证书/参考/openssl 根证书 服务器证书 客户端证书: -------------------------------------------------------------------------------- 1 | 1、生成根证书,生成两个文件 root.key 和root.crt文件 2 | 用于签名服务器端证书和客户端证书 3 | openssl req -new -x509 -nodes -days 3650 -newkey rsa:2048 -keyout ${PATH}/lzgyy_root.key -out ${PATH}/lzgyy_root.crt -config /etc/pki/tls/openssl.cnf 4 | 5 | 2、为服务器证书生成私钥文件 6 | openssl genrsa -out ${PATH}lzgyy_server.key 2048 7 | 8 | 3、为服务器证书生成CSR证书签名请求 9 | openssl req -new -key ${PATH}/lzgyy_server.key -out ${PATH}/lzgyy_server.csr -config /etc/pki/tls/openssl.cnf 10 | 11 | 4、使用根证书签名服务器CSR,生成服务器证书。 12 | openssl ca -in ${PATH}/lzgyy_server.csr -out ${PATH}/lzgyy_server.crt -cert ${PATH}/lzgyy_root.crt -keyfile ${PATH}/lzgyy_root.key -config /etc/pki/tls/openssl.cnf 13 | 14 | 5、为用户张三生成私钥 15 | openssl genrsa -out ${PATH}/zhangsan.key 2048 16 | 17 | 6、为用户张三生成证书签名请求 18 | openssl req -new -utf8 -key ${PATH}/lzgyy_zhangsan.key -out ${PATH}/lzgyy_zhangsan.csr -config /etc/pki/tls/openssl.cnf 19 | 20 | 7、使用根证书签名张三CSR 21 | openssl ca -in ${PATH}/lzgyy_zhangsan.csr -out ${PATH}/lzgyy_zhangsan.crt -cert ${PATH}/lzgyy_root.crt -keyfile ${PATH}/lzgyy_root.key -config /etc/pki/tls/openssl.cnf 22 | 23 | 将用户张三的公钥和私钥导出为p12格式证书,并启用私钥密码保护。 24 | openssl pkcs12 -export -in /etc/nginx/ssl/zhangsan.crt -inkey /etc/nginx/ssl/zhangsan.key -out /etc/nginx/ssl/zhangsan.p12 25 | Enter Export Password: 26 | Verifying - Enter Export Password: -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/证书/参考/关于证书: -------------------------------------------------------------------------------- 1 | 关于证书 2 | 1、每个人都可以使用一些证书生成工具为自己的https站点生成证书(比如jdk的keytool),大家称它为“自签名证书”,但是自己生成的证书是不被互联网承认的,所以浏览器会报安全提示,要求你手动安装证书。只有通过权威的CA机构付费获得的证书才能被互联网承认(有点类似于根域服务器的权威机构)。 3 | 2、证书(无客户端服务端之分)保存着ip信息、证书过期时间、证书所有者地址信息等。 4 | 5 | 双向认证 6 |   1、先决条件是有两个或两个以上的证书,一个是服务端证书,另一个或多个是客户端证书。 7 |   2、服务端保存着客户端的证书并信任该证书,客户端保存着服务端的证书并信任该证书。这样,在证书验证成功的情况下即可完成请求响应。 8 |   3、双向认证一般企业应用对接。 9 | 10 | 单向认证 11 |   1、客户端保存着服务端的证书并信任该证书即可 12 |   2、https一般是单向认证,这样可以让绝大部分人都可以访问你的站点。 -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-iot-service/证书/证书格式: -------------------------------------------------------------------------------- 1 | #密钥库文件格式[keystore]代码 2 | 格式 : JKS 3 | 扩展名 : .jks/.ks 4 | 描述 : [Java Keystore]密钥库的Java实现版本,provider为SUN 5 | 特点 : 密钥库和私钥用不同的密码进行保护 6 | 7 | 格式 : JCEKS 8 | 扩展名 : .jce 9 | 描述 : [JCE Keystore]密钥库的JCE实现版本,provider为SUN JCE 10 | 特点 : 相对于JKS安全级别更高,保护Keystore私钥时采用TripleDES 11 | 12 | 格式 : PKCS12 13 | 扩展名 : .p12/.pfx 14 | 描述 : [PKCS #12]个人信息交换语法标准 15 | 特点 : 1、包含私钥、公钥及其证书 16 | 2、密钥库和私钥用相同密码进行保护 17 | 18 | 格式 : BKS 19 | 扩展名 : .bks 20 | 描述 : Bouncycastle Keystore]密钥库的BC实现版本,provider为BC 21 | 特点 : 基于JCE实现 22 | 23 | 格式 : UBER 24 | 扩展名 : .ubr 25 | 描述 : [Bouncycastle UBER Keystore]密钥库的BC更安全实现版本,provider为BC 26 | 27 | #证书文件格式[certificate]代码 28 | 格式 : DER 29 | 扩展名 : .cer/.crt/.rsa 30 | 描述 : [ASN .1 DER]用于存放证书 31 | 特点 : 不含私钥、二进制 32 | 33 | 格式 : PKCS7 34 | 扩展名 : .p7b/.p7r 35 | 描述 : [PKCS #7]加密信息语法标准 36 | 特点 : 1、p7b以树状展示证书链,不含私钥 37 | 2、p7r为CA对证书请求签名的回复,只能用于导入 38 | 39 | 格式 : CMS 40 | 扩展名 : .p7c/.p7m/.p7s 41 | 描述 : [Cryptographic Message Syntax] 42 | 特点 : 1、p7c只保存证书 43 | 2、p7m:signature with enveloped data 44 | 3、p7s:时间戳签名文件 45 | 46 | 格式 : PEM 47 | 扩展名 : .pem 48 | 描述 : [Printable Encoded Message] 49 | 特点 : 1、该编码格式在RFC1421中定义,其实PEM是[Privacy-Enhanced Mail]的简写,但他也同样广泛运用于密钥管理 50 | 2、ASCII文件 51 | 3、一般基于base 64编码 52 | 53 | 格式 : PKCS10 54 | 扩展名 : .p10/.csr 55 | 描述 : [PKCS #10]公钥加密标准[Certificate Signing Request] 56 | 特点 : 1、证书签名请求文件 57 | 2、ASCII文件 58 | 3、CA签名后以p7r文件回复 59 | 60 | 格式 : SPC 61 | 扩展名 : .pvk/.spc 62 | 描述 : [Software Publishing Certificate] 63 | 特点 : 微软公司特有的双证书文件格式,经常用于代码签名,其中 64 | 1、pvk用于保存私钥 65 | 2、spc用于保存公钥 -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-quartz-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-quartz-plugin/db/job_entity.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-30 16:08:47 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for job_entity 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `job_entity`; 22 | CREATE TABLE `job_entity` ( 23 | `id` bigint(40) NOT NULL COMMENT 'job主键', 24 | `name` varchar(255) DEFAULT NULL COMMENT 'job名称', 25 | `group` varchar(255) DEFAULT NULL COMMENT 'job组名', 26 | `cron` varchar(255) DEFAULT NULL COMMENT '执行的cron', 27 | `parameter` varchar(255) DEFAULT NULL COMMENT 'job的参数', 28 | `description` varchar(255) DEFAULT NULL COMMENT 'job描述信息', 29 | `vm_param` varchar(255) DEFAULT NULL COMMENT 'vm参数', 30 | `jar_path` varchar(255) DEFAULT NULL COMMENT 'job的jar路径', 31 | `status` varchar(80) DEFAULT NULL COMMENT 'job的执行状态,这里我设置为OPEN/CLOSE且只有该值为OPEN才会执行该Job', 32 | PRIMARY KEY (`id`) 33 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 34 | 35 | -- ---------------------------- 36 | -- Records of job_entity 37 | -- ---------------------------- 38 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-quartz-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.lzgyy 6 | lzgyy-plugins 7 | 0.0.1-SNAPSHOT 8 | 9 | lzgyy-quartz-plugin 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-web 14 | 15 | 16 | org.springframework 17 | spring-context-support 18 | 19 | 20 | com.lzgyy 21 | lzgyy-core 22 | 0.0.1-SNAPSHOT 23 | 24 | 25 | 26 | org.projectlombok 27 | lombok 28 | provided 29 | 30 | 31 | 32 | org.quartz-scheduler 33 | quartz 34 | 35 | 36 | org.quartz-scheduler 37 | quartz-jobs 38 | 39 | 40 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-quartz-plugin/src/main/java/com/lzgyy/plugins/quartz/entity/JobEntity.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.quartz.entity; 2 | import java.io.Serializable; 3 | 4 | import lombok.Data; 5 | 6 | @Data 7 | public class JobEntity implements Serializable { 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | /* job主键 */ 12 | private Long id; 13 | /* job名称 */ 14 | private String name; 15 | /* job组名 */ 16 | private String group; 17 | /* 执行的cron */ 18 | private String cron; 19 | /* job的参数 */ 20 | private String parameter; 21 | /* job描述信息 */ 22 | private String description; 23 | /* vm参数 */ 24 | private String vmParam; 25 | /* job的jar路径 */ 26 | private String jarPath; 27 | /* job的执行状态,这里我设置为OPEN/CLOSE且只有该值为OPEN才会执行该Job */ 28 | private String status; 29 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-quartz-plugin/src/main/java/com/lzgyy/plugins/quartz/mapper/JobMapper.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.quartz.mapper; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.lzgyy.plugins.quartz.entity.JobEntity; 7 | 8 | public interface JobMapper{ 9 | 10 | int insert(JobEntity test); 11 | 12 | int update(JobEntity test); 13 | 14 | List getList(Map paramMap); 15 | 16 | int getTotal(Map paramMap); 17 | 18 | int deleteIds(List idsList); 19 | 20 | int deleteIdsPhysical(List idsList); 21 | 22 | int updateIdsRestore(List idsList); 23 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-quartz-plugin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | ########### Quartz调度中心 ########## 2 | quartz: 3 | enabled: true 4 | server: 5 | port: 9090 6 | spring: 7 | application: 8 | name: Spring-Quartz-Scheduler 9 | datasource: 10 | url: jdbc:mysql://localhost:3306/yourdatabase 11 | username: yourname 12 | password: yourpass 13 | tomcat: 14 | initialSize: 20 15 | maxActive: 100 16 | maxIdle: 100 17 | minIdle: 20 18 | maxWait: 10000 19 | testWhileIdle: true 20 | testOnBorrow: false 21 | testOnReturn: false 22 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-quartz-plugin/src/main/resources/quartz.properties: -------------------------------------------------------------------------------- 1 | #ID\u8bbe\u7f6e\u4e3a\u81ea\u52a8\u83b7\u53d6 \u6bcf\u4e00\u4e2a\u5fc5\u987b\u4e0d\u540c \uff08\u6240\u6709\u8c03\u5ea6\u5668\u5b9e\u4f8b\u4e2d\u662f\u552f\u4e00\u7684\uff09 2 | org.quartz.scheduler.instanceId=AUTO 3 | #\u6307\u5b9a\u8c03\u5ea6\u7a0b\u5e8f\u7684\u4e3b\u7ebf\u7a0b\u662f\u5426\u5e94\u8be5\u662f\u5b88\u62a4\u7ebf\u7a0b 4 | org.quartz.scheduler.makeSchedulerThreadDaemon=true 5 | #ThreadPool\u5b9e\u73b0\u7684\u7c7b\u540d 6 | org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool 7 | #ThreadPool\u914d\u7f6e\u7ebf\u7a0b\u5b88\u62a4\u8fdb\u7a0b 8 | org.quartz.threadPool.makeThreadsDaemons=true 9 | #\u7ebf\u7a0b\u6570\u91cf 10 | org.quartz.threadPool.threadCount:20 11 | #\u7ebf\u7a0b\u4f18\u5148\u7ea7 12 | org.quartz.threadPool.threadPriority:5 13 | #\u6570\u636e\u4fdd\u5b58\u65b9\u5f0f\u4e3a\u6301\u4e45\u5316 14 | org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX 15 | #StdJDBCDelegate\u8bf4\u660e\u652f\u6301\u96c6\u7fa4 16 | org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate 17 | #quartz\u5185\u90e8\u8868\u7684\u524d\u7f00 18 | org.quartz.jobStore.tablePrefix=QRTZ_ 19 | #\u662f\u5426\u52a0\u5165\u96c6\u7fa4 20 | org.quartz.jobStore.isClustered=true 21 | #\u5bb9\u8bb8\u7684\u6700\u5927\u4f5c\u4e1a\u5ef6\u957f\u65f6\u95f4 22 | org.quartz.jobStore.misfireThreshold=25000 -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-redis-interf/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-redis-interf/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.lzgyy 6 | lzgyy-plugins 7 | 0.0.1-SNAPSHOT 8 | 9 | lzgyy-redis-interf 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-data-redis 14 | 15 | 16 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-redis-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-redis-service/src/main/java/com/lzgyy/plugins/redis/RedisServiceProviderApp.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.redis; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 8 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 9 | import org.springframework.context.annotation.Import; 10 | 11 | import com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan; 12 | import com.lzgyy.config.dubbo.provider.DubboProviderConfiguration; 13 | 14 | @SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) 15 | @Import({DubboProviderConfiguration.class}) 16 | @DubboComponentScan(basePackages="com.lzgyy.plugins.redis.service.impl") 17 | public class RedisServiceProviderApp { 18 | 19 | private static final Logger logger = LogManager.getLogger(RedisServiceProviderApp.class); 20 | 21 | public static void main( String[] args ) { 22 | logger.info("***** RedisServiceProviderApp starting ... "); 23 | SpringApplication.run(RedisServiceProviderApp.class, args); 24 | logger.info("***** RedisServiceProviderApp started "); 25 | } 26 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-redis-service/src/main/java/com/lzgyy/plugins/redis/config/RedisCacheConfig.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.redis.config; 2 | 3 | import org.springframework.cache.annotation.CachingConfigurerSupport; 4 | import org.springframework.cache.annotation.EnableCaching; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.data.redis.connection.RedisConnectionFactory; 8 | import org.springframework.data.redis.core.RedisTemplate; 9 | import org.springframework.data.redis.serializer.StringRedisSerializer; 10 | 11 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 12 | import com.fasterxml.jackson.annotation.PropertyAccessor; 13 | import com.fasterxml.jackson.databind.ObjectMapper; 14 | 15 | @Configuration 16 | @EnableCaching 17 | public class RedisCacheConfig extends CachingConfigurerSupport { 18 | 19 | @Bean 20 | public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { 21 | 22 | RedisTemplate redisTemplate = new RedisTemplate<>(); 23 | redisTemplate.setConnectionFactory(redisConnectionFactory); 24 | 25 | // 使用Jackson2JsonRedisSerializer 替换默认序列化 26 | RedisSerializerConfig redisSerializerConfig = new RedisSerializerConfig(); 27 | 28 | ObjectMapper objectMapper = new ObjectMapper(); 29 | objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC); 30 | objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); 31 | 32 | // 设置value的序列化规则和 key的序列化规则 33 | redisTemplate.setValueSerializer(redisSerializerConfig); 34 | redisTemplate.setDefaultSerializer(redisSerializerConfig); 35 | redisTemplate.setHashKeySerializer(new StringRedisSerializer()); 36 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 37 | redisTemplate.afterPropertiesSet(); 38 | return redisTemplate; 39 | } 40 | } -------------------------------------------------------------------------------- /lzgyy-plugins/lzgyy-redis-service/src/main/java/com/lzgyy/plugins/redis/config/RedisSerializerConfig.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.plugins.redis.config; 2 | 3 | import org.springframework.data.redis.serializer.RedisSerializer; 4 | import org.springframework.data.redis.serializer.SerializationException; 5 | 6 | import com.alibaba.fastjson.JSONArray; 7 | import com.alibaba.fastjson.parser.Feature; 8 | import com.alibaba.fastjson.serializer.SerializerFeature; 9 | 10 | public class RedisSerializerConfig implements RedisSerializer{ 11 | 12 | 13 | @Override 14 | public byte[] serialize(T t) throws SerializationException { 15 | if(null == t) { 16 | return new byte[0]; 17 | } 18 | return JSONArray.toJSONBytes(t,SerializerFeature.PrettyFormat, 19 | SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty, 20 | SerializerFeature.DisableCircularReferenceDetect, 21 | SerializerFeature.WriteNullListAsEmpty); 22 | } 23 | 24 | @Override 25 | public T deserialize(byte[] bytes) throws SerializationException { 26 | 27 | if(null == bytes || bytes.length == 0) { 28 | return null; 29 | } 30 | Object obj = JSONArray.parse(bytes, Feature.AllowUnQuotedFieldNames, Feature.AllowISO8601DateFormat, Feature.CustomMapDeserializer); 31 | 32 | return (T) obj ; 33 | } 34 | } -------------------------------------------------------------------------------- /lzgyy-plugins/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.lzgyy 5 | lzgyy 6 | 0.0.1-SNAPSHOT 7 | 8 | lzgyy-plugins 9 | pom 10 | 11 | lzgyy-quartz-plugin 12 | lzgyy-elasticsearch-plugin 13 | lzgyy-redis-interf 14 | lzgyy-redis-service 15 | lzgyy-iot-core 16 | lzgyy-iot-client 17 | lzgyy-iot-service 18 | 19 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-api/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.lzgyy 5 | lzgyy-products 6 | 0.0.1-SNAPSHOT 7 | 8 | lzgyy-platform-api 9 | 10 | 11 | com.lzgyy 12 | lzgyy-swagger-config 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | com.lzgyy 17 | lzgyy-platform-interf 18 | 0.0.1-SNAPSHOT 19 | 20 | 21 | 22 | org.slf4j 23 | log4j-over-slf4j 24 | 25 | 26 | 27 | org.apache.zookeeper 28 | zookeeper 29 | 30 | 31 | com.101tec 32 | zkclient 33 | 34 | 35 | org.apache.curator 36 | curator-framework 37 | 38 | 39 | org.apache.curator 40 | curator-recipes 41 | 42 | 43 | 44 | 45 | com.esotericsoftware.kryo 46 | kryo 47 | 48 | 49 | de.javakaffee 50 | kryo-serializers 51 | 52 | 53 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-api/src/main/java/com/lzgyy/platform/PlatformApiConsumerApp.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.platform; 2 | 3 | import java.util.TimeZone; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 10 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 11 | import org.springframework.boot.builder.SpringApplicationBuilder; 12 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 13 | import org.springframework.context.annotation.ComponentScan; 14 | import org.springframework.context.annotation.ImportResource; 15 | 16 | import com.lzgyy.core.io.PropertiesConfig; 17 | import com.lzgyy.core.utils.PropertiesUtil; 18 | 19 | 20 | @SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) 21 | // 扫描包 22 | @ComponentScan(basePackages={"com.lzgyy.config","com.lzgyy.platform"}) 23 | // 加载插件 24 | @ImportResource(locations={"classpath:applicationContext-plug.xml"}) 25 | public class PlatformApiConsumerApp extends SpringBootServletInitializer{ 26 | 27 | private static final Logger logger = LoggerFactory.getLogger(PlatformApiConsumerApp.class); 28 | 29 | // 默认加载的文件,可通过继承覆盖(若有相同Key,优先加载后面的) 30 | public static final String[] DEFAULT_CONFIG_FILE = new String[]{"classpath:config/application.yml"}; 31 | 32 | public static void main(String[] args) { 33 | logger.info("***** PlatformApiConsumerApp starting"); 34 | System.setProperty("user.timezone","Asia/Shanghai"); //设置时区 35 | TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); 36 | SpringApplication app = new SpringApplication(PlatformApiConsumerApp.class); 37 | PropertiesConfig propertiesConfig = new PropertiesConfig(DEFAULT_CONFIG_FILE); 38 | app.setDefaultProperties(propertiesConfig.getProperties()); 39 | PropertiesUtil.setPropertiesConfig(propertiesConfig); // 设置配置文件工具类 40 | app.run(args); 41 | logger.info("***** PlatformApiConsumerApp started"); 42 | } 43 | 44 | @Override 45 | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 46 | this.setRegisterErrorPageFilter(false); // 错误页面由容器来处理,而不是SpringBoot 47 | PropertiesConfig propertiesConfig = new PropertiesConfig(DEFAULT_CONFIG_FILE); 48 | builder.properties(propertiesConfig.getProperties()); 49 | PropertiesUtil.setPropertiesConfig(propertiesConfig); // 设置配置文件工具类 50 | return builder.sources(PlatformApiConsumerApp.class); 51 | } 52 | } -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-api/src/main/resources/applicationContext-plug.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | applicationContext文件插件列表 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-api/src/main/resources/config/application-dev.yml: -------------------------------------------------------------------------------- 1 | ########### 开发环境 ########## 2 | # tomcat 3 | server : 4 | port : 9999 5 | tomcat : 6 | min-spare-threads : 30 7 | max-threads : 800 8 | connection-timeout : 5000 9 | uri-encoding : UTF-8 10 | 11 | # dubbo 12 | dubbo : 13 | port : 20992 14 | applicationName : lzgyy-platform-api 15 | registry : 16 | address : zookeeper://192.168.0.114:2181 17 | timeout : 60000 18 | 19 | # spring 20 | spring: 21 | application: 22 | name : lzgyy-platform 23 | http : 24 | encoding : 25 | charset : UTF-8 26 | enabled : true 27 | force : true 28 | messages : 29 | encoding : UTF-8 30 | 31 | # logging 32 | logging : 33 | level : 34 | com : 35 | evisible : 36 | blockchain : 37 | dealfee : DEBUG 38 | 39 | # banner 40 | banner : 41 | charset : UTF-8 42 | location : classpath:config/banner.txt -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-api/src/main/resources/config/application.yml: -------------------------------------------------------------------------------- 1 | # 多环境配置 2 | spring : 3 | profiles : 4 | active : dev -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-api/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, DEBUG, console, file 2 | 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.console.layout.ConversionPattern=%d %p [%c] - %m%n 6 | 7 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 8 | #log4j.appender.file.File=logs/lzgyy-platform-web.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d %p [%c] - %m%n 11 | 12 | log4j.logger.org.springframework=DEBUG 13 | 14 | #log4j.logger.com.ibatis = debug 15 | #log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = debug 16 | #log4j.logger.com.ibatis.common.jdbc.ScriptRunner = debug 17 | #log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = debug 18 | #log4j.logger.java.sql.Connection = debug 19 | log4j.logger.java.sql.Statement = debug 20 | log4j.logger.java.sql.PreparedStatement = debug 21 | log4j.logger.java.sql.ResultSet =debug 22 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-api/src/main/resources/spring/dubbo-consumer.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-interf/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-interf/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.lzgyy 5 | lzgyy-products 6 | 0.0.1-SNAPSHOT 7 | 8 | lzgyy-platform-interf 9 | 10 | 11 | com.lzgyy 12 | lzgyy-core 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | com.alibaba 18 | fastjson 19 | 20 | 21 | 22 | com.alibaba 23 | dubbo 24 | 25 | 26 | 27 | javax.ws.rs 28 | javax.ws.rs-api 29 | 30 | 31 | 32 | org.projectlombok 33 | lombok 34 | provided 35 | 36 | 37 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-interf/src/main/java/com/lzgyy/platform/modules/demo/service/DemoService.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.platform.modules.demo.service; 2 | 3 | import java.util.List; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import com.alibaba.fastjson.JSONObject; 7 | 8 | public interface DemoService { 9 | 10 | JSONObject get(Integer id, HttpServletRequest request) throws Exception; 11 | 12 | JSONObject getById(Integer id) throws Exception; 13 | 14 | List getByName(String name) throws Exception; 15 | 16 | List getList(JSONObject jsonParam) throws Exception; 17 | 18 | int getTotal(JSONObject jsonParam) throws Exception; 19 | 20 | int insert(JSONObject jsonObject) throws Exception; 21 | 22 | int update(JSONObject json) throws Exception; 23 | 24 | int delete(Integer id) throws Exception; 25 | 26 | int deletePhysical(List idsList) throws Exception; 27 | } -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-interf/src/main/java/com/lzgyy/platform/modules/test/entity/Test.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.platform.modules.test.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | @Data /** @ToString, @EqualsAndHashCode, 所有属性的@Getter, 所有non-final属性的@Setter和@RequiredArgsConstructor的组合,通常情况下,我们使用这个注解就足够了 */ 11 | //@AllArgsConstructor /** 全参构造器 */ 12 | //@NoArgsConstructor /** 无参构造器 */ 13 | public class Test implements Serializable{ 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | /** 主键 **/ 18 | private Long id; 19 | /** 名称 **/ 20 | private String name; 21 | /** 创建人 **/ 22 | private Long createUser; 23 | /** 创建时间 **/ 24 | private Date createDate; 25 | /** 更新人 **/ 26 | private Long updateUser; 27 | /** 更新时间 **/ 28 | private Date updateDate; 29 | /** 删除标识 **/ 30 | private String deleteState; 31 | 32 | } -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-interf/src/main/java/com/lzgyy/platform/modules/test/service/TestService.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.platform.modules.test.service; 2 | 3 | import java.util.List; 4 | 5 | import com.lzgyy.core.entity.PageQuery; 6 | import com.lzgyy.platform.modules.test.entity.Test; 7 | 8 | public interface TestService { 9 | 10 | Test get(Long id) throws Exception; 11 | 12 | Test getById(Long id) throws Exception; 13 | 14 | List getByName(String name) throws Exception; 15 | 16 | List getList(PageQuery pageQuery) throws Exception; 17 | 18 | List getList2(Test test, Integer startPage, Integer limitSize) throws Exception; 19 | 20 | int getTotal(Test test) throws Exception; 21 | 22 | int insert(Test test) throws Exception; 23 | 24 | int update(Test test) throws Exception; 25 | 26 | int deleteIds(List idsList) throws Exception; 27 | 28 | int deletePhysical(List idsList) throws Exception; 29 | 30 | int updateIdsRestore(List idsList) throws Exception; 31 | 32 | } -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-interf/src/main/java/com/lzgyy/platform/serial/SerializationOptimizerImpl.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.platform.serial; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | 7 | import com.alibaba.dubbo.common.serialize.support.SerializationOptimizer; 8 | import com.alibaba.fastjson.JSONObject; 9 | 10 | public class SerializationOptimizerImpl implements SerializationOptimizer{ 11 | 12 | public Collection getSerializableClasses() { 13 | List classes = new LinkedList(); 14 | //这里可以把所有需要进行序列化的类进行添加 15 | classes.add(JSONObject.class); 16 | return classes; 17 | } 18 | } -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/java/com/lzgyy/platform/PlatformServiceProviderApp.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.platform; 2 | 3 | import java.util.TimeZone; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.builder.SpringApplicationBuilder; 10 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 11 | import org.springframework.context.annotation.ComponentScan; 12 | import org.springframework.context.annotation.ImportResource; 13 | 14 | import com.lzgyy.core.io.PropertiesConfig; 15 | import com.lzgyy.core.utils.PropertiesUtil; 16 | 17 | 18 | @SpringBootApplication 19 | // 扫描包 20 | @ComponentScan(basePackages={"com.lzgyy.platform"}) 21 | // 加载插件 22 | @ImportResource(locations={"classpath:applicationContext-plug.xml"}) 23 | public class PlatformServiceProviderApp extends SpringBootServletInitializer{ 24 | 25 | private static final Logger logger = LoggerFactory.getLogger(PlatformServiceProviderApp.class); 26 | 27 | // 默认加载的文件,可通过继承覆盖(若有相同Key,优先加载后面的) 28 | public static final String[] DEFAULT_CONFIG_FILE = new String[]{"classpath:config/application.yml"}; 29 | 30 | public static void main(String[] args) { 31 | logger.info("***** PlatformServiceProviderApp starting"); 32 | System.setProperty("user.timezone","Asia/Shanghai"); //设置时区 33 | TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); 34 | SpringApplication app = new SpringApplication(PlatformServiceProviderApp.class); 35 | PropertiesConfig propertiesConfig = new PropertiesConfig(DEFAULT_CONFIG_FILE); 36 | app.setDefaultProperties(propertiesConfig.getProperties()); 37 | PropertiesUtil.setPropertiesConfig(propertiesConfig); // 设置配置文件工具类 38 | app.run(args); 39 | logger.info("***** PlatformServiceProviderApp started"); 40 | } 41 | 42 | @Override 43 | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 44 | this.setRegisterErrorPageFilter(false); // 错误页面由容器来处理,而不是SpringBoot 45 | PropertiesConfig propertiesConfig = new PropertiesConfig(DEFAULT_CONFIG_FILE); 46 | builder.properties(propertiesConfig.getProperties()); 47 | PropertiesUtil.setPropertiesConfig(propertiesConfig); // 设置配置文件工具类 48 | return builder.sources(PlatformServiceProviderApp.class); 49 | } 50 | } -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/java/com/lzgyy/platform/modules/test/mapper/TestMapper.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.platform.modules.test.mapper; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.lzgyy.platform.modules.test.entity.Test; 7 | 8 | public interface TestMapper { 9 | 10 | int insert(Test test); 11 | 12 | int update(Test test); 13 | 14 | List getList(Map paramMap); 15 | 16 | int getTotal(Map paramMap); 17 | 18 | int deleteIds(List idsList); 19 | 20 | int deleteIdsPhysical(List idsList); 21 | 22 | int updateIdsRestore(List idsList); 23 | } 24 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/resources/applicationContext-plug.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | applicationContext文件插件列表 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/resources/config/application-dev.yml: -------------------------------------------------------------------------------- 1 | ########### 开发环境 ########## 2 | # tomcat 3 | server : 4 | port : 8888 5 | tomcat : 6 | min-spare-threads : 30 7 | max-threads : 800 8 | connection-timeout : 5000 9 | uri-encoding : UTF-8 10 | 11 | # dubbo 12 | dubbo : 13 | port : 20881 14 | applicationName : lzgyy-platform-service 15 | registry : 16 | address : zookeeper://192.168.0.114:2181 17 | rest : 18 | port : 8081 19 | server : tomcat 20 | contextpath : lzgyy-platform-service 21 | threads : 500 22 | accepts : 500 23 | 24 | # spring 25 | spring: 26 | application: 27 | name : lzgyy-platform 28 | datasource : 29 | type : com.alibaba.druid.pool.DruidDataSource 30 | url : jdbc:mysql://192.168.0.114:3306/lzgyy-platform?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=true 31 | username : root 32 | password : root 33 | driverClassName : com.mysql.jdbc.Driver 34 | initialSize : 5 35 | minIdle : 20 36 | maxActive : 200 37 | maxWait : 60000 38 | timeBetweenEvictionRunsMillis : 60000 39 | minEvictableIdleTimeMillis : 300000 40 | validationQuery : SELECT 1 FROM DUAL 41 | testWhileIdle : true 42 | testOnBorrow : false 43 | testOnReturn : false 44 | # 打开PSCache,并且指定每个连接上PSCache的大小 45 | poolPreparedStatements : true 46 | maxPoolPreparedStatementPerConnectionSize : 20 47 | # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 48 | filters : stat,wall,log4j 49 | # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 50 | connectionProperties : druid.stat.mergeSql=true;druid.stat.slowSqlMillis=3000 51 | # 合并多个DruidDataSource的监控数据 52 | #useGlobalDataSourceStat : true 53 | http : 54 | encoding : 55 | charset : UTF-8 56 | enabled : true 57 | force : true 58 | messages : 59 | encoding : UTF-8 60 | 61 | # logging 62 | logging : 63 | config : classpath:logback-spring.xml 64 | level : 65 | com : 66 | evisible : 67 | blockchain : 68 | orguser : DEBUG 69 | 70 | # banner 71 | banner : 72 | charset : UTF-8 73 | location : classpath:config/banner.txt 74 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/resources/config/application.yml: -------------------------------------------------------------------------------- 1 | # 多环境配置 2 | spring : 3 | profiles : 4 | active : dev 5 | #active : prod 6 | #active : test 7 | other : 8 | config : cache -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/resources/config/cache.yml: -------------------------------------------------------------------------------- 1 | #===============缓存配置=============== 2 | CACHE : 3 | PREFIX : PT_ -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/resources/mybatis/applicationContext-mybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | MyBatis配置 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/resources/mybatis/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/resources/spring/dubbo-provider.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 38 | 39 | 40 | 41 | 44 | 45 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-service/src/main/resources/spring/spring-tx.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-sso/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-sso/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.lzgyy 5 | lzgyy-products 6 | 0.0.1-SNAPSHOT 7 | 8 | lzgyy-platform-sso 9 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-web/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-web/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.lzgyy 6 | lzgyy-products 7 | 0.0.1-SNAPSHOT 8 | 9 | lzgyy-platform-web 10 | 11 | 12 | com.lzgyy 13 | lzgyy-platform-interf 14 | 0.0.1-SNAPSHOT 15 | 16 | 17 | 18 | org.slf4j 19 | log4j-over-slf4j 20 | 21 | 22 | 23 | org.apache.zookeeper 24 | zookeeper 25 | 26 | 27 | com.101tec 28 | zkclient 29 | 30 | 31 | org.apache.curator 32 | curator-framework 33 | 34 | 35 | org.apache.curator 36 | curator-recipes 37 | 38 | 39 | 40 | 41 | com.caucho 42 | hessian 43 | 44 | 45 | 46 | com.esotericsoftware.kryo 47 | kryo 48 | 49 | 50 | de.javakaffee 51 | kryo-serializers 52 | 53 | 54 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-web/src/main/java/com/lzgyy/platform/PlatformServiceConsumerApp.java: -------------------------------------------------------------------------------- 1 | package com.lzgyy.platform; 2 | 3 | import java.util.TimeZone; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 10 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 11 | import org.springframework.boot.builder.SpringApplicationBuilder; 12 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 13 | import org.springframework.context.annotation.ComponentScan; 14 | import org.springframework.context.annotation.ImportResource; 15 | 16 | import com.lzgyy.core.io.PropertiesConfig; 17 | import com.lzgyy.core.utils.PropertiesUtil; 18 | 19 | 20 | @SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) 21 | // 扫描包 22 | @ComponentScan(basePackages={"com.lzgyy.platform"}) 23 | // 加载插件 24 | @ImportResource(locations={"classpath:applicationContext-plug.xml"}) 25 | public class PlatformServiceConsumerApp extends SpringBootServletInitializer{ 26 | 27 | private static final Logger logger = LoggerFactory.getLogger(PlatformServiceConsumerApp.class); 28 | 29 | // 默认加载的文件,可通过继承覆盖(若有相同Key,优先加载后面的) 30 | public static final String[] DEFAULT_CONFIG_FILE = new String[]{"classpath:config/application.yml"}; 31 | 32 | public static void main(String[] args) { 33 | logger.info("***** PlatformServiceConsumerApp starting"); 34 | System.setProperty("user.timezone","Asia/Shanghai"); //设置时区 35 | TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); 36 | SpringApplication app = new SpringApplication(PlatformServiceConsumerApp.class); 37 | PropertiesConfig propertiesConfig = new PropertiesConfig(DEFAULT_CONFIG_FILE); 38 | app.setDefaultProperties(propertiesConfig.getProperties()); 39 | PropertiesUtil.setPropertiesConfig(propertiesConfig); // 设置配置文件工具类 40 | app.run(args); 41 | logger.info("***** PlatformServiceConsumerApp started"); 42 | } 43 | 44 | @Override 45 | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 46 | this.setRegisterErrorPageFilter(false); // 错误页面由容器来处理,而不是SpringBoot 47 | PropertiesConfig propertiesConfig = new PropertiesConfig(DEFAULT_CONFIG_FILE); 48 | builder.properties(propertiesConfig.getProperties()); 49 | PropertiesUtil.setPropertiesConfig(propertiesConfig); // 设置配置文件工具类 50 | return builder.sources(PlatformServiceConsumerApp.class); 51 | } 52 | } -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-web/src/main/resources/applicationContext-plug.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | applicationContext文件插件列表 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-web/src/main/resources/config/application-dev.yml: -------------------------------------------------------------------------------- 1 | ########### 开发环境 ########## 2 | # tomcat 3 | server : 4 | port : 9999 5 | tomcat : 6 | min-spare-threads : 30 7 | max-threads : 800 8 | connection-timeout : 5000 9 | uri-encoding : UTF-8 10 | 11 | # dubbo 12 | dubbo : 13 | port : 20992 14 | applicationName : lzgyy-platform-consumer 15 | registry : 16 | address : zookeeper://192.168.0.114:2181 17 | timeout : 60000 18 | 19 | # spring 20 | spring: 21 | application: 22 | name : lzgyy-platform 23 | http : 24 | encoding : 25 | charset : UTF-8 26 | enabled : true 27 | force : true 28 | messages : 29 | encoding : UTF-8 30 | 31 | # logging 32 | logging : 33 | level : 34 | com : 35 | evisible : 36 | blockchain : 37 | dealfee : DEBUG 38 | 39 | # banner 40 | banner : 41 | charset : UTF-8 42 | location : classpath:config/banner.txt -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-web/src/main/resources/config/application.yml: -------------------------------------------------------------------------------- 1 | # 多环境配置 2 | spring : 3 | profiles : 4 | active : dev -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-web/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, DEBUG, console, file 2 | 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.console.layout.ConversionPattern=%d %p [%c] - %m%n 6 | 7 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 8 | #log4j.appender.file.File=logs/lzgyy-platform-web.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d %p [%c] - %m%n 11 | 12 | log4j.logger.org.springframework=DEBUG 13 | 14 | #log4j.logger.com.ibatis = debug 15 | #log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = debug 16 | #log4j.logger.com.ibatis.common.jdbc.ScriptRunner = debug 17 | #log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = debug 18 | #log4j.logger.java.sql.Connection = debug 19 | log4j.logger.java.sql.Statement = debug 20 | log4j.logger.java.sql.PreparedStatement = debug 21 | log4j.logger.java.sql.ResultSet =debug 22 | -------------------------------------------------------------------------------- /lzgyy-products/lzgyy-platform-web/src/main/resources/spring/dubbo-consumer.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /lzgyy-products/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.lzgyy 5 | lzgyy 6 | 0.0.1-SNAPSHOT 7 | 8 | lzgyy-products 9 | pom 10 | 11 | lzgyy-platform-api 12 | lzgyy-platform-interf 13 | lzgyy-platform-service 14 | lzgyy-platform-web 15 | lzgyy-platform-sso 16 | 17 | --------------------------------------------------------------------------------