├── .gitignore ├── .idea ├── SpringCloudTutorials.iml ├── compiler.xml ├── encodings.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── APIZuul ├── APIZuul.iml ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── yq │ │ │ ├── APIZuulApplication.java │ │ │ ├── filter │ │ │ └── MyZuulFilter.java │ │ │ └── security │ │ │ └── WebSecurityConfig.java │ │ └── resources │ │ └── bootstrap.yml └── zuul_README.md ├── AdminDemo ├── AdminDemo.iml ├── admin_readme.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── AdminDemoApplication.java │ │ ├── SwaggerConfig.java │ │ ├── config │ │ └── ServerConfig.java │ │ └── controller │ │ └── HelloController.java │ └── resources │ └── application.properties ├── ConfigServer ├── ConfigServer.iml └── pom.xml ├── ConsulAPIZuul ├── ConsulAPIZuul.iml ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── yq │ │ │ ├── APIZuulApplication.java │ │ │ └── filter │ │ │ ├── MyFallBackProvider.java │ │ │ └── MyZuulFilter.java │ │ └── resources │ │ ├── application.properties │ │ └── logback-spring.xml └── zuul_README.md ├── ConsulCfgCenter ├── ConsulAsCfgCenterREADME.md ├── ConsulCfgCenter.iml ├── docs │ └── imgs │ │ └── keystoreDemo.png ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── yq │ │ │ ├── ConsulAsCfgCenterDemoApplication.java │ │ │ ├── SwaggerConfig.java │ │ │ ├── controller │ │ │ ├── PropController.java │ │ │ ├── SvcInfoController.java │ │ │ └── UserController.java │ │ │ └── domain │ │ │ └── User.java │ │ └── resources │ │ ├── application.properties │ │ ├── bootstrap.properties │ │ ├── bootstrap2.yml │ │ └── keystore.p12 └── target │ └── classes │ ├── application.properties │ ├── bootstrap.properties │ ├── bootstrap2.yml │ └── keystore.p12 ├── ConsulCommoditySvc ├── ConsulCommoditySvc.iml ├── ConsulCommoditySvc_README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── ConsulCommodityApplication.java │ │ ├── SwaggerConfig.java │ │ ├── controller │ │ ├── CommodityController.java │ │ └── HealthController.java │ │ └── domain │ │ └── Commodity.java │ └── resources │ ├── application-prod1.properties │ ├── application.properties │ └── logback-spring.xml ├── ConsulFeignUserCommoditySvc ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── ConsulFeignUserCommodityApplication.java │ │ ├── SwaggerConfig.java │ │ ├── client │ │ ├── FileServiceClient.java │ │ └── UserServiceClient.java │ │ ├── config │ │ └── MultipartSupportConfig.java │ │ ├── controller │ │ ├── CommodityController.java │ │ ├── FileController.java │ │ ├── HealthController.java │ │ └── UserController.java │ │ └── domain │ │ ├── Commodity.java │ │ └── User.java │ └── resources │ ├── application-prod1.properties │ ├── application.properties │ └── logback-spring.xml ├── ConsulFileUploadDemo ├── ConsulFileUploadDemo.iml ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── hello │ │ │ ├── FileUploadController.java │ │ │ ├── FileUploadDemoApplication.java │ │ │ └── storage │ │ │ ├── FileSystemStorageService.java │ │ │ ├── StorageException.java │ │ │ ├── StorageFileNotFoundException.java │ │ │ ├── StorageProperties.java │ │ │ └── StorageService.java │ └── resources │ │ ├── application.properties │ │ └── static │ │ └── index.html │ └── test │ └── resources │ └── hello │ └── testupload.txt ├── ConsulOAuthDemo ├── README_consul_OAUTH.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── GitHubApplication.java │ │ └── controller │ │ └── UserController.java │ └── resources │ ├── application.properties │ └── static │ └── index.html ├── ConsulUserSvc ├── ConsulUserSvc.iml ├── ConsulUserSvc_README.md ├── docs │ └── imgs │ │ └── keystoreDemo.png ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── ConsulUserApplication.java │ │ ├── SwaggerConfig.java │ │ ├── controller │ │ ├── SvcInfoController.java │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ ├── application.properties │ └── keystore.p12 ├── CorsDemo ├── CorsDemo.iml ├── README.md ├── img │ └── cors-setting.png ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── CorsDemoApplication.java │ │ ├── Swagger2.java │ │ ├── controller │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ ├── application.properties │ └── static │ ├── hello.js │ └── index.html ├── CuratorDemo ├── CuratorDemo.iml ├── curator_readme.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── Constant │ │ └── PathConstants.java │ │ ├── ConsulCuratorApplication.java │ │ ├── MyCommandLineRunner.java │ │ ├── SwaggerConfig.java │ │ ├── config │ │ ├── ConfigZKBean.java │ │ └── ZkConfig.java │ │ ├── controller │ │ ├── HelloController.java │ │ └── ZKController.java │ │ ├── framework │ │ ├── CreateClientExamples.java │ │ ├── CrudExamples.java │ │ └── TransactionExamples.java │ │ └── service │ │ ├── CuratorService.java │ │ ├── CuratorWatcherTest.java │ │ ├── LeaderSelectorService.java │ │ └── MyLeaderSelectorListener.java │ └── resources │ ├── application-dev1.properties │ ├── application-dev2.properties │ ├── application-dev3.properties │ ├── application.properties │ ├── log4j.properties │ ├── logback-spring1.xml │ ├── logback-spring2.xml │ └── logback-spring3.xml ├── ELKDemo ├── ELKDemo.iml ├── elk_readme.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── ELKApplication.java │ │ ├── SwaggerConfig.java │ │ ├── controller │ │ ├── LogController.java │ │ ├── MovieResource.java │ │ └── UserController.java │ │ ├── domain │ │ ├── Director.java │ │ ├── Genre.java │ │ ├── Log.java │ │ ├── Movie.java │ │ └── User.java │ │ ├── repository │ │ ├── LogRepository.java │ │ └── MovieRepository.java │ │ └── service │ │ ├── ELKService.java │ │ ├── LogService.java │ │ └── MovieService.java │ └── resources │ └── application.properties ├── EncryptDemo ├── EncryptDemo.iml ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── yq │ ├── asymmetric │ ├── AsymmetricCryptography.java │ └── RSADemo.java │ ├── keypair │ └── GenerateKeys.java │ └── symmetric │ ├── D3ESDemo.java │ ├── ThreeDESECBKeyGenerator.java │ └── ThreeDESECBUtil.java ├── ErrorControllerDemoSvc ├── ErrorControllerDemoSvc.iml ├── ErrorControllerSvc_README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── ErrorControllerApplication.java │ │ ├── controller │ │ ├── MyErrorController.java │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ ├── application.properties │ ├── public │ └── myErrorPage.png │ ├── static │ ├── img │ │ └── myErrorPage.png │ ├── myErrorPage.png │ └── style.css │ └── templates │ └── myError.html ├── ErrorPageDemoSvc ├── ErrorPageDemoSvc.iml ├── ErrorPageSvc_README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── ErrorPageApplication.java │ │ ├── SwaggerConfig.java │ │ ├── controller │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ ├── application.properties │ ├── public │ └── myErrorPage.png │ ├── static │ └── myErrorPage.png │ └── templates │ └── error.html ├── EurekaCommoditySvc ├── EurekaCommoditySvc.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── EurekaUserApplication.java │ │ ├── SwaggerConfig.java │ │ ├── controller │ │ └── CommodityController.java │ │ └── domain │ │ └── Commodity.java │ └── resources │ └── bootstrap.yml ├── EurekaServerDemo ├── EurekaServerDemo.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ └── EurekaServerApplication.java │ └── resources │ └── application.yml ├── EurekaUserSvc ├── EurekaUserSvc.iml ├── UserSvc_README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── EurekaUserApplication.java │ │ ├── SwaggerConfig.java │ │ ├── controller │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ └── application.properties ├── ExceptionDemo ├── GlobalExceptionDemo.iml ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ └── exceptiondemo │ │ ├── ExecptionDemoApplication.java │ │ ├── Swagger2.java │ │ ├── config │ │ ├── SystemLog.java │ │ └── SystemLogAspect.java │ │ ├── controller │ │ └── HelloWorldController.java │ │ ├── exception │ │ ├── BaseException.java │ │ ├── ComputerException.java │ │ └── GlobalException.java │ │ ├── service │ │ ├── ComputerService.java │ │ └── impl │ │ │ └── ComputerServiceImpl.java │ │ └── utils │ │ ├── Constants.java │ │ └── ReturnResult.java │ └── resources │ ├── application.properties │ └── logback-boot.xml ├── GatewayConsulDemo ├── GatewayConsulDemo.iml ├── gatewayConsul_README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── APIGatewayConsulApplication.java │ │ └── filter │ │ ├── AuthenticationFilter.java │ │ ├── CustomFilter.java │ │ ├── MyPostGatewayFilterFactory.java │ │ ├── MyPreGatewayFilterFactory.java │ │ └── UrlFilterGatewayFilterFactory.java │ └── resources │ ├── Bapplication.properties │ └── application.yml ├── GatewayDemo ├── GatewayDemo.iml ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── yq │ │ │ ├── APIGatewayApplication.java │ │ │ └── filter │ │ │ ├── AuthenticationFilter.java │ │ │ ├── CustomFilter.java │ │ │ ├── MyPostGatewayFilterFactory.java │ │ │ ├── MyPreGatewayFilterFactory.java │ │ │ └── UrlFilterGatewayFilterFactory.java │ │ └── resources │ │ ├── application.yml │ │ └── bootstrap.yml └── zuul_README.md ├── GatewayOAuthDemo ├── GatewayOAuthDemo.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ └── APIGatewayOAuthApplication.java │ └── resources │ ├── application.yml │ ├── bootstrap.yml │ └── static │ └── index.html ├── HttpSessionDemo ├── HttpSessionDemo.iml ├── README_httpsession.md ├── docs │ └── redis_httpsession.png ├── pom.xml └── src │ └── main │ ├── java │ └── sample │ │ ├── HttpSessionDemoApplication.java │ │ └── config │ │ ├── Config.java │ │ ├── SecurityConfig.java │ │ └── WebMvcConfig.java │ └── resources │ ├── application.properties │ ├── static │ ├── favicon.ico │ └── images │ │ └── logo.png │ └── templates │ ├── index.html │ └── layout.html ├── HystrixDemo ├── HystrixDemo.iml ├── README.md ├── img │ └── hytrix01.png ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── HystrixDemoApplication.java │ │ ├── SwaggerConfig.java │ │ ├── client │ │ ├── UserClient.java │ │ ├── UserServiceClient.java │ │ └── UserServiceClientFallbackFactory.java │ │ ├── controller │ │ ├── SvcInfoController.java │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ └── application.properties ├── HystrixTimeoutDemo ├── HystrixDemo.iml ├── HystrixFeignTimeoutDemo.iml ├── README.md ├── img │ └── hytrix01.png ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── HystrixDemoApplication.java │ │ ├── SwaggerConfig.java │ │ ├── client │ │ ├── UserClient.java │ │ ├── UserServiceClient.java │ │ └── UserServiceClientFallbackFactory.java │ │ ├── controller │ │ ├── SvcInfoController.java │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ └── application.properties ├── Neo4jDemo2 ├── Neo4jDemo2.iml ├── README_neo4jspringboot2.md ├── docs │ └── sprinboot_springDataNeo4j版本关系.png ├── pom.xml └── src │ └── main │ ├── java │ └── movies │ │ └── spring │ │ └── data │ │ └── neo4j │ │ ├── SampleMovieApplication.java │ │ ├── controller │ │ └── MovieController.java │ │ ├── domain │ │ ├── Movie.java │ │ ├── Person.java │ │ └── Role.java │ │ ├── repositories │ │ ├── MovieRepository.java │ │ └── PersonRepository.java │ │ └── services │ │ └── MovieService.java │ └── resources │ ├── application.properties │ └── static │ └── index.html ├── OAuthDemo ├── OAuthDemo.iml ├── README_OAUTH.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── SocialApplication.java │ │ └── controller │ │ └── UserController.java │ └── resources │ ├── Bapplication.yml │ ├── application.properties │ └── static │ └── index.html ├── README.md ├── RabbitMqDemo ├── RabbitMqDemo.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── RabbitMQApplication.java │ │ ├── SwaggerConfig.java │ │ └── producer │ │ └── SyncProducer.java │ └── resources │ └── application.properties ├── RedisCacheBoot15Demo ├── README_redisCacheSpringBoot15.md ├── RedisCacheBoot15Demo.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── RedisCacheApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── domain │ │ └── User.java │ │ └── service │ │ └── UserRepository.java │ └── resources │ └── application.properties ├── RedisDemo ├── README_redisSpringBoot2.md ├── RedisDemo.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── RedisDemoApplication.java │ │ ├── SwaggerConfig.java │ │ ├── config │ │ └── MyRedisConfig.java │ │ ├── controller │ │ └── RedisController.java │ │ └── service │ │ ├── RedisService.java │ │ └── impl │ │ └── RedisServiceImpl.java │ └── resources │ ├── application-beta.properties │ ├── application-dev.properties │ ├── application-prod.properties │ ├── application-test.properties │ └── application.properties ├── RedisPubSubDemo ├── README_redisSpringBoot2.md ├── RedisPubSubDemo.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── MyCommandLineRunner.java │ │ ├── RedisDemoApplication.java │ │ ├── SwaggerConfig.java │ │ ├── callable │ │ └── MyCallable.java │ │ ├── config │ │ ├── ConfigRedisConfigBean.java │ │ ├── MyRedisConfig.java │ │ ├── RedisConfig.java │ │ └── ThreadPool.java │ │ ├── controller │ │ ├── RedisController.java │ │ ├── RedisExecutorController.java │ │ └── RedisMapController.java │ │ ├── dist │ │ └── DistLock.java │ │ ├── other │ │ └── SynchronousQueueQuiz.java │ │ ├── service │ │ ├── MyMessageListener.java │ │ ├── MyRedisPubSubListener.java │ │ ├── RedisService.java │ │ └── impl │ │ │ └── RedisServiceImpl.java │ │ └── task │ │ └── RunnableTask.java │ └── resources │ ├── application-beta.properties │ ├── application-dev.properties │ ├── application-prod.properties │ ├── application-test.properties │ └── application.properties ├── RedisReadWriteDemo ├── README.md ├── RedisReadWriteDemo.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── RedisReadWriteDemoApplication.java │ │ ├── SwaggerConfig.java │ │ ├── controller │ │ └── RedisController.java │ │ └── service │ │ ├── RedisService.java │ │ └── impl │ │ └── RedisServiceImpl.java │ └── resources │ ├── application-beta.properties │ ├── application-dev.properties │ ├── application-prod.properties │ ├── application-test.properties │ └── application.properties ├── RestTemplateDemo ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── RestTemplateApplication.java │ │ ├── SwaggerConfig.java │ │ ├── controller │ │ ├── ClientController.java │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ ├── application.properties │ └── keystore.p12 ├── SecurityDemo ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── SecurityDemoApplication.java │ │ ├── config │ │ ├── SecurityConfig.java │ │ └── UnauthorizedEntryPoint.java │ │ └── controller │ │ └── MainController.java │ └── resources │ ├── application.properties │ ├── application.yml │ ├── static │ └── css │ │ └── main.css │ └── templates │ ├── index.html │ ├── login.html │ └── user │ └── index.html ├── StaticResDemo ├── README_staticResource.md ├── StaticResDemo.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── StaticResDemoApplication.java │ │ ├── controller │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ ├── application.properties │ ├── public │ ├── img │ │ └── cloud02.jpg │ └── index.html │ └── static │ ├── css │ └── main.css │ ├── hello.js │ ├── img │ └── cloud01.jpg │ └── index.html ├── WebClientDemo ├── README.md ├── WebClientDemo.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── SwaggerConfig.java │ │ ├── WebClientApplication.java │ │ ├── controller │ │ ├── ClientController.java │ │ └── UserController.java │ │ └── domain │ │ └── User.java │ └── resources │ └── application.properties ├── WebSocket ├── README_WebSocket.md ├── WebSocket.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── yq │ │ │ ├── Swagger2.java │ │ │ ├── WebSocketApplication.java │ │ │ ├── config │ │ │ ├── MyHandler.java │ │ │ ├── MyWebSocketConfig.java │ │ │ ├── WebSocketConfig.java │ │ │ └── WebSocketInterceptor.java │ │ │ ├── controller │ │ │ ├── GreetingController.java │ │ │ └── SocketController.java │ │ │ ├── domain │ │ │ ├── Greeting.java │ │ │ └── HelloMessage.java │ │ │ └── service │ │ │ ├── MyRunnable.java │ │ │ └── WebSocketSendSvc.java │ └── resources │ │ ├── application.properties │ │ ├── keystore.p12 │ │ ├── logback-spring.xml │ │ └── static │ │ ├── app.js │ │ ├── index.html │ │ └── main.css │ └── test │ └── java │ └── com │ └── yq │ └── GreetingIntegrationTests.java ├── WebSocket2 ├── WebSocket2.iml ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── yq │ │ │ ├── Swagger2.java │ │ │ ├── WebSocket2Application.java │ │ │ ├── config │ │ │ └── WebSocketConfig.java │ │ │ ├── controller │ │ │ ├── GreetingController.java │ │ │ └── SocketController.java │ │ │ ├── domain │ │ │ ├── Greeting.java │ │ │ └── HelloMessage.java │ │ │ └── service │ │ │ └── WebSocketSendSvc.java │ │ └── resources │ │ ├── application.properties │ │ ├── logback-spring.xml │ │ └── static │ │ ├── app.js │ │ ├── index.html │ │ ├── main.css │ │ └── myindex.html └── websocket2_readme.md ├── ZKClientDemo ├── ZKClientDemo.iml ├── a.txt ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── yq │ │ │ ├── CuratorWatcherTest.java │ │ │ ├── ZKClientApp.java │ │ │ ├── ZKClientSequenceApp.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ ├── official │ │ │ ├── DataMonitor.java │ │ │ ├── Executor.java │ │ │ ├── cache │ │ │ │ ├── PathCacheExample.java │ │ │ │ └── TreeCacheExample.java │ │ │ ├── discovery │ │ │ │ ├── DiscoveryExample.java │ │ │ │ ├── ExampleServer.java │ │ │ │ └── InstanceDetails.java │ │ │ ├── framework │ │ │ │ ├── CreateClientExamples.java │ │ │ │ ├── CrudExamples.java │ │ │ │ └── TransactionExamples.java │ │ │ └── leader │ │ │ │ ├── ExampleClient.java │ │ │ │ ├── LeaderLatchTest.java │ │ │ │ └── LeaderSelectorExample.java │ │ │ └── service │ │ │ └── MyZooKeeper.java │ │ └── resources │ │ ├── application.properties │ │ └── log4j.properties ├── zk_readme.md └── zookeeperDemo1.iml ├── ZKDistLock ├── README.md ├── ZKDistLock.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── ZKClientApp.java │ │ ├── ZKCounterApp.java │ │ ├── ZKDistributedAtomicLongSequenceApp.java │ │ ├── ZKSequenceApp.java │ │ └── service │ │ ├── DistSequenceGenerator.java │ │ └── MyZooKeeper.java │ └── resources │ ├── application.properties │ └── log4j.properties ├── eureka └── readme.txt ├── rocketmqDemo ├── README.md ├── pom.xml ├── rocketmqDemo.iml └── src │ └── main │ ├── java │ └── com │ │ └── yq │ │ ├── RocketMQApplication.java │ │ ├── SwaggerConfig.java │ │ └── producer │ │ └── SyncProducer.java │ └── resources │ └── application.properties └── zookeeperDemo1 ├── pom.xml ├── src └── main │ ├── java │ └── com │ │ └── yq │ │ ├── SwaggerConfig.java │ │ ├── ZKDemoOneApplication.java │ │ ├── ZKLeaderSelector.java │ │ ├── controller │ │ └── ZKController.java │ │ ├── domain │ │ └── User.java │ │ └── service │ │ ├── MyZooKeeper.java │ │ └── ZkClientDemo.java │ └── resources │ ├── application.properties │ └── log4j.properties ├── zk_readme.md └── zookeeperDemo1.iml /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.ear 19 | *.zip 20 | *.tar.gz 21 | *.rar 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | 26 | -------------------------------------------------------------------------------- /.idea/SpringCloudTutorials.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /APIZuul/src/main/java/com/yq/APIZuulApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 10 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 11 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 12 | import org.springframework.web.cors.CorsConfiguration; 13 | 14 | 15 | @SpringBootApplication 16 | @EnableDiscoveryClient 17 | @EnableZuulProxy 18 | public class APIZuulApplication extends WebSecurityConfigurerAdapter { 19 | private static final Logger logger = LoggerFactory.getLogger(APIZuulApplication.class); 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(APIZuulApplication.class, args); 23 | logger.info(" Start APIZuulApplication Done"); 24 | } 25 | 26 | 27 | 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /APIZuul/src/main/java/com/yq/filter/MyZuulFilter.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.filter; 4 | 5 | 6 | import com.netflix.zuul.*; 7 | 8 | import com.netflix.zuul.context.RequestContext; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.stereotype.Component; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | 15 | /** 16 | 17 | * @author EricYang 18 | * @version 2018/6/30 20:25 19 | */ 20 | 21 | @Component 22 | public class MyZuulFilter extends ZuulFilter { 23 | private static final Logger log = LoggerFactory.getLogger(MyZuulFilter.class); 24 | 25 | @Override 26 | public String filterType() { 27 | return "pre"; 28 | } 29 | 30 | @Override 31 | public int filterOrder() { 32 | return 0; 33 | } 34 | 35 | @Override 36 | public boolean shouldFilter() { 37 | return true; 38 | } 39 | 40 | @Override 41 | public Object run() { 42 | RequestContext ctx = RequestContext.getCurrentContext(); 43 | HttpServletRequest request = ctx.getRequest(); 44 | log.info(String.format("%s >>> %s", request.getMethod(), request.getRequestURL().toString())); 45 | Object accessToken = request.getParameter("token"); 46 | if(accessToken == null) { 47 | log.warn("token is empty"); 48 | ctx.setSendZuulResponse(false); 49 | ctx.setResponseStatusCode(401); 50 | try { 51 | ctx.getResponse().getWriter().write("token is empty"); 52 | }catch (Exception e){} 53 | 54 | return null; 55 | } 56 | 57 | log.info("ok"); 58 | return null; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /APIZuul/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | client: 4 | serviceUrl: 5 | defaultZone: http://localhost:7700/eureka/ 6 | 7 | server: 8 | port: 6603 9 | 10 | spring: 11 | application: 12 | name: apizuul-service 13 | 14 | security: 15 | user: 16 | password: none 17 | basic: 18 | enabled: false 19 | 20 | 21 | zuul: 22 | routes: 23 | api-user: 24 | path: /userapi/** 25 | service-id: user-service 26 | sensitive-headers: 27 | api-commodity: 28 | path: /commodityapi/** 29 | service-id: commodity-service -------------------------------------------------------------------------------- /APIZuul/zuul_README.md: -------------------------------------------------------------------------------- 1 | # APIZUUL 2 | 3 | http://127.0.0.1:7700/ 4 | http://localhost:6601/swagger-ui.html#/ 5 | 6 | zuul启动 7 | 8 | http://127.0.0.1:6603/userapi/swagger-ui.html ---no token 9 | http://127.0.0.1:6603/userapi/swagger-ui.html?token=aaa# 10 | 11 | http://localhost:6601/user/users/2 ---直接访问user服务 12 | http://localhost:6603/userapi/user/users/2?token=aaa, 通过API网关访问user服务, 用户服务的所有path前面都有user 13 | -------------------------------------------------------------------------------- /AdminDemo/admin_readme.md: -------------------------------------------------------------------------------- 1 | 2 | http://localhost:6062 3 | 4 | 5 | 6 | de.codecentric 7 | spring-boot-admin-starter-client 8 | ${admin.version} 9 | 10 | 11 | 12 | de.codecentric 13 | spring-boot-admin-starter-server 14 | ${admin.version} 15 | 16 | 17 | http://codecentric.github.io/spring-boot-admin/current/ -------------------------------------------------------------------------------- /AdminDemo/src/main/java/com/yq/AdminDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | 4 | import de.codecentric.boot.admin.server.config.EnableAdminServer; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 9 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | 13 | 14 | @Configuration 15 | @EnableAutoConfiguration 16 | @EnableAdminServer 17 | @EnableDiscoveryClient 18 | public class AdminDemoApplication { 19 | private static final Logger log = LoggerFactory.getLogger(AdminDemoApplication.class); 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(AdminDemoApplication.class, args); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /AdminDemo/src/main/java/com/yq/config/ServerConfig.java: -------------------------------------------------------------------------------- 1 | package com.yq.config; 2 | 3 | 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.boot.web.context.WebServerInitializedEvent; 6 | import org.springframework.context.ApplicationListener; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: ServerConfig 12 | * 13 | * @author EricYang 14 | * @version 2018/9/8 23:39 15 | */ 16 | @Component 17 | @Slf4j 18 | public class ServerConfig implements ApplicationListener { 19 | 20 | private int serverPort; 21 | 22 | public int getPort() { 23 | return this.serverPort; 24 | } 25 | 26 | @Override 27 | public void onApplicationEvent(WebServerInitializedEvent event) { 28 | this.serverPort = event.getWebServer().getPort(); 29 | log.info("Get WebServer port {}", serverPort); 30 | } 31 | } 32 | 33 | ////for 1.5.x Spring Boot 34 | //public class ServerConfig implements ApplicationListener { 35 | // private int serverPort;; 36 | // 37 | // public int getPort() { 38 | // return this.serverPort; 39 | // } 40 | // 41 | // @Override 42 | // public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) { 43 | // this.serverPort = event.getEmbeddedServletContainer().getPort(); 44 | // } 45 | //} -------------------------------------------------------------------------------- /AdminDemo/src/main/java/com/yq/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.yq.controller; 2 | 3 | import com.yq.config.ServerConfig; 4 | import io.swagger.annotations.ApiImplicitParam; 5 | import io.swagger.annotations.ApiImplicitParams; 6 | import io.swagger.annotations.ApiOperation; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | 12 | 13 | 14 | @RestController 15 | public class HelloController { 16 | 17 | @Autowired 18 | private ServerConfig serverConfig; 19 | 20 | @GetMapping("/port") 21 | @ApiOperation("get server port service") 22 | @ApiImplicitParams({ 23 | }) 24 | public String getPort() { 25 | return "server port " + serverConfig.getPort(); 26 | } 27 | 28 | @GetMapping("/hello") 29 | @ApiOperation("hello world rest demo") 30 | @ApiImplicitParams({ 31 | }) 32 | public String handle() { 33 | return "Hello World"; 34 | } 35 | } -------------------------------------------------------------------------------- /AdminDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/AdminDemo/src/main/resources/application.properties -------------------------------------------------------------------------------- /ConfigServer/ConfigServer.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ConfigServer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.yq.configServer 8 | ConfigServer 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /ConsulAPIZuul/src/main/java/com/yq/APIZuulApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 9 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 10 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 11 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 12 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 13 | 14 | 15 | @SpringBootApplication 16 | @EnableDiscoveryClient 17 | @EnableZuulProxy 18 | @EnableCircuitBreaker 19 | @EnableHystrix 20 | @EnableHystrixDashboard 21 | public class APIZuulApplication { 22 | private static final Logger logger = LoggerFactory.getLogger(APIZuulApplication.class); 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(APIZuulApplication.class, args); 26 | logger.info("Start APIZuulApplication Done"); 27 | } 28 | 29 | 30 | 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /ConsulAPIZuul/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulAPIZuul/src/main/resources/application.properties -------------------------------------------------------------------------------- /ConsulCfgCenter/ConsulAsCfgCenterREADME.md: -------------------------------------------------------------------------------- 1 | # ConsulCfgCenter 7001 2 | 3 | http://127.0.0.1:7001/ 4 | http://localhost:7001/swagger-ui.html#/ 5 | 6 | 7 | https 8 | https://www.tutorialspoint.com/spring_boot/spring_boot_enabling_https.htm 9 | https://127.0.0.1:7001/swagger-ui.html 10 | 11 | ###配置如下时 12 | spring: 13 | application: 14 | name: user-service 15 | cloud: 16 | consul: 17 | port: 8500 18 | host: 127.0.0.1 19 | config: 20 | enabled: true 21 | format: properties 22 | defaultContext: application 23 | profileSeparator: ',' 24 | watch: 25 | enabled: true 26 | delay: 10000 27 | 28 | 日志为 29 | 2019-07-07 10:24:15.127 INFO 18912 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='consul', propertySources= 30 | [ConsulPropertySource {name='config/user-service,dev/'}, 31 | ConsulPropertySource {name='config/user-service/'}, 32 | ConsulPropertySource {name='config/application,dev/'}, 33 | ConsulPropertySource {name='config/application/'}]} -------------------------------------------------------------------------------- /ConsulCfgCenter/docs/imgs/keystoreDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulCfgCenter/docs/imgs/keystoreDemo.png -------------------------------------------------------------------------------- /ConsulCfgCenter/src/main/java/com/yq/controller/PropController.java: -------------------------------------------------------------------------------- 1 | package com.yq.controller; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.yq.domain.User; 5 | import io.swagger.annotations.ApiImplicitParam; 6 | import io.swagger.annotations.ApiImplicitParams; 7 | import io.swagger.annotations.ApiOperation; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import java.util.Collection; 18 | import java.util.Date; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | 23 | @RestController 24 | @RequestMapping("/v1") 25 | @Slf4j 26 | public class PropController { 27 | 28 | @Value("${demo.prop1}") 29 | private String prop1; 30 | 31 | @ApiOperation(value = "按用户id查询, 参数在path部分", notes="private") 32 | @ApiImplicitParams({ 33 | @ApiImplicitParam(name = "prop", defaultValue = "demo.prop1", value = "prop", required = true, dataType = "string", paramType = "path"), 34 | }) 35 | @GetMapping(value = "/props/{prop}", produces = "application/json;charset=UTF-8") 36 | public String getUser(@PathVariable String prop) { 37 | JSONObject jsonObj = new JSONObject(); 38 | jsonObj.put("key", prop); 39 | jsonObj.put("value", prop1); 40 | return jsonObj.toJSONString(); 41 | } 42 | } -------------------------------------------------------------------------------- /ConsulCfgCenter/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * Simple to Introduction 12 | * className: User 13 | * 14 | * @author EricYang 15 | * @version 2018/6/29 23:43 16 | */ 17 | @Data 18 | public class User { 19 | String id; 20 | String name; 21 | String mail; 22 | 23 | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") 24 | Date regDate; 25 | } 26 | -------------------------------------------------------------------------------- /ConsulCfgCenter/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | 3 | spring.cloud.config.profile=@spring.profiles.active@ 4 | 5 | session.store-type=none 6 | 7 | server.port=7001 8 | #server.ssl.key-store=classpath:keystore.p12 9 | #server.ssl.key-store-password=123456 10 | #server.ssl.keyStoreType=PKCS12 11 | #server.ssl.keyAlias=yqdemo 12 | 13 | 14 | logging.level.com.yq=DEBUG 15 | 16 | spring.cloud.consul.host=127.0.0.1 17 | spring.cloud.consul.port=8500 18 | spring.cloud.consul.discovery.service-name=${spring.application.name} 19 | spring.cloud.consul.discovery.health-check-interval=120s 20 | spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.int} 21 | spring.cloud.consul.discovery.tags=trial 22 | spring.cloud.consul.discovery.healthCheckCriticalTimeout=2m 23 | 24 | 25 | demo.prop1=local 26 | 27 | 28 | 29 | #actuator 30 | health.sensitive=true 31 | 32 | 33 | -------------------------------------------------------------------------------- /ConsulCfgCenter/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulCfgCenter/src/main/resources/bootstrap.properties -------------------------------------------------------------------------------- /ConsulCfgCenter/src/main/resources/bootstrap2.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | application: 4 | name: user-service 5 | cloud: 6 | consul: 7 | port: 8500 8 | host: 127.0.0.1 9 | config: 10 | enabled: true 11 | format: properties 12 | defaultContext: application 13 | profileSeparator: ',' 14 | watch: 15 | enabled: true 16 | delay: 10000 17 | discovery: 18 | health-check-path: /actuator/health 19 | health-check-interval: 10s 20 | enabled: true 21 | queryPassing: true 22 | prefer-ip-address: true 23 | instance-id: ${spring.application.name}:${server.port}:${random.int} 24 | profiles: 25 | active: dev 26 | -------------------------------------------------------------------------------- /ConsulCfgCenter/src/main/resources/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulCfgCenter/src/main/resources/keystore.p12 -------------------------------------------------------------------------------- /ConsulCfgCenter/target/classes/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | 3 | spring.cloud.config.profile=@spring.profiles.active@ 4 | 5 | session.store-type=none 6 | 7 | server.port=7001 8 | #server.ssl.key-store=classpath:keystore.p12 9 | #server.ssl.key-store-password=123456 10 | #server.ssl.keyStoreType=PKCS12 11 | #server.ssl.keyAlias=yqdemo 12 | 13 | 14 | logging.level.com.yq=DEBUG 15 | 16 | spring.cloud.consul.host=127.0.0.1 17 | spring.cloud.consul.port=8500 18 | spring.cloud.consul.discovery.service-name=${spring.application.name} 19 | spring.cloud.consul.discovery.health-check-interval=120s 20 | spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.int} 21 | spring.cloud.consul.discovery.tags=trial 22 | spring.cloud.consul.discovery.healthCheckCriticalTimeout=2m 23 | 24 | 25 | demo.prop1=local 26 | 27 | 28 | 29 | #actuator 30 | health.sensitive=true 31 | 32 | 33 | -------------------------------------------------------------------------------- /ConsulCfgCenter/target/classes/bootstrap.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulCfgCenter/target/classes/bootstrap.properties -------------------------------------------------------------------------------- /ConsulCfgCenter/target/classes/bootstrap2.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | application: 4 | name: user-service 5 | cloud: 6 | consul: 7 | port: 8500 8 | host: 127.0.0.1 9 | config: 10 | enabled: true 11 | format: properties 12 | defaultContext: application 13 | profileSeparator: ',' 14 | watch: 15 | enabled: true 16 | delay: 10000 17 | discovery: 18 | health-check-path: /actuator/health 19 | health-check-interval: 10s 20 | enabled: true 21 | queryPassing: true 22 | prefer-ip-address: true 23 | instance-id: ${spring.application.name}:${server.port}:${random.int} 24 | profiles: 25 | active: dev 26 | -------------------------------------------------------------------------------- /ConsulCfgCenter/target/classes/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulCfgCenter/target/classes/keystore.p12 -------------------------------------------------------------------------------- /ConsulCommoditySvc/ConsulCommoditySvc_README.md: -------------------------------------------------------------------------------- 1 | # ConsulCommoditySvc 7002 2 | 3 | http://127.0.0.1:7002/ 4 | http://localhost:7002/swagger-ui.html#/ 5 | 6 | 7 | 也可以直接使用ConsulRegistration, 使用可以获得instanceId String currentInstId = registration.getInstanceId(); 8 | 9 | 10 | rest API 11 | 1, http://localhost:7002/commodity/commodities 12 | 13 | 2, http://localhost:7002/commodity/commodities/2 14 | 15 | 通过API网关 16 | http://127.0.0.1:7700/comapi/swagger-ui.html?token=aaa 17 | 1, http://localhost:7700/comapi/commodity/commodities?token=aaa 18 | 2, http://localhost:7700/comapi/commodity/commodities/2?token=aaa -------------------------------------------------------------------------------- /ConsulCommoditySvc/src/main/java/com/yq/ConsulCommodityApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | 9 | @SpringBootApplication 10 | @EnableDiscoveryClient 11 | public class ConsulCommodityApplication { 12 | private static final Logger logger = LoggerFactory.getLogger(ConsulCommodityApplication.class); 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ConsulCommodityApplication.class, args); 16 | logger.info("SpringBoot start done."); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ConsulCommoditySvc/src/main/java/com/yq/controller/HealthController.java: -------------------------------------------------------------------------------- 1 | package com.yq.controller; 2 | 3 | import com.yq.domain.Commodity; 4 | import io.swagger.annotations.ApiImplicitParam; 5 | import io.swagger.annotations.ApiImplicitParams; 6 | import io.swagger.annotations.ApiOperation; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import java.util.Collection; 16 | import java.util.Date; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | 21 | @RestController 22 | @RequestMapping("/my") 23 | @Slf4j 24 | public class HealthController { 25 | private Logger logger = LoggerFactory.getLogger(HealthController.class); 26 | 27 | @ApiOperation(value = "health", notes="private") 28 | @GetMapping(value = "/health", produces = "application/json;charset=UTF-8") 29 | public String getMyHealth() { 30 | String str = "{\"description\":\"my customized health\",\"status\":\"UP\"}"; 31 | return str; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /ConsulCommoditySvc/src/main/java/com/yq/domain/Commodity.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: Commodity 12 | * 13 | * @author EricYang 14 | * @version 2018/6/30 0:13 15 | */ 16 | @Data 17 | public class Commodity { 18 | String id; 19 | String name; 20 | String description; 21 | String price; 22 | String count; 23 | String picUrl; 24 | Date onlineDate; 25 | } 26 | -------------------------------------------------------------------------------- /ConsulCommoditySvc/src/main/resources/application-prod1.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | spring.profiles.active=@spring.profiles.active@ 3 | spring.cloud.config.profile=@spring.profiles.active@ 4 | 5 | session.store-type=none 6 | 7 | spring.application.name=commodity-service 8 | server.port=7003 9 | 10 | 11 | 12 | logging.level.com.yq=DEBUG 13 | logging.config=classpath:logback-spring.xml 14 | 15 | spring.cloud.consul.host=127.0.0.1 16 | spring.cloud.consul.port=8500 17 | spring.cloud.consul.discovery.service-name=${spring.application.name} 18 | spring.cloud.consul.discovery.health-check-interval=120s 19 | spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.int} 20 | spring.cloud.consul.discovery.tags=trial 21 | spring.cloud.consul.discovery.healthCheckCriticalTimeout=2m 22 | 23 | 24 | spring.boot.admin.client.url=http://localhost:6062 25 | management.endpoints.web.exposure.include=* 26 | 27 | 28 | #actuator 29 | health.sensitive=true 30 | 31 | 32 | -------------------------------------------------------------------------------- /ConsulCommoditySvc/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulCommoditySvc/src/main/resources/application.properties -------------------------------------------------------------------------------- /ConsulFeignUserCommoditySvc/README.md: -------------------------------------------------------------------------------- 1 | #按照swagger访问服务间调用 2 | 3 | 4 | http://localhost:7010/swagger-ui.html#/ 5 | 6 | 1, https://github.com/Netflix/ribbon 7 | 2,https://cloud.spring.io/spring-cloud-static/spring-cloud-netflix/2.0.2.RELEASE/single/spring-cloud-netflix.html#spring-cloud-ribbon 8 | 3,https://github.com/Netflix/ribbon/wiki/Programmers-Guide 9 | 10 | http://cloud.spring.io/spring-cloud-openfeign/single/spring-cloud-openfeign.html -------------------------------------------------------------------------------- /ConsulFeignUserCommoditySvc/src/main/java/com/yq/ConsulFeignUserCommodityApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.cloud.openfeign.EnableFeignClients; 9 | 10 | @SpringBootApplication 11 | @EnableDiscoveryClient 12 | @EnableFeignClients(basePackages = {"com.yq.client"}) 13 | public class ConsulFeignUserCommodityApplication { 14 | private static final Logger logger = LoggerFactory.getLogger(ConsulFeignUserCommodityApplication.class); 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ConsulFeignUserCommodityApplication.class, args); 18 | logger.info("SpringBoot start done."); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ConsulFeignUserCommoditySvc/src/main/java/com/yq/config/MultipartSupportConfig.java: -------------------------------------------------------------------------------- 1 | package com.yq.config; 2 | 3 | /** 4 | * Simple to Introduction 5 | * className: MultipartSupportConfig 6 | * 7 | * @author EricYang 8 | * @version 2019/1/22 19:49 9 | */ 10 | 11 | 12 | import feign.codec.Encoder; 13 | import feign.form.spring.SpringFormEncoder; 14 | import org.springframework.beans.factory.ObjectFactory; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.boot.autoconfigure.http.HttpMessageConverters; 17 | import org.springframework.cloud.openfeign.support.SpringEncoder; 18 | import org.springframework.context.annotation.Bean; 19 | import org.springframework.context.annotation.Configuration; 20 | 21 | 22 | @Configuration 23 | public class MultipartSupportConfig { 24 | 25 | @Autowired 26 | private ObjectFactory messageConverters; 27 | 28 | @Bean 29 | public Encoder feignFormEncoder(){ 30 | return new SpringFormEncoder(new SpringEncoder(messageConverters)); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ConsulFeignUserCommoditySvc/src/main/java/com/yq/controller/HealthController.java: -------------------------------------------------------------------------------- 1 | package com.yq.controller; 2 | 3 | import com.yq.domain.Commodity; 4 | import io.swagger.annotations.ApiImplicitParam; 5 | import io.swagger.annotations.ApiImplicitParams; 6 | import io.swagger.annotations.ApiOperation; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import java.util.Collection; 16 | import java.util.Date; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | 21 | @RestController 22 | @RequestMapping("/my") 23 | @Slf4j 24 | public class HealthController { 25 | private Logger logger = LoggerFactory.getLogger(HealthController.class); 26 | 27 | @ApiOperation(value = "health", notes="private") 28 | @GetMapping(value = "/health", produces = "application/json;charset=UTF-8") 29 | public String getMyHealth() { 30 | String str = "{\"description\":\"my customized health\",\"status\":\"UP\"}"; 31 | return str; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /ConsulFeignUserCommoditySvc/src/main/java/com/yq/domain/Commodity.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: Commodity 12 | * 13 | * @author EricYang 14 | * @version 2018/6/30 0:13 15 | */ 16 | @Data 17 | public class Commodity { 18 | String id; 19 | String name; 20 | String description; 21 | String price; 22 | String count; 23 | String picUrl; 24 | Date onlineDate; 25 | } 26 | -------------------------------------------------------------------------------- /ConsulFeignUserCommoditySvc/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * Simple to Introduction 12 | * className: User 13 | * 14 | * @author EricYang 15 | * @version 2018/6/29 23:43 16 | */ 17 | @Data 18 | public class User { 19 | String id; 20 | String name; 21 | String mail; 22 | 23 | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") 24 | Date regDate; 25 | } 26 | -------------------------------------------------------------------------------- /ConsulFeignUserCommoditySvc/src/main/resources/application-prod1.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | spring.profiles.active=@spring.profiles.active@ 3 | spring.cloud.config.profile=@spring.profiles.active@ 4 | 5 | session.store-type=none 6 | 7 | spring.application.name=feignusercommodity-service 8 | server.port=7011 9 | 10 | 11 | 12 | logging.level.com.yq=DEBUG 13 | logging.config=classpath:logback-spring.xml 14 | 15 | spring.cloud.consul.host=127.0.0.1 16 | spring.cloud.consul.port=8500 17 | spring.cloud.consul.discovery.service-name=${spring.application.name} 18 | spring.cloud.consul.discovery.health-check-interval=120s 19 | spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.int} 20 | spring.cloud.consul.discovery.tags=trial 21 | spring.cloud.consul.discovery.healthCheckCriticalTimeout=2m 22 | 23 | 24 | spring.boot.admin.client.url=http://localhost:6062 25 | management.endpoints.web.exposure.include=* 26 | 27 | 28 | #actuator 29 | health.sensitive=true 30 | 31 | 32 | -------------------------------------------------------------------------------- /ConsulFeignUserCommoditySvc/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulFeignUserCommoditySvc/src/main/resources/application.properties -------------------------------------------------------------------------------- /ConsulFileUploadDemo/README.md: -------------------------------------------------------------------------------- 1 | # file upload demo 2 | 3 | 4 | http://127.0.0.1:7013 -------------------------------------------------------------------------------- /ConsulFileUploadDemo/src/main/java/hello/FileUploadDemoApplication.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.context.annotation.Bean; 9 | 10 | import hello.storage.StorageProperties; 11 | import hello.storage.StorageService; 12 | 13 | @SpringBootApplication 14 | @EnableDiscoveryClient 15 | @EnableConfigurationProperties(StorageProperties.class) 16 | public class FileUploadDemoApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(FileUploadDemoApplication.class, args); 20 | } 21 | 22 | @Bean 23 | CommandLineRunner init(StorageService storageService) { 24 | return (args) -> { 25 | storageService.deleteAll(); 26 | storageService.init(); 27 | }; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ConsulFileUploadDemo/src/main/java/hello/storage/StorageException.java: -------------------------------------------------------------------------------- 1 | package hello.storage; 2 | 3 | public class StorageException extends RuntimeException { 4 | 5 | public StorageException(String message) { 6 | super(message); 7 | } 8 | 9 | public StorageException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ConsulFileUploadDemo/src/main/java/hello/storage/StorageFileNotFoundException.java: -------------------------------------------------------------------------------- 1 | package hello.storage; 2 | 3 | public class StorageFileNotFoundException extends StorageException { 4 | 5 | public StorageFileNotFoundException(String message) { 6 | super(message); 7 | } 8 | 9 | public StorageFileNotFoundException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } -------------------------------------------------------------------------------- /ConsulFileUploadDemo/src/main/java/hello/storage/StorageProperties.java: -------------------------------------------------------------------------------- 1 | package hello.storage; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | @ConfigurationProperties("storage") 6 | public class StorageProperties { 7 | 8 | /** 9 | * Folder location for storing files 10 | */ 11 | private String location = "upload-dir"; 12 | 13 | public String getLocation() { 14 | return location; 15 | } 16 | 17 | public void setLocation(String location) { 18 | this.location = location; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /ConsulFileUploadDemo/src/main/java/hello/storage/StorageService.java: -------------------------------------------------------------------------------- 1 | package hello.storage; 2 | 3 | import org.springframework.core.io.Resource; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import java.nio.file.Path; 7 | import java.util.stream.Stream; 8 | 9 | public interface StorageService { 10 | 11 | void init(); 12 | 13 | void store(MultipartFile file); 14 | 15 | Stream loadAll(); 16 | 17 | Path load(String filename); 18 | 19 | Resource loadAsResource(String filename); 20 | 21 | void deleteAll(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /ConsulFileUploadDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | spring.profiles.active=@spring.profiles.active@ 3 | spring.cloud.config.profile=@spring.profiles.active@ 4 | 5 | session.store-type=none 6 | 7 | spring.application.name=file-service 8 | server.port=7013 9 | 10 | spring.servlet.multipart.max-file-size=128KB 11 | spring.servlet.multipart.max-request-size=128KB 12 | spring.http.multipart.enabled=false 13 | 14 | #thymeleaf 15 | spring.thymeleaf.encoding=UTF-8 16 | spring.thymeleaf.suffix=.html 17 | 18 | management.health.consul.enabled=true 19 | 20 | spring.cloud.consul.host=127.0.0.1 21 | spring.cloud.consul.port=8500 22 | spring.cloud.consul.discovery.service-name=${spring.application.name} 23 | spring.cloud.consul.discovery.health-check-interval=120s 24 | spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.int} 25 | spring.cloud.consul.discovery.tags=trial 26 | spring.cloud.consul.discovery.healthCheckCriticalTimeout=2m 27 | #actuator 28 | health.sensitive=true -------------------------------------------------------------------------------- /ConsulFileUploadDemo/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | file upload demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 |

文件:

16 |

17 |
18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ConsulFileUploadDemo/src/test/resources/hello/testupload.txt: -------------------------------------------------------------------------------- 1 | Spring Framework -------------------------------------------------------------------------------- /ConsulOAuthDemo/README_consul_OAUTH.md: -------------------------------------------------------------------------------- 1 | # SpringCloudTutorials 2 | 3 | https://gitee.com/api/v5/swagger#/getV5User 4 | https://gitee.com/api/v5/oauth_doc -------------------------------------------------------------------------------- /ConsulOAuthDemo/src/main/java/com/yq/GitHubApplication.java: -------------------------------------------------------------------------------- 1 | 2 | package com.yq; 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 7 | 8 | @SpringBootApplication 9 | @EnableOAuth2Sso 10 | public class GitHubApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(GitHubApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ConsulOAuthDemo/src/main/java/com/yq/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.yq.controller; 2 | 3 | import org..Logger; 4 | import org..LoggerFactory; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import java.security.Principal; 9 | import java.util.LinkedHashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * Simple to Introduction 14 | * className: UserController 15 | * 16 | * @author EricYang 17 | * @version 2018/8/6 11:34 18 | */ 19 | @RestController 20 | 21 | public class UserController { 22 | private static final Logger logger = LoggerFactory.getLogger(UserController.class); 23 | 24 | 25 | @RequestMapping({ "/user", "/me" }) 26 | public Map user(Principal principal) { 27 | Map map = new LinkedHashMap<>(); 28 | map.put("name", principal.getName()); 29 | logger.info("name={}", principal.getName()); 30 | return map; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /ConsulOAuthDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.cloud.consul.host=127.0.0.1 3 | spring.cloud.consul.port=8500 4 | spring.cloud.consul.discovery.service-name=oauth-service 5 | spring.cloud.consul.discovery.health-check-interval=120s 6 | spring.cloud.consul.discovery.instance-id=oauth-service1 7 | spring.cloud.consul.discovery.tags=trial 8 | 9 | security.oauth2.client.clientId=ffc92fdfad5460e396de 10 | security.oauth2.client.clientSecret=549aff048e5d0e8b6f39873628bac08011ca77b4 11 | security.oauth2.client.accessTokenUri=https://github.com/login/oauth/access_token 12 | security.oauth2.client.userAuthorizationUri=https://github.com/login/oauth/authorize 13 | security.oauth2.client.clientAuthenticationScheme=form 14 | security.oauth2.resource.userInfoUri=https://api.github.com/user 15 | security.oauth2.sso.login-path=/sso 16 | 17 | 18 | logging.level.org.springframework.security=DEBUG -------------------------------------------------------------------------------- /ConsulOAuthDemo/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Demo 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

Demo

16 |
17 | 18 | -------------------------------------------------------------------------------- /ConsulUserSvc/ConsulUserSvc_README.md: -------------------------------------------------------------------------------- 1 | # ConsulUserSvc 7001 2 | 3 | http://127.0.0.1:7001/ 4 | http://localhost:7001/swagger-ui.html#/ 5 | 6 | 7 | 也可以直接使用ConsulRegistration, 使用可以获得instanceId String currentInstId = registration.getInstanceId(); 8 | 9 | 10 | deregisterCriticalServiceAfter 11 | 12 | spring.cloud.consul.discovery.check.Check.deregisterCriticalServiceAfter=20s 13 | 14 | 设置了spring.cloud.consul.discovery.healthCheckCriticalTimeout=20s后, 自动就有了deregisterCriticalServiceAfter='20s', 15 | 16 | 2018-09-28 18:39:07.683 INFO 19724 --- [ main] o.s.c.c.s.ConsulServiceRegistry : Registering service with consul: NewService{id='user-service-7001-1724970637', name='user-service', tags=[trial, secure=false], address='DESKTOP-8S2E5H7', port=7001, enableTagOverride=null, check=Check{script='null', interval='120s', ttl='null', http='http://DESKTOP-8S2E5H7:7001/actuator/health', tcp='null', timeout='null', deregisterCriticalServiceAfter='20s', tlsSkipVerify=null, status='null'}, checks=null} 17 | 18 | 19 | To disable the Consul Discovery Client you can set spring.cloud.consul.discovery.enabled to false. 20 | To disable the service registration you can set spring.cloud.consul.discovery.register to false. 21 | 22 | You can disable the health check by setting management.health.consul.enabled=false. 23 | 24 | https 25 | https://www.tutorialspoint.com/spring_boot/spring_boot_enabling_https.htm 26 | https://127.0.0.1:7001/swagger-ui.html -------------------------------------------------------------------------------- /ConsulUserSvc/docs/imgs/keystoreDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulUserSvc/docs/imgs/keystoreDemo.png -------------------------------------------------------------------------------- /ConsulUserSvc/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * Simple to Introduction 12 | * className: User 13 | * 14 | * @author EricYang 15 | * @version 2018/6/29 23:43 16 | */ 17 | @Data 18 | public class User { 19 | String id; 20 | String name; 21 | String mail; 22 | 23 | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") 24 | Date regDate; 25 | } 26 | -------------------------------------------------------------------------------- /ConsulUserSvc/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulUserSvc/src/main/resources/application.properties -------------------------------------------------------------------------------- /ConsulUserSvc/src/main/resources/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ConsulUserSvc/src/main/resources/keystore.p12 -------------------------------------------------------------------------------- /CorsDemo/img/cors-setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/CorsDemo/img/cors-setting.png -------------------------------------------------------------------------------- /CorsDemo/src/main/java/com/yq/CorsDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 9 | 10 | @SpringBootApplication 11 | public class CorsDemoApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(CorsDemoApplication.class, args); 15 | } 16 | 17 | @Bean 18 | public WebMvcConfigurer corsConfigurer() { 19 | return new WebMvcConfigurerAdapter() { 20 | @Override 21 | public void addCorsMappings(CorsRegistry registry) { 22 | registry.addMapping("/user/users/*").allowedOrigins("http://localhost:6677"); 23 | } 24 | }; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CorsDemo/src/main/java/com/yq/Swagger2.java: -------------------------------------------------------------------------------- 1 | package com.yq; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class Swagger2 { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.yq.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Spring Boot 测试使用 Swagger2 构建WebSocket send RESTful API") .contact(new Contact("EricYang", "https://github.com/yqbjtu/SpringCloudTutorials.git", "test@163.com")) .version("1.0") .description("User API 描述") .build(); } } -------------------------------------------------------------------------------- /CorsDemo/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /CorsDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | 3 | #application 4 | server.port=6606 5 | 6 | # Path pattern used for static resources. 7 | #spring.mvc.static-path-pattern=/** 8 | #spring.resources.chain.strategy.content.enabled=true 9 | #spring.resources.chain.strategy.content.paths=/** 10 | #spring.resources.static-locations=/static/css/,classpath:/static/images/,classpath:/static/js/ 11 | #spring.resources.static-locations=classpath:/static 12 | 13 | -------------------------------------------------------------------------------- /CorsDemo/src/main/resources/static/hello.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | $.ajax({ 3 | url: "http://localhost:6606/user/users/2" 4 | }).then(function(data, status, jqxhr) { 5 | console.log(data); 6 | $('.user-id').append(data.id); 7 | $('.user-name').append(data.name); 8 | console.log(jqxhr); 9 | }); 10 | }); -------------------------------------------------------------------------------- /CorsDemo/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello CORS 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

The user id is

15 |

The user name is

16 |
17 | 18 | -------------------------------------------------------------------------------- /CuratorDemo/src/main/java/com/yq/Constant/PathConstants.java: -------------------------------------------------------------------------------- 1 | package com.yq.Constant; 2 | 3 | /** 4 | * Simple to Introduction 5 | * className: PathConstants 6 | * 7 | * @author EricYang 8 | * @version 2018/9/2 12:49 9 | */ 10 | public class PathConstants { 11 | /* 所有的任务都是放入这个path下面 12 | 路径, /subList/uuidA. 内容为 axouosfs/zton/aoe 13 | 路径, /subList/uuidB. 内容为 axzruuy/noys/iue 14 | 路径, /subList/uuidC. 内容为 aytimxf/pnkyt/lyx 15 | */ 16 | public static final String ALL_SUB_PATH= "/allSubList"; 17 | 18 | 19 | /*临时节点,所有的work都去该路径下面创建childPath,使用自己的serviceId, 然后写上自己的当前时间为数据内容。 20 | 路径, /myWorkerList/SVCA. 内容为 long的时间戳, 也及时服务注册时间 21 | 路径, /myWorkerList/SVCB. 内容为 ong的时间戳, 也及时服务注册时间 22 | 路径, /myWorkerList/SVCC. 内容为 ong的时间戳, 也及时服务注册时间 23 | */ 24 | public static final String WORKER_PATH = "/myWorkerList"; 25 | 26 | /*临时节点,所有的work都去该路径下面创建childPath,使用任务的uuid, 然后任务的内容。 27 | 路径, /mySubList/SVCA/uuidA. 内容为 axouosfs/zton/aoe 28 | 路径, /mySubList/SVCA/uuidB. 内容为 axzruuy/noys/iue 29 | 路径, /mySubList/SVCC/uuidC. 内容为 aytimxf/pnkyt/lyx 30 | */ 31 | public static final String MY_SUB_PATH = "/mySubList"; 32 | 33 | 34 | public static final String LEADER_PATH = "/worker/leader"; 35 | } 36 | -------------------------------------------------------------------------------- /CuratorDemo/src/main/java/com/yq/ConsulCuratorApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.context.ApplicationContext; 9 | 10 | import java.util.Arrays; 11 | 12 | @SpringBootApplication 13 | @EnableDiscoveryClient 14 | public class ConsulCuratorApplication { 15 | private static final Logger logger = LoggerFactory.getLogger(ConsulCuratorApplication.class); 16 | 17 | public static void main(String[] args) { 18 | ApplicationContext ctx = SpringApplication.run(ConsulCuratorApplication.class, args); 19 | String[] activeProfiles = ctx.getEnvironment().getActiveProfiles(); 20 | if (activeProfiles == null || activeProfiles.length == 0) { 21 | logger.info("没有设置profile"); 22 | } 23 | Arrays.asList(activeProfiles).forEach( 24 | profile -> logger.info("Spring Boot profile为 {}", profile) 25 | ); 26 | logger.info("ConsulCuratorApplication Start done."); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CuratorDemo/src/main/java/com/yq/MyCommandLineRunner.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import com.yq.Constant.PathConstants; 4 | import com.yq.service.CuratorService; 5 | import com.yq.service.LeaderSelectorService; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.CommandLineRunner; 9 | import org.springframework.cloud.client.serviceregistry.Registration; 10 | import org.springframework.cloud.consul.serviceregistry.ConsulRegistration; 11 | import org.springframework.stereotype.Component; 12 | 13 | /** 14 | * Simple to Introduction 15 | * className: MyCommandLineRunner 16 | * 17 | * @author EricYang 18 | * @version 2018/9/2 14:03 19 | */ 20 | @Component 21 | @Slf4j 22 | public class MyCommandLineRunner implements CommandLineRunner { 23 | @Autowired 24 | private CuratorService zkClient; 25 | 26 | @Autowired 27 | private ConsulRegistration registration; 28 | 29 | @Autowired 30 | LeaderSelectorService svc; 31 | 32 | @Override 33 | public void run(String... strings) throws Exception { 34 | log.info("MyCommandLineRunner初始化 zkClient={}, registration={}, svc={}", zkClient, registration, svc); 35 | zkClient.init(); 36 | zkClient.getData(PathConstants.ALL_SUB_PATH); 37 | svc.init(); 38 | 39 | //需要检查一下是否是刚刚启动,判断刚刚启动的标准,第一/myWorkerList不存在或者为空, 40 | //第二, /mySubList下面的childrenNode有,但是/myWorkerList中没有改节点, 如果childrenNode不存在于/myWorkerList 41 | //立刻清理改children 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CuratorDemo/src/main/java/com/yq/config/ConfigZKBean.java: -------------------------------------------------------------------------------- 1 | package com.yq.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.annotation.Order; 7 | 8 | /** 9 | * Simple to Introduction 10 | * className: ConfigA 11 | * 12 | * @author EricYang 13 | * @version 2018/10/21 15:39 14 | */ 15 | @Configuration 16 | @Order(3) 17 | @Slf4j 18 | public class ConfigZKBean { 19 | 20 | @Bean 21 | public ZkConfig zKConfig() { 22 | log.info("Create a zkConfig"); 23 | return new ZkConfig(); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /CuratorDemo/src/main/java/com/yq/config/ZkConfig.java: -------------------------------------------------------------------------------- 1 | package com.yq.config; 2 | 3 | import lombok.Data; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.core.annotation.Order; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.annotation.PostConstruct; 10 | 11 | /** 12 | * 13 | */ 14 | @Component 15 | @Data 16 | @Slf4j 17 | @Order(1) 18 | public class ZkConfig { 19 | 20 | @Value("${zkServers}") 21 | private String zkServers; 22 | 23 | @PostConstruct 24 | public void postConstruct(){ 25 | log.info("zkServers={}", zkServers); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CuratorDemo/src/main/java/com/yq/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.yq.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | 7 | /** 8 | * Created by yangqian on 2018/8/7. 9 | */ 10 | 11 | @RestController 12 | public class HelloController { 13 | 14 | @GetMapping("/hello") 15 | public String handle() { 16 | return "Hello World"; 17 | } 18 | 19 | 20 | 21 | } -------------------------------------------------------------------------------- /CuratorDemo/src/main/resources/application-dev1.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.profiles.active=dev1 3 | server.port=8081 4 | 5 | logging.level.com.yq=info 6 | 7 | 8 | 9 | security.user.password=none 10 | security.basic.enabled=false 11 | 12 | 13 | logging.config=classpath:logback-spring1.xml 14 | 15 | -------------------------------------------------------------------------------- /CuratorDemo/src/main/resources/application-dev2.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.profiles.active=dev2 3 | 4 | server.port=8082 5 | 6 | 7 | logging.config=classpath:logback-spring2.xml -------------------------------------------------------------------------------- /CuratorDemo/src/main/resources/application-dev3.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.profiles.active=dev3 3 | 4 | server.port=8083 5 | 6 | 7 | logging.config=classpath:logback-spring3.xml -------------------------------------------------------------------------------- /CuratorDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.profiles.active=@spring.profiles.active@ 3 | 4 | spring.application.name=sub-service 5 | server.contextPath= 6 | spring.cloud.consul.host=127.0.0.1 7 | spring.cloud.consul.port=8500 8 | spring.cloud.consul.discovery.service-name=sub-service 9 | spring.cloud.consul.discovery.health-check-interval=120s 10 | spring.cloud.consul.discovery.tags=trial 11 | spring.cloud.consul.discovery.health-check-path=${server.contextPath}/health 12 | spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.int} 13 | 14 | 15 | zkServers=127.0.0.1 16 | #not used now 17 | workerId=${server.port}:${random.int} 18 | 19 | logging.level.com.yq=DEBUG 20 | logging.level.org.apache.http=OFF 21 | 22 | -------------------------------------------------------------------------------- /CuratorDemo/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, stdout, R 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | 6 | log4j.appender.stdout.layout.ConversionPattern=%5p - %m%n 7 | 8 | log4j.appender.R=org.apache.log4j.RollingFileAppender 9 | log4j.appender.R.File=zkinfo.log 10 | 11 | log4j.appender.R.MaxFileSize=100KB 12 | log4j.appender.R.MaxBackupIndex=1 13 | 14 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 15 | log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n 16 | 17 | log4j.logger.com.yq=INFO -------------------------------------------------------------------------------- /ELKDemo/elk_readme.md: -------------------------------------------------------------------------------- 1 | 2 | https://github.com/SpringDataElasticsearchDevs/spring-data-elasticsearch-sample-application 3 | 4 | https://github.com/spring-projects/spring-data-elasticsearch 5 | 6 | 7 | 8 | #使用1.5.15 或者1.5.12自带的spring-data-elasticsearch 9 | 访问ES serverVersion: 5.4.3 一直报错 10 | 11 | org.elasticsearch.transport.NodeDisconnectedException: [][192.168.1.101:9300][cluster:monitor/nodes/liveness] disconnected 12 | 13 | 升级到 最新的spring-data-search需要springboot升级 14 | http://127.0.0.1:9000/swagger-ui.html 15 | 16 | @JsonFormat (shape = JsonFormat.Shape.STRING, pattern ="yyyy-MM-dd'T'HH:mm:ss.SSSZZ"). 17 | 18 | @Field(type = FieldType.Date, index = FieldIndex.not_analyzed, store = true, 19 | format = DateFormat.custom, pattern = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'") 20 | private Date createDate; -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/ELKApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class ELKApplication { 10 | private static final Logger logger = LoggerFactory.getLogger(ELKApplication.class); 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(ELKApplication.class, args); 14 | logger.info("ELKApplication Start done."); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/domain/Director.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | 4 | import lombok.*; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by nasir on 14/11/17. 10 | */ 11 | @Getter 12 | @Setter 13 | @ToString 14 | @RequiredArgsConstructor 15 | public class Director { 16 | 17 | @NonNull 18 | private String name; 19 | 20 | private List movies; 21 | } -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/domain/Genre.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | import lombok.*; 4 | 5 | /** 6 | * Created by Nasir on 12-09-2015. 7 | */ 8 | @Getter 9 | @Setter 10 | @ToString 11 | @RequiredArgsConstructor 12 | public class Genre { 13 | 14 | @NonNull 15 | private String name; 16 | } 17 | -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/domain/Movie.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | import lombok.*; 4 | import org.springframework.data.annotation.Id; 5 | import org.springframework.data.elasticsearch.annotations.Document; 6 | import org.springframework.data.elasticsearch.annotations.Field; 7 | import org.springframework.data.elasticsearch.annotations.FieldType; 8 | 9 | import java.util.List; 10 | 11 | 12 | @Getter 13 | @Setter 14 | @ToString 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Document(indexName = "movie-store", type = "movie", shards = 1, replicas = 0) 18 | public class Movie { 19 | 20 | @Id 21 | private Long id; 22 | 23 | private String name; 24 | 25 | private Double rating; 26 | } -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/repository/LogRepository.java: -------------------------------------------------------------------------------- 1 | package com.yq.repository; 2 | 3 | import com.yq.domain.Director; 4 | import com.yq.domain.Log; 5 | import com.yq.domain.Movie; 6 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by Nasir on 12-09-2015. 13 | */ 14 | @Repository 15 | public interface LogRepository extends ElasticsearchRepository { 16 | 17 | List findByLevel(String level); 18 | } 19 | -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/repository/MovieRepository.java: -------------------------------------------------------------------------------- 1 | package com.yq.repository; 2 | 3 | import com.yq.domain.Director; 4 | import com.yq.domain.Movie; 5 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | 11 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 12 | import org.springframework.stereotype.Repository; 13 | 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Created by Nasir on 12-09-2015. 19 | */ 20 | @Repository 21 | public interface MovieRepository extends ElasticsearchRepository { 22 | 23 | List findByName(String name); 24 | List findByRatingBetween(Double start, Double end); 25 | } 26 | -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/service/ELKService.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * Simple to Introduction 9 | * className: ELKService 10 | * 11 | * @author EricYang 12 | * @version 2018/9/4 10:29 13 | */ 14 | @Service 15 | public class ELKService { 16 | @Autowired 17 | private ElasticsearchTemplate elasticsearchTemplate ; 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/service/LogService.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | 4 | import com.yq.domain.Log; 5 | import com.yq.repository.LogRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | import java.util.Optional; 11 | 12 | /** 13 | * Created by Nasir on 12-09-2015. 14 | */ 15 | @Service 16 | public class LogService { 17 | 18 | @Autowired 19 | private LogRepository logRepository; 20 | 21 | public List findByLevel(String level) { 22 | return logRepository.findByLevel(level); 23 | } 24 | 25 | public Optional findById(String id) { 26 | return logRepository.findById(id); 27 | } 28 | 29 | public Log addOneLog(Log log) { 30 | return logRepository.save(log); 31 | } 32 | 33 | public void deleteLog(String id) { 34 | logRepository.deleteById(id); 35 | } 36 | } -------------------------------------------------------------------------------- /ELKDemo/src/main/java/com/yq/service/MovieService.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | 4 | import com.yq.domain.Director; 5 | import com.yq.domain.Movie; 6 | import com.yq.repository.MovieRepository; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by Nasir on 12-09-2015. 15 | */ 16 | @Service 17 | public class MovieService { 18 | 19 | @Autowired 20 | private MovieRepository movieRepository; 21 | 22 | public List getByName(String name) { 23 | return movieRepository.findByName(name); 24 | } 25 | 26 | public List getByRatingInterval(Double start, Double end) { 27 | return movieRepository.findByRatingBetween(start, end); 28 | } 29 | 30 | public Movie addMovie(Movie movie) { 31 | return movieRepository.save(movie); 32 | } 33 | 34 | public void deleteMovie(Long id) { 35 | movieRepository.deleteById(id); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /ELKDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | server.port=9000 3 | 4 | 5 | #Cluster node port configuration 6 | spring.data.elasticsearch.cluster-name=docker-cluster 7 | spring.data.elasticsearch.cluster-nodes=192.168.119.134:9300 8 | spring.data.elasticsearch.repositories.enabled=true 9 | 10 | #add the format in Log class 11 | #spring.jackson.date-format=yyyy-MM-dd HH:mm:ss 12 | #spring.jackson.time-zone=GMT+8 -------------------------------------------------------------------------------- /EncryptDemo/EncryptDemo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /EncryptDemo/src/main/java/com/yq/symmetric/D3ESDemo.java: -------------------------------------------------------------------------------- 1 | package com.yq.symmetric; 2 | 3 | import org.apache.commons.codec.binary.Base64; 4 | 5 | /** 6 | * Created by EricYang on 2021/3/13. 7 | */ 8 | 9 | public class D3ESDemo { 10 | public static void main(String[] argv) throws Exception { 11 | ThreeDESECBKeyGenerator keyGenerator = new ThreeDESECBKeyGenerator(); 12 | String newKey = keyGenerator.get3DESKey(); 13 | System.out.println("newKey:" + newKey); 14 | ThreeDESECBUtil threeDES = new ThreeDESECBUtil(); 15 | //String key = "Abc123%^&"; 16 | //3des秘钥有长度要求的 168,112或56 位(对应密钥选项 1, 2, 3) 17 | String key = "wc3l+2LxAiYLqAtAx0klehDqKbVwduky"; 18 | 19 | String plaintext = "a1b2c3&*()123456"; 20 | byte[] encryptedBytes = threeDES.doEncryption(plaintext, key); 21 | System.out.println("plaintext String:" + plaintext); 22 | System.out.println("Encrypted bytes:" + encryptedBytes); 23 | System.out.println("Encrypted String:" + Base64.encodeBase64String(encryptedBytes)); 24 | System.out.println("Decrypted String:" + threeDES.doDecryption(encryptedBytes, key)); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EncryptDemo/src/main/java/com/yq/symmetric/ThreeDESECBKeyGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yq.symmetric; 2 | 3 | /** 4 | * Created by EricYang on 2021/3/13. 5 | */ 6 | 7 | import org.apache.commons.codec.binary.Base64; 8 | 9 | import javax.crypto.Cipher; 10 | import javax.crypto.KeyGenerator; 11 | import javax.crypto.SecretKey; 12 | 13 | class ThreeDESECBKeyGenerator { 14 | private KeyGenerator keyGenerator; 15 | private SecretKey desKey; 16 | private Cipher cipher; 17 | 18 | public ThreeDESECBKeyGenerator() throws Exception { 19 | // Generate the Key 20 | keyGenerator = KeyGenerator.getInstance("DESede"); 21 | desKey = keyGenerator.generateKey(); 22 | } 23 | 24 | public String get3DESKey() { 25 | return Base64.encodeBase64String(desKey.getEncoded()); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /EncryptDemo/src/main/java/com/yq/symmetric/ThreeDESECBUtil.java: -------------------------------------------------------------------------------- 1 | package com.yq.symmetric; 2 | 3 | /** 4 | * Created by EricYang on 2021/3/13. 5 | */ 6 | 7 | import org.apache.commons.codec.binary.Base64; 8 | 9 | import javax.crypto.Cipher; 10 | import javax.crypto.SecretKey; 11 | import javax.crypto.spec.SecretKeySpec; 12 | 13 | 14 | class ThreeDESECBUtil { 15 | private Cipher cipher; 16 | 17 | public ThreeDESECBUtil() throws Exception { 18 | // Create the cipher 19 | cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); 20 | } 21 | /* 22 | * 加密后密文不一定能按照string进行显示,一把会进行base64,然后保存到文件或者数据, 使用时 23 | */ 24 | public byte[] doEncryption(String plaintext, String threeDESKeyBase64String) throws Exception { 25 | // Initialize the cipher for encryption 26 | final SecretKey key = new SecretKeySpec(Base64.decodeBase64(threeDESKeyBase64String), "DESede"); 27 | cipher.init(Cipher.ENCRYPT_MODE, key); 28 | 29 | //sensitive information 30 | byte[] text = plaintext.getBytes(); 31 | 32 | // Encrypt the text 33 | byte[] textEncrypted = cipher.doFinal(text); 34 | 35 | return(textEncrypted); 36 | } 37 | 38 | public String doDecryption(byte[] s, String threeDESKeyBase64String) throws Exception { 39 | // Initialize the same cipher for decryption 40 | final SecretKey key = new SecretKeySpec(Base64.decodeBase64(threeDESKeyBase64String), "DESede"); 41 | cipher.init(Cipher.DECRYPT_MODE, key); 42 | 43 | // Decrypt the text 44 | byte[] textDecrypted = cipher.doFinal(s); 45 | 46 | return(new String(textDecrypted)); 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /ErrorControllerDemoSvc/src/main/java/com/yq/ErrorControllerApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ErrorControllerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ErrorControllerApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ErrorControllerDemoSvc/src/main/java/com/yq/controller/MyErrorController.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.controller; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | 8 | import org.springframework.boot.web.servlet.error.ErrorController; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | 12 | 13 | //@RestController 14 | @Controller 15 | public class MyErrorController implements ErrorController { 16 | 17 | // @Autowired 18 | // private ErrorAttributes errorAttributes; 19 | 20 | private static final String PATH = "/error"; 21 | 22 | @RequestMapping(value = PATH) 23 | public String error() { 24 | return "myError"; 25 | } 26 | 27 | 28 | @Override 29 | public String getErrorPath() { 30 | return PATH; 31 | } 32 | 33 | 34 | } -------------------------------------------------------------------------------- /ErrorControllerDemoSvc/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /ErrorControllerDemoSvc/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | server.port=5502 3 | 4 | spring.application.name=errorController-service 5 | 6 | error.whitelabel.enabled=false 7 | 8 | #security.user.password=none 9 | #security.basic.enabled=false 10 | -------------------------------------------------------------------------------- /ErrorControllerDemoSvc/src/main/resources/public/myErrorPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ErrorControllerDemoSvc/src/main/resources/public/myErrorPage.png -------------------------------------------------------------------------------- /ErrorControllerDemoSvc/src/main/resources/static/img/myErrorPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ErrorControllerDemoSvc/src/main/resources/static/img/myErrorPage.png -------------------------------------------------------------------------------- /ErrorControllerDemoSvc/src/main/resources/static/myErrorPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ErrorControllerDemoSvc/src/main/resources/static/myErrorPage.png -------------------------------------------------------------------------------- /ErrorControllerDemoSvc/src/main/resources/static/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #cccccc; 3 | font-family: arial,helvetica,sans-serif; 4 | } 5 | 6 | .bookHeadline { 7 | font-size: 12pt; 8 | font-weight: bold; 9 | } 10 | 11 | .bookDescription { 12 | font-size: 10pt; 13 | } 14 | 15 | label { 16 | font-weight: bold; 17 | } 18 | 19 | .error { 20 | color: red; 21 | } 22 | 23 | .errorPage { 24 | text-align:center; 25 | } 26 | 27 | .oops { 28 | font-size: 76pt; 29 | } -------------------------------------------------------------------------------- /ErrorControllerDemoSvc/src/main/resources/templates/myError.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 错误页面! 6 | 7 | 8 | 9 |
10 | 错误Path!
11 | 12 |

There seems to be a problem with the page you requested 13 | ().

14 |

15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /ErrorPageDemoSvc/ErrorPageSvc_README.md: -------------------------------------------------------------------------------- 1 | # ErrorPageDemoSvc 2 | 3 | http://127.0.0.1:5501/ 4 | http://localhost:5501/swagger-ui.html#/ 5 | 6 | 删除swagger的SwaggerConfig,静态资源,就是图片和css文件能正常加载了 7 | 8 | -------------------------------------------------------------------------------- /ErrorPageDemoSvc/src/main/java/com/yq/ErrorPageApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ErrorPageApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ErrorPageApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ErrorPageDemoSvc/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /ErrorPageDemoSvc/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | server.port=5501 3 | 4 | spring.application.name=error-service 5 | 6 | spring.mvc.static-path-pattern=/** 7 | spring.resources.chain.strategy.content.enabled=true 8 | spring.resources.chain.strategy.content.paths=/** 9 | spring.resources.static-locations=/static/css/,classpath:/static/images/,classpath:/static/js/,classpath:/static/ 10 | #spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/ 11 | 12 | #security.user.password=none 13 | #security.basic.enabled=false 14 | -------------------------------------------------------------------------------- /ErrorPageDemoSvc/src/main/resources/public/myErrorPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ErrorPageDemoSvc/src/main/resources/public/myErrorPage.png -------------------------------------------------------------------------------- /ErrorPageDemoSvc/src/main/resources/static/myErrorPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ErrorPageDemoSvc/src/main/resources/static/myErrorPage.png -------------------------------------------------------------------------------- /ErrorPageDemoSvc/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 错误页面! 8 | 9 | 10 | 11 |
12 | 错误Path!
13 | 14 |

There seems to be a problem with the page you requested 15 | ().

16 |

17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /EurekaCommoditySvc/src/main/java/com/yq/EurekaUserApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | 10 | 11 | public class EurekaUserApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(EurekaUserApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /EurekaCommoditySvc/src/main/java/com/yq/domain/Commodity.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: Commodity 12 | * 13 | * @author EricYang 14 | * @version 2018/6/30 0:13 15 | */ 16 | @Data 17 | public class Commodity { 18 | String id; 19 | String name; 20 | String description; 21 | String price; 22 | String count; 23 | String picUrl; 24 | Date onlineDate; 25 | } 26 | -------------------------------------------------------------------------------- /EurekaCommoditySvc/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | 2 | eureka: 3 | client: 4 | serviceUrl: 5 | defaultZone: http://localhost:7700/eureka/ 6 | 7 | server: 8 | port: 6602 9 | 10 | spring: 11 | application: 12 | name: commodity-service 13 | 14 | security: 15 | user: 16 | password: none 17 | basic: 18 | enabled: false 19 | -------------------------------------------------------------------------------- /EurekaServerDemo/src/main/java/com/yq/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 7 | 8 | @EnableEurekaServer 9 | @SpringBootApplication 10 | public class EurekaServerApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(EurekaServerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /EurekaServerDemo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7700 3 | 4 | eureka: 5 | instance: 6 | hostname: localhost 7 | client: 8 | registerWithEureka: false 9 | fetchRegistry: false 10 | serviceUrl: 11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /EurekaUserSvc/UserSvc_README.md: -------------------------------------------------------------------------------- 1 | # EurekaUserSvc 2 | 3 | http://127.0.0.1:7700/ 4 | http://localhost:6601/swagger-ui.html#/ 5 | 6 | -------------------------------------------------------------------------------- /EurekaUserSvc/src/main/java/com/yq/EurekaUserApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class EurekaUserApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(EurekaUserApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /EurekaUserSvc/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /EurekaUserSvc/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/EurekaUserSvc/src/main/resources/application.properties -------------------------------------------------------------------------------- /ExceptionDemo/README.md: -------------------------------------------------------------------------------- 1 | # SpringCloudTutorials 2 | 3 | http://127.0.0.1:8085/swagger-ui.html 4 | 5 | spring.mvc.throw-exception-if-no-handler-found=true 6 | 7 | @ExceptionHandler表示该方法可以处理的异常,可以多个,比如 8 | @ExceptionHandler({ NullPointerException.class, DataAccessException.class}) 9 | 也可以针对不同的异常写不同的方法。@ExceptionHandler(Exception.class)可以处理所有的异常类型。 10 | 11 | 12 | 13 | AfterReturningAdvice 14 | ThrowsAdvice 15 | MethodInterceptor 16 | 17 | 事务 与 Afterthrowing 冲突, 通过order解决 -------------------------------------------------------------------------------- /ExceptionDemo/src/main/java/com/yq/exceptiondemo/ExecptionDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq.exceptiondemo; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | 9 | @SpringBootApplication 10 | public class ExecptionDemoApplication { 11 | private static final Logger log = LoggerFactory.getLogger(ExecptionDemoApplication.class); 12 | 13 | public static void main(String[] args) { 14 | 15 | SpringApplication.run(ExecptionDemoApplication.class, args); 16 | log.info("Spring Boot start done!"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /ExceptionDemo/src/main/java/com/yq/exceptiondemo/config/SystemLog.java: -------------------------------------------------------------------------------- 1 | 2 | package com.yq.exceptiondemo.config; 3 | 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * Simple to Introduction 12 | * className: SystemLog 13 | * 14 | * @author EricYang 15 | * @version 2018/6/9 18:38 16 | */ 17 | 18 | @Target({ElementType.PARAMETER, ElementType.METHOD}) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | @Documented 21 | public @interface SystemLog { 22 | String description() default ""; 23 | } 24 | -------------------------------------------------------------------------------- /ExceptionDemo/src/main/java/com/yq/exceptiondemo/exception/BaseException.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.exceptiondemo.exception; 4 | 5 | import lombok.Data; 6 | 7 | @Data 8 | public class BaseException extends Throwable { 9 | private int code; 10 | private String myCause; 11 | 12 | 13 | public BaseException(int code, String myCause) { 14 | this.code = code; 15 | this.myCause = myCause; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ExceptionDemo/src/main/java/com/yq/exceptiondemo/exception/ComputerException.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.exceptiondemo.exception; 4 | 5 | import com.yq.exceptiondemo.utils.Constants; 6 | import lombok.Data; 7 | 8 | /** 9 | */ 10 | @Data 11 | public class ComputerException extends BaseException { 12 | 13 | public ComputerException(String cause) { 14 | super(Constants.DIVIDE_ERROR, cause); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ExceptionDemo/src/main/java/com/yq/exceptiondemo/service/ComputerService.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.exceptiondemo.service; 4 | 5 | import com.yq.exceptiondemo.exception.ComputerException; 6 | 7 | /** 8 | * Simple to Introduction 9 | * className: ComputerService 10 | 11 | */ 12 | public interface ComputerService { 13 | int divide(int a, int b); 14 | 15 | int divideCatchExecption(int a, int b) throws ComputerException; 16 | } -------------------------------------------------------------------------------- /ExceptionDemo/src/main/java/com/yq/exceptiondemo/service/impl/ComputerServiceImpl.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.exceptiondemo.service.impl; 4 | 5 | import com.yq.exceptiondemo.exception.ComputerException; 6 | import com.yq.exceptiondemo.service.ComputerService; 7 | import com.yq.exceptiondemo.utils.Constants; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | */ 12 | @Service 13 | public class ComputerServiceImpl implements ComputerService { 14 | 15 | @Override 16 | public int divide(int a, int b) { 17 | int result = a / b; 18 | return result; 19 | } 20 | 21 | @Override 22 | public int divideCatchExecption(int a, int b) throws ComputerException { 23 | int result = 0; 24 | try { 25 | result = a / b; 26 | } 27 | catch (Exception ex) { 28 | throw new ComputerException(ex.getMessage() + ", a:" + a + ", b:" + b); 29 | } 30 | 31 | return result; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ExceptionDemo/src/main/java/com/yq/exceptiondemo/utils/Constants.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.exceptiondemo.utils; 4 | 5 | /** 6 | * Simple to Introduction 7 | * className: Constants 8 | * 9 | * @author EricYang 10 | */ 11 | public class Constants { 12 | public static final int QUERY_OK = 001; 13 | public static final int POST_OK = 002; 14 | public static final int DELETE_OK = 003; 15 | public static final int PUT_OK = 004; 16 | 17 | public static final int DIVIDE_ERROR = 005; 18 | public static final int PARAMETER_ERROR = 006; 19 | } 20 | -------------------------------------------------------------------------------- /ExceptionDemo/src/main/java/com/yq/exceptiondemo/utils/ReturnResult.java: -------------------------------------------------------------------------------- 1 | package com.yq.exceptiondemo.utils; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONObject; 5 | import lombok.Data; 6 | 7 | /** 8 | */ 9 | @Data 10 | public class ReturnResult { 11 | private int code; 12 | private T obj; 13 | 14 | public ReturnResult(int code, T obj) { 15 | this.code = code; 16 | this.obj = obj; 17 | } 18 | 19 | @Override 20 | public String toString(){ 21 | JSONObject json = new JSONObject(); 22 | json.put("code", code); 23 | json.put("obj", obj.toString()); 24 | 25 | return json.toJSONString(); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ExceptionDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/ExceptionDemo/src/main/resources/application.properties -------------------------------------------------------------------------------- /GatewayConsulDemo/gatewayConsul_README.md: -------------------------------------------------------------------------------- 1 | # API gateway 2 | 3 | http://127.0.0.1:7443/ 4 | http://localhost:7443/swagger-ui.html#/ 5 | 6 | gateway启动 7 | 8 | http://127.0.0.1:7443/userapi/swagger-ui.html ---no token 9 | http://127.0.0.1:7443/userapi/swagger-ui.html?token=aaa# 10 | 11 | http://127.0.0.1:7001/user/users/2 ---直接访问user服务 12 | http://127.0.0.1:7443/userapi/user/users/2?token=aaa, 通过API网关访问user服务, 用户服务的所有path前面都有user 13 | 14 | 15 | consul agent -data-dir dir1 -node=192.168.1.102 -bind=192.168.1.102 -datacenter=dc1 -ui -server -bootstrap-expect 1 只能通过http://127.0.0.1:8500/ui/dc1/services 16 | 以该命令启动consul, 无法无法注册因为 17 | 2018-07-22 17:53:12.682 ERROR 17424 --- [ main] o.s.c.c.s.ConsulServiceRegistry : 18 | Error registering service with consul: NewService{id='saas-gateway-service', name='saas-gateway-service', 19 | tags=[trial, secure=false], address='localhost', port=7443, enableTagOverride=null, check=Check{script='null', interval='10s', ttl='null', http='http://localhost:7443/actuator/health', tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null'}, checks=null} 20 | com.ecwid.consul.transport.TransportException: org.apache.http.conn.HttpHostConnectException: Connect to 192.168.1.102:8500 [/192.168.1.102] failed: Connection refused: connect 21 | 22 | 23 | 必须修改application.properties, 将spring.cloud.consul.host=192.168.1.102 修改为spring.cloud.consul.host=127.0.0.1 -------------------------------------------------------------------------------- /GatewayConsulDemo/src/main/java/com/yq/filter/AuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.yq.filter; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 5 | import org.springframework.cloud.gateway.filter.GlobalFilter; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.server.reactive.ServerHttpResponse; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.reactive.function.BodyInserters; 11 | import org.springframework.web.reactive.function.server.ServerResponse; 12 | import org.springframework.web.server.ServerWebExchange; 13 | import reactor.core.publisher.Mono; 14 | 15 | /** 16 | * Simple to Introduction 17 | * className: AuthenticationFilter 18 | * 19 | * @author EricYang 20 | * @version 2018/7/11 18:56 21 | */ 22 | @Component 23 | @Slf4j 24 | public class AuthenticationFilter implements GlobalFilter, Ordered { 25 | 26 | @Override 27 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 28 | String token = exchange.getRequest().getQueryParams().getFirst("token"); 29 | log.info("token is "+ token); 30 | // if (token == null || token.isEmpty()) { 31 | // ServerHttpResponse response = exchange.getResponse(); 32 | // response.setStatusCode(HttpStatus.UNAUTHORIZED); 33 | // return exchange.getResponse().setComplete(); 34 | // } 35 | return chain.filter(exchange); 36 | } 37 | 38 | @Override 39 | public int getOrder() { 40 | return -200; 41 | } 42 | } -------------------------------------------------------------------------------- /GatewayConsulDemo/src/main/java/com/yq/filter/MyPostGatewayFilterFactory.java: -------------------------------------------------------------------------------- 1 | package com.yq.filter; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.gateway.filter.GatewayFilter; 5 | import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory; 6 | import org.springframework.http.server.reactive.ServerHttpRequest; 7 | import org.springframework.http.server.reactive.ServerHttpResponse; 8 | import org.springframework.stereotype.Component; 9 | import reactor.core.publisher.Mono; 10 | 11 | /** 12 | * Simple to Introduction 13 | * className: MyPreGatewayFilterFactory 14 | * 对于Post类型的Filter,SetStatus 15 | 代码将会在chain.filter(exchange).then()里面的代码运行。 16 | 17 | https://github.com/spring-cloud/spring-cloud-gateway/blob/master/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/AddResponseHeaderGatewayFilterFactory.java 18 | * @author EricYang 19 | * @version 2018/7/12 10:15 20 | */ 21 | @Component 22 | @Slf4j 23 | public class MyPostGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory { 24 | @Override 25 | public GatewayFilter apply(NameValueConfig config) { 26 | log.info("MyPostGatewayFilterFactory name={}, value={}", config.getName(), config.getValue()); 27 | 28 | return (exchange, chain) -> { 29 | exchange.getResponse().getHeaders().add(config.getName(), config.getValue()); 30 | 31 | return chain.filter(exchange); 32 | }; 33 | 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /GatewayConsulDemo/src/main/java/com/yq/filter/MyPreGatewayFilterFactory.java: -------------------------------------------------------------------------------- 1 | package com.yq.filter; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.gateway.filter.GatewayFilter; 5 | import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory; 6 | import org.springframework.http.server.reactive.ServerHttpRequest; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: MyPreGatewayFilterFactory 12 | * 个Pre类型的Filter,code将会在chain.filter() 之前被执行,代 13 | * @author EricYang 14 | * @version 2018/7/12 10:15 15 | */ 16 | @Component 17 | @Slf4j 18 | public class MyPreGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory { 19 | @Override 20 | public GatewayFilter apply(NameValueConfig config) { 21 | log.info("MyPreGatewayFilterFactory name={}, value={}", config.getName(), config.getValue()); 22 | return (exchange, chain) -> { 23 | ServerHttpRequest request = exchange.getRequest().mutate() 24 | .header(config.getName(), config.getValue()) 25 | .build(); 26 | return chain.filter(exchange.mutate().request(request).build()); 27 | }; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /GatewayConsulDemo/src/main/resources/Bapplication.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | spring.profiles.active=@spring.profiles.active@ 3 | spring.cloud.config.profile=@spring.profiles.active@ 4 | 5 | session.store-type=none 6 | 7 | spring.application.name=gateway-service 8 | server.port=7443 9 | 10 | spring.application.cloud.gateway.discovery.locator.enabled=true 11 | spring.application.cloud.gateway.routes.apiuser.uri=lb://user-service 12 | spring.application.cloud.gateway.routes.apiuser.predicates.Path=/userapi/** 13 | spring.application.cloud.gateway.routes.apiuser.filters.StripPrefix=1 14 | 15 | spring.application.cloud.gateway.routes.apioauth.uri=lb://oauth-service 16 | spring.application.cloud.gateway.routes.apioauth.predicates.Path=/oauthapi/** 17 | spring.application.cloud.gateway.routes.apioauth.filters.StripPrefix=1 18 | 19 | security.user.password=none 20 | security.basic.enabled=false 21 | 22 | logging.level.org.springframework.cloud.gateway=TRACE 23 | logging.level.org.springframework.http.server.reactive=DEBUG 24 | logging.level.org.springframework.web.reactive=DEBUG 25 | logging.level.reactor.ipc.netty=INFO 26 | logging.level.com.yq=DEBUG 27 | 28 | spring.cloud.consul.host=127.0.0.1 29 | spring.cloud.consul.port=8500 30 | spring.cloud.consul.discovery.service-name=gateway-service 31 | spring.cloud.consul.discovery.health-check-interval=120s 32 | spring.cloud.consul.discovery.instance-id=gateway-service 33 | spring.cloud.consul.discovery.tags=trial 34 | 35 | 36 | #actuator 37 | health.sensitive=true 38 | 39 | 40 | -------------------------------------------------------------------------------- /GatewayDemo/src/main/java/com/yq/filter/AuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.yq.filter; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 5 | import org.springframework.cloud.gateway.filter.GlobalFilter; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.server.reactive.ServerHttpResponse; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.reactive.function.BodyInserters; 11 | import org.springframework.web.reactive.function.server.ServerResponse; 12 | import org.springframework.web.server.ServerWebExchange; 13 | import reactor.core.publisher.Mono; 14 | 15 | /** 16 | * Simple to Introduction 17 | * className: AuthenticationFilter 18 | * 19 | * @author EricYang 20 | * @version 2018/7/11 18:56 21 | */ 22 | @Component 23 | @Slf4j 24 | public class AuthenticationFilter implements GlobalFilter, Ordered { 25 | 26 | @Override 27 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 28 | String token = exchange.getRequest().getQueryParams().getFirst("token"); 29 | log.info("token is "+ token); 30 | // if (token == null || token.isEmpty()) { 31 | // ServerHttpResponse response = exchange.getResponse(); 32 | // response.setStatusCode(HttpStatus.UNAUTHORIZED); 33 | // return exchange.getResponse().setComplete(); 34 | // } 35 | return chain.filter(exchange); 36 | } 37 | 38 | @Override 39 | public int getOrder() { 40 | return -200; 41 | } 42 | } -------------------------------------------------------------------------------- /GatewayDemo/src/main/java/com/yq/filter/MyPostGatewayFilterFactory.java: -------------------------------------------------------------------------------- 1 | package com.yq.filter; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.gateway.filter.GatewayFilter; 5 | import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory; 6 | import org.springframework.http.server.reactive.ServerHttpRequest; 7 | import org.springframework.http.server.reactive.ServerHttpResponse; 8 | import org.springframework.stereotype.Component; 9 | import reactor.core.publisher.Mono; 10 | 11 | /** 12 | * Simple to Introduction 13 | * className: MyPreGatewayFilterFactory 14 | * 对于Post类型的Filter,SetStatus 15 | 代码将会在chain.filter(exchange).then()里面的代码运行。 16 | 17 | https://github.com/spring-cloud/spring-cloud-gateway/blob/master/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/AddResponseHeaderGatewayFilterFactory.java 18 | * @author EricYang 19 | * @version 2018/7/12 10:15 20 | */ 21 | @Component 22 | @Slf4j 23 | public class MyPostGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory { 24 | @Override 25 | public GatewayFilter apply(NameValueConfig config) { 26 | log.info("MyPostGatewayFilterFactory name={}, value={}", config.getName(), config.getValue()); 27 | 28 | return (exchange, chain) -> { 29 | exchange.getResponse().getHeaders().add(config.getName(), config.getValue()); 30 | 31 | return chain.filter(exchange); 32 | }; 33 | 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /GatewayDemo/src/main/java/com/yq/filter/MyPreGatewayFilterFactory.java: -------------------------------------------------------------------------------- 1 | package com.yq.filter; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.gateway.filter.GatewayFilter; 5 | import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory; 6 | import org.springframework.http.server.reactive.ServerHttpRequest; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: MyPreGatewayFilterFactory 12 | * 个Pre类型的Filter,code将会在chain.filter() 之前被执行,代 13 | * @author EricYang 14 | * @version 2018/7/12 10:15 15 | */ 16 | @Component 17 | @Slf4j 18 | public class MyPreGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory { 19 | @Override 20 | public GatewayFilter apply(NameValueConfig config) { 21 | log.info("MyPreGatewayFilterFactory name={}, value={}", config.getName(), config.getValue()); 22 | return (exchange, chain) -> { 23 | ServerHttpRequest request = exchange.getRequest().mutate() 24 | .header(config.getName(), config.getValue()) 25 | .build(); 26 | return chain.filter(exchange.mutate().request(request).build()); 27 | }; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /GatewayDemo/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | #session存储 2 | session: 3 | store-type: none 4 | 5 | 6 | #将 hystrix 的超时时间禁用掉 7 | #hystrix: 8 | # command: 9 | # default: 10 | # execution: 11 | # timeout: 12 | # enabled: false 13 | 14 | 15 | 16 | 17 | #zuul: 18 | # routes: 19 | # echo: 20 | # path: /myusers/** 21 | # serviceId: myusers-service 22 | # stripPrefix: true 23 | 24 | # hystrix: 25 | # command: 26 | # myusers-service: 27 | # execution: 28 | # isolation: 29 | # thread: 30 | # timeoutInMilliseconds: ... 31 | # 32 | # myusers-service: 33 | # ribbon: 34 | # NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList 35 | # ListOfServers: http://example1.com,http://example2.com 36 | # ConnectTimeout: 1000 37 | # ReadTimeout: 3000 38 | # MaxTotalHttpConnections: 500 39 | # MaxConnectionsPerHost: 100 -------------------------------------------------------------------------------- /GatewayDemo/zuul_README.md: -------------------------------------------------------------------------------- 1 | # APIZUUL 2 | 3 | http://127.0.0.1:7700/ 4 | http://localhost:6601/swagger-ui.html#/ 5 | 6 | gateway启动 7 | 8 | http://127.0.0.1:6604/userapi/swagger-ui.html ---no token 9 | http://127.0.0.1:6604/userapi/swagger-ui.html?token=aaa# 10 | 11 | http://127.0.0.1:6601/user/users/2 ---直接访问user服务 12 | http://127.0.0.1:6604/userapi/user/users/2?token=aaa, 通过API网关访问user服务, 用户服务的所有path前面都有user 13 | 14 | 15 | 启用了 16 | #而不是我们期望的去掉userapi,只保留**部分 17 | filters: 18 | - StripPrefix=1 19 | - MyPre=foo, bar 20 | - AddRequestParameter=foo1, bar1 21 | - UrlFilter 22 | - AddResponseHeader=X-Response-Foo, Bar2 23 | 之后urlFilter会对url进行过滤 24 | http://127.0.0.1:6604/userapi2/user/users/2, 可以工作,但是http://127.0.0.1:6604/userapi/user/users/2不行 25 | -------------------------------------------------------------------------------- /GatewayOAuthDemo/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | #session存储 2 | session: 3 | store-type: none 4 | 5 | 6 | #将 hystrix 的超时时间禁用掉 7 | #hystrix: 8 | # command: 9 | # default: 10 | # execution: 11 | # timeout: 12 | # enabled: false 13 | 14 | 15 | 16 | 17 | #zuul: 18 | # routes: 19 | # echo: 20 | # path: /myusers/** 21 | # serviceId: myusers-service 22 | # stripPrefix: true 23 | 24 | # hystrix: 25 | # command: 26 | # myusers-service: 27 | # execution: 28 | # isolation: 29 | # thread: 30 | # timeoutInMilliseconds: ... 31 | # 32 | # myusers-service: 33 | # ribbon: 34 | # NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList 35 | # ListOfServers: http://example1.com,http://example2.com 36 | # ConnectTimeout: 1000 37 | # ReadTimeout: 3000 38 | # MaxTotalHttpConnections: 500 39 | # MaxConnectionsPerHost: 100 -------------------------------------------------------------------------------- /GatewayOAuthDemo/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Demo 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

Demo

16 |
17 | 18 | -------------------------------------------------------------------------------- /HttpSessionDemo/docs/redis_httpsession.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/HttpSessionDemo/docs/redis_httpsession.png -------------------------------------------------------------------------------- /HttpSessionDemo/src/main/java/sample/HttpSessionDemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; 22 | 23 | /** 24 | * @author Rob Winch 25 | */ 26 | @SpringBootApplication 27 | public class HttpSessionDemoApplication { 28 | 29 | public static void main(String[] args) { 30 | SpringApplication.run(HttpSessionDemoApplication.class, args); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /HttpSessionDemo/src/main/java/sample/config/Config.java: -------------------------------------------------------------------------------- 1 | package sample.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; 6 | 7 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; 8 | /** 9 | * Simple to Introduction 10 | * className: Config 11 | * 12 | * @author EricYang 13 | * @version 2018/8/4 11:06 14 | */ 15 | 16 | 17 | @Configuration 18 | @EnableRedisHttpSession 19 | public class Config { 20 | 21 | @Bean 22 | public LettuceConnectionFactory connectionFactory() { 23 | return new LettuceConnectionFactory(); 24 | } 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /HttpSessionDemo/src/main/java/sample/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample.config; 18 | 19 | import org.springframework.context.annotation.Configuration; 20 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 21 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 22 | 23 | @Configuration 24 | public class WebMvcConfig implements WebMvcConfigurer { 25 | 26 | @Override 27 | public void addViewControllers(ViewControllerRegistry registry) { 28 | registry.addViewController("/").setViewName("index"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /HttpSessionDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.redis.database=0 3 | spring.redis.host=127.0.0.1 4 | spring.redis.port=6379 5 | #spring.redis.password=xxxx 6 | spring.redis.pool.maxa-ctive=8 7 | spring.redis.pool.max-wait=-1 8 | spring.redis.pool.max-idle=8 9 | spring.redis.pool.min-idle=0 10 | spring.redis.timeout=0 11 | 12 | spring.security.user.password=password 13 | spring.security.user.username=tom -------------------------------------------------------------------------------- /HttpSessionDemo/src/main/resources/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/HttpSessionDemo/src/main/resources/static/favicon.ico -------------------------------------------------------------------------------- /HttpSessionDemo/src/main/resources/static/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/HttpSessionDemo/src/main/resources/static/images/logo.png -------------------------------------------------------------------------------- /HttpSessionDemo/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Secured Content 4 | 5 | 6 |
7 |

Secured Page

8 |

This page is secured using Spring Boot, Spring Session, and Spring Security.

9 |
10 | 11 | 12 | -------------------------------------------------------------------------------- /HystrixDemo/img/hytrix01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/HystrixDemo/img/hytrix01.png -------------------------------------------------------------------------------- /HystrixDemo/src/main/java/com/yq/HystrixDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 10 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 11 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 12 | 13 | @SpringBootApplication 14 | @EnableHystrix 15 | @EnableHystrixDashboard 16 | @EnableDiscoveryClient 17 | @EnableCircuitBreaker 18 | //@EnableTurbine 19 | @EnableFeignClients(basePackages = {"com.yq.client"}) 20 | public class HystrixDemoApplication { 21 | private static final Logger logger = LoggerFactory.getLogger(HystrixDemoApplication.class); 22 | 23 | public static void main(String[] args) { 24 | SpringApplication.run(HystrixDemoApplication.class, args); 25 | logger.info("HystrixDemoApplication Start done."); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /HystrixDemo/src/main/java/com/yq/client/UserServiceClient.java: -------------------------------------------------------------------------------- 1 | package com.yq.client; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: UserServiceClient 12 | * 13 | * @author EricYang 14 | * @version 2018/10/14 21:06 15 | */ 16 | 17 | 18 | @FeignClient(value = "user-service", fallback = UserServiceClientFallbackFactory.class) 19 | @Component 20 | public interface UserServiceClient { 21 | @RequestMapping(value = "/v1/users/{userId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") 22 | String getUserDetail(@PathVariable("userId") String userId); 23 | } -------------------------------------------------------------------------------- /HystrixDemo/src/main/java/com/yq/client/UserServiceClientFallbackFactory.java: -------------------------------------------------------------------------------- 1 | package com.yq.client; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Simple to Introduction 8 | * className: UserServiceClientFallbackFactory 9 | * 10 | * @author EricYang 11 | * @version 2018/10/14 21:07 12 | */ 13 | 14 | 15 | @Component 16 | @Slf4j 17 | public class UserServiceClientFallbackFactory implements UserServiceClient{ 18 | @Override 19 | public String getUserDetail(String userId) { 20 | log.error("Fallback2, userId={}", userId); 21 | return "user-service not available2 when query '" + userId + "'"; 22 | } 23 | } -------------------------------------------------------------------------------- /HystrixDemo/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /HystrixDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | spring.profiles.active=@spring.profiles.active@ 3 | spring.cloud.config.profile=@spring.profiles.active@ 4 | 5 | session.store-type=none 6 | 7 | spring.application.name=hystrix-user-service 8 | server.port=7009 9 | 10 | 11 | security.user.password=none 12 | security.basic.enabled=false 13 | 14 | 15 | logging.level.com.yq=DEBUG 16 | 17 | spring.cloud.consul.host=127.0.0.1 18 | spring.cloud.consul.port=8500 19 | spring.cloud.consul.discovery.service-name=${spring.application.name} 20 | spring.cloud.consul.discovery.health-check-interval=120s 21 | spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.int} 22 | spring.cloud.consul.discovery.tags=trial 23 | spring.cloud.consul.discovery.prefer-ip-address=true 24 | spring.cloud.consul.discovery.healthCheckCriticalTimeout=2m 25 | spring.cloud.consul.enabled=true 26 | 27 | feign.hystrix.enabled=true 28 | 29 | feign.compression.request.enabled=true 30 | feign.compression.response.enabled=true 31 | feign.compression.request.mime-types=text/xml,application/xml,application/json 32 | feign.compression.request.min-request-size=2048 33 | 34 | logging.level.com.yq.client.UserServiceClient=DEBUG 35 | 36 | #actuator 37 | health.sensitive=true 38 | 39 | turbine.app-config=commodity-service,user-service 40 | turbine.aggregator.clusterConfig=default 41 | turbine.clusterNameExpression=new String("default") 42 | turbine.combine-host=true 43 | turbine.instanceUrlSuffix.default=actuator/hystrix.stream 44 | 45 | 46 | -------------------------------------------------------------------------------- /HystrixTimeoutDemo/img/hytrix01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/HystrixTimeoutDemo/img/hytrix01.png -------------------------------------------------------------------------------- /HystrixTimeoutDemo/src/main/java/com/yq/HystrixDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | 10 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 11 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 12 | import org.springframework.cloud.openfeign.EnableFeignClients; 13 | 14 | @SpringBootApplication 15 | @EnableHystrix 16 | @EnableHystrixDashboard 17 | @EnableDiscoveryClient 18 | @EnableCircuitBreaker 19 | //@EnableTurbine 20 | @EnableFeignClients(basePackages = {"com.yq.client"}) 21 | public class HystrixDemoApplication { 22 | private static final Logger logger = LoggerFactory.getLogger(HystrixDemoApplication.class); 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(HystrixDemoApplication.class, args); 26 | logger.info("HystrixDemoApplication Start done."); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /HystrixTimeoutDemo/src/main/java/com/yq/client/UserServiceClient.java: -------------------------------------------------------------------------------- 1 | package com.yq.client; 2 | 3 | 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | 11 | /** 12 | * Simple to Introduction 13 | * className: UserServiceClient 14 | * 15 | * @author EricYang 16 | * @version 2018/10/14 21:06 17 | */ 18 | 19 | 20 | @FeignClient(value = "user-service", fallback = UserServiceClientFallbackFactory.class) 21 | @Component 22 | public interface UserServiceClient { 23 | @RequestMapping(value = "/v1/users/{userId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") 24 | String getUserDetail(@PathVariable("userId") String userId); 25 | 26 | @RequestMapping(value = "/v1/usersWithSleep/{userId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") 27 | String getUserDetail(@PathVariable("userId") String userId, @RequestParam("sleepTimeMillis") Long sleepTimeMillis); 28 | } -------------------------------------------------------------------------------- /HystrixTimeoutDemo/src/main/java/com/yq/client/UserServiceClientFallbackFactory.java: -------------------------------------------------------------------------------- 1 | package com.yq.client; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Simple to Introduction 8 | * className: UserServiceClientFallbackFactory 9 | * 10 | * @author EricYang 11 | * @version 2018/10/14 21:07 12 | */ 13 | 14 | 15 | @Component 16 | @Slf4j 17 | public class UserServiceClientFallbackFactory implements UserServiceClient{ 18 | @Override 19 | public String getUserDetail(String userId) { 20 | log.error("Fallback2, userId={}", userId); 21 | return "user-service not available2 when query '" + userId + "'"; 22 | } 23 | 24 | @Override 25 | public String getUserDetail(String userId, Long sleepTimeMillis) { 26 | log.error("Fallback2 sleep, userId={}", userId); 27 | return "user-service not available2 when query '" + userId + "'," + sleepTimeMillis; 28 | } 29 | } -------------------------------------------------------------------------------- /HystrixTimeoutDemo/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /HystrixTimeoutDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | spring.profiles.active=@spring.profiles.active@ 3 | spring.cloud.config.profile=@spring.profiles.active@ 4 | 5 | session.store-type=none 6 | 7 | spring.application.name=hystrix-user-service 8 | server.port=7009 9 | 10 | logging.level.com.yq=DEBUG 11 | 12 | spring.cloud.consul.host=127.0.0.1 13 | spring.cloud.consul.port=8500 14 | spring.cloud.consul.discovery.service-name=${spring.application.name} 15 | spring.cloud.consul.discovery.health-check-interval=120s 16 | spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}:${random.int} 17 | spring.cloud.consul.discovery.tags=trial 18 | spring.cloud.consul.discovery.prefer-ip-address=true 19 | spring.cloud.consul.discovery.healthCheckCriticalTimeout=2m 20 | spring.cloud.consul.enabled=true 21 | 22 | feign.hystrix.enabled=false 23 | 24 | feign.compression.request.enabled=true 25 | feign.compression.response.enabled=true 26 | feign.compression.request.mime-types=text/xml,application/xml,application/json 27 | feign.compression.request.min-request-size=2048 28 | 29 | logging.level.com.yq.client.UserServiceClient=DEBUG 30 | 31 | hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 32 | ribbon.ConnectTimeout=30000 33 | ribbon.ReadTimeout=3000 34 | hystrix.command.user-service.execution.isolation.thread.timeoutInMilliseconds=3500 35 | 36 | #actuator 37 | health.sensitive=true 38 | 39 | turbine.app-config=commodity-service,user-service 40 | turbine.aggregator.clusterConfig=default 41 | turbine.clusterNameExpression=new String("default") 42 | turbine.combine-host=true 43 | turbine.instanceUrlSuffix.default=actuator/hystrix.stream 44 | 45 | 46 | -------------------------------------------------------------------------------- /Neo4jDemo2/docs/sprinboot_springDataNeo4j版本关系.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/Neo4jDemo2/docs/sprinboot_springDataNeo4j版本关系.png -------------------------------------------------------------------------------- /Neo4jDemo2/src/main/java/movies/spring/data/neo4j/SampleMovieApplication.java: -------------------------------------------------------------------------------- 1 | package movies.spring.data.neo4j; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; 7 | import org.springframework.transaction.annotation.EnableTransactionManagement; 8 | 9 | /** 10 | * @author Michael Hunger 11 | * @author Mark Angrish 12 | */ 13 | @SpringBootApplication 14 | @EnableNeo4jRepositories("movies.spring.data.neo4j.repositories") 15 | public class SampleMovieApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(SampleMovieApplication.class, args); 19 | } 20 | } -------------------------------------------------------------------------------- /Neo4jDemo2/src/main/java/movies/spring/data/neo4j/controller/MovieController.java: -------------------------------------------------------------------------------- 1 | package movies.spring.data.neo4j.controller; 2 | 3 | import java.util.Collection; 4 | import java.util.Map; 5 | 6 | import movies.spring.data.neo4j.domain.Movie; 7 | import movies.spring.data.neo4j.services.MovieService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestParam; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | /** 15 | * @author Mark Angrish 16 | * @author Michael J. Simons 17 | */ 18 | @RestController 19 | @RequestMapping("/") 20 | public class MovieController { 21 | 22 | private final MovieService movieService; 23 | 24 | public MovieController(MovieService movieService) { 25 | this.movieService = movieService; 26 | } 27 | 28 | @GetMapping("/graph") 29 | public Map graph(@RequestParam(value = "limit",required = false) Integer limit) { 30 | return movieService.graph(limit == null ? 100 : limit); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Neo4jDemo2/src/main/java/movies/spring/data/neo4j/domain/Movie.java: -------------------------------------------------------------------------------- 1 | package movies.spring.data.neo4j.domain; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 7 | import org.neo4j.ogm.annotation.GeneratedValue; 8 | import org.neo4j.ogm.annotation.Id; 9 | import org.neo4j.ogm.annotation.NodeEntity; 10 | import org.neo4j.ogm.annotation.Relationship; 11 | 12 | /** 13 | * @author Mark Angrish 14 | */ 15 | @NodeEntity 16 | public class Movie { 17 | 18 | @Id 19 | @GeneratedValue 20 | private Long id; 21 | private String title; 22 | private int released; 23 | private String tagline; 24 | 25 | @JsonIgnoreProperties("movie") 26 | @Relationship(type = "ACTED_IN", direction = Relationship.INCOMING) 27 | private List roles; 28 | 29 | public Movie() { 30 | } 31 | 32 | public Movie(String title, int released, String tagline) { 33 | this.title = title; 34 | this.released = released; 35 | this.tagline = tagline; 36 | } 37 | 38 | public Long getId() { 39 | return id; 40 | } 41 | public void setId(Long id) { 42 | this.id = id; 43 | } 44 | 45 | public String getTitle() { 46 | return title; 47 | } 48 | 49 | public int getReleased() { 50 | return released; 51 | } 52 | 53 | public String getTagline() { 54 | return tagline; 55 | } 56 | 57 | public List getRoles() { 58 | return roles; 59 | } 60 | 61 | public void addRole(Role role) { 62 | if (this.roles == null) { 63 | this.roles = new ArrayList<>(); 64 | } 65 | this.roles.add(role); 66 | } 67 | } -------------------------------------------------------------------------------- /Neo4jDemo2/src/main/java/movies/spring/data/neo4j/domain/Person.java: -------------------------------------------------------------------------------- 1 | package movies.spring.data.neo4j.domain; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 8 | import org.neo4j.ogm.annotation.GeneratedValue; 9 | import org.neo4j.ogm.annotation.Id; 10 | import org.neo4j.ogm.annotation.NodeEntity; 11 | import org.neo4j.ogm.annotation.Relationship; 12 | 13 | /** 14 | * @author Mark Angrish 15 | */ 16 | @NodeEntity 17 | public class Person { 18 | 19 | @Id 20 | @GeneratedValue 21 | private Long id; 22 | private String name; 23 | private int born; 24 | 25 | @Relationship(type = "ACTED_IN") 26 | private List movies = new ArrayList<>(); 27 | 28 | public Person() { 29 | } 30 | 31 | public Person(String name, int born) { 32 | this.name = name; 33 | this.born = born; 34 | } 35 | 36 | public Long getId() { 37 | return id; 38 | } 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public int getBorn() { 45 | return born; 46 | } 47 | 48 | public List getMovies() { 49 | return movies; 50 | } 51 | } -------------------------------------------------------------------------------- /Neo4jDemo2/src/main/java/movies/spring/data/neo4j/domain/Role.java: -------------------------------------------------------------------------------- 1 | package movies.spring.data.neo4j.domain; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.fasterxml.jackson.annotation.JsonIgnore; 7 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 8 | import org.neo4j.ogm.annotation.*; 9 | 10 | /** 11 | * @author Mark Angrish 12 | */ 13 | @RelationshipEntity(type = "ACTED_IN") 14 | public class Role { 15 | 16 | @Id 17 | @GeneratedValue 18 | private Long id; 19 | private List roles = new ArrayList<>(); 20 | 21 | @StartNode 22 | private Person person; 23 | 24 | @EndNode 25 | private Movie movie; 26 | 27 | public Role() { 28 | } 29 | 30 | public Role(Movie movie, Person actor) { 31 | this.movie = movie; 32 | this.person = actor; 33 | } 34 | 35 | public Long getId() { 36 | return id; 37 | } 38 | 39 | public List getRoles() { 40 | return roles; 41 | } 42 | 43 | public Person getPerson() { 44 | return person; 45 | } 46 | 47 | public Movie getMovie() { 48 | return movie; 49 | } 50 | 51 | public void addRoleName(String name) { 52 | if (this.roles == null) { 53 | this.roles = new ArrayList<>(); 54 | } 55 | this.roles.add(name); 56 | } 57 | } -------------------------------------------------------------------------------- /Neo4jDemo2/src/main/java/movies/spring/data/neo4j/repositories/MovieRepository.java: -------------------------------------------------------------------------------- 1 | package movies.spring.data.neo4j.repositories; 2 | 3 | import java.util.Collection; 4 | 5 | import movies.spring.data.neo4j.domain.Movie; 6 | import org.springframework.data.neo4j.annotation.Query; 7 | import org.springframework.data.neo4j.repository.Neo4jRepository; 8 | import org.springframework.data.repository.query.Param; 9 | import org.springframework.data.rest.core.annotation.RepositoryRestResource; 10 | 11 | /** 12 | * @author Michael Hunger 13 | * @author Mark Angrish 14 | * @author Michael J. Simons 15 | */ 16 | @RepositoryRestResource(collectionResourceRel = "movies", path = "movies") 17 | public interface MovieRepository extends Neo4jRepository { 18 | 19 | Movie findByTitle(@Param("title") String title); 20 | 21 | Collection findByTitleLike(@Param("title") String title); 22 | 23 | @Query("MATCH (m:Movie)<-[r:ACTED_IN]-(a:Person) RETURN m,r,a LIMIT {limit}") 24 | Collection graph(@Param("limit") int limit); 25 | } -------------------------------------------------------------------------------- /Neo4jDemo2/src/main/java/movies/spring/data/neo4j/repositories/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package movies.spring.data.neo4j.repositories; 2 | 3 | import movies.spring.data.neo4j.domain.Person; 4 | import org.springframework.data.neo4j.repository.Neo4jRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @author pdtyreus 9 | * @author Mark Angrish 10 | */ 11 | public interface PersonRepository extends Neo4jRepository { 12 | 13 | Person findByName(String name); 14 | 15 | } -------------------------------------------------------------------------------- /Neo4jDemo2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #org.springframework.data.rest.level=DEBUG 2 | #debug: true 3 | spring.data.neo4j.uri=bolt://localhost 4 | spring.data.neo4j.username=neo4j 5 | spring.data.neo4j.password=neo4j123 6 | -------------------------------------------------------------------------------- /OAuthDemo/README_OAUTH.md: -------------------------------------------------------------------------------- 1 | # SpringCloudTutorials 2 | 3 | https://gitee.com/api/v5/swagger#/getV5User 4 | https://gitee.com/api/v5/oauth_doc -------------------------------------------------------------------------------- /OAuthDemo/src/main/java/com/yq/SocialApplication.java: -------------------------------------------------------------------------------- 1 | 2 | package com.yq; 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 7 | 8 | @SpringBootApplication 9 | @EnableOAuth2Sso 10 | public class SocialApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(SocialApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /OAuthDemo/src/main/java/com/yq/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.yq.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import java.security.Principal; 7 | import java.util.LinkedHashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * Simple to Introduction 12 | * className: UserController 13 | * 14 | * @author EricYang 15 | * @version 2018/8/6 11:34 16 | */ 17 | @RestController 18 | public class UserController { 19 | @RequestMapping({ "/user", "/me" }) 20 | public Map user(Principal principal) { 21 | Map map = new LinkedHashMap<>(); 22 | map.put("name", principal.getName()); 23 | return map; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /OAuthDemo/src/main/resources/Bapplication.yml: -------------------------------------------------------------------------------- 1 | security: 2 | oauth2: 3 | client: 4 | clientId: ffc92fdfad5460e396de 5 | clientSecret: 549aff048e5d0e8b6f39873628bac08011ca77b4 6 | accessTokenUri: https://github.com/login/oauth/access_token 7 | userAuthorizationUri: https://github.com/login/oauth/authorize 8 | clientAuthenticationScheme: form 9 | resource: 10 | userInfoUri: https://api.github.com/user 11 | 12 | logging: 13 | level: 14 | org.springframework.security: DEBUG -------------------------------------------------------------------------------- /OAuthDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.cloud.consul.host=127.0.0.1 3 | spring.cloud.consul.port=8500 4 | spring.cloud.consul.discovery.service-name=oauth-service 5 | spring.cloud.consul.discovery.health-check-interval=10s 6 | spring.cloud.consul.discovery.instance-id=oauth-service 7 | spring.cloud.consul.discovery.tags=trial 8 | 9 | security.oauth2.client.clientId=ffc92fdfad5460e396de 10 | security.oauth2.client.clientSecret=549aff048e5d0e8b6f39873628bac08011ca77b4 11 | security.oauth2.client.accessTokenUri=https://github.com/login/oauth/access_token 12 | security.oauth2.client.userAuthorizationUri=https://github.com/login/oauth/authorize 13 | security.oauth2.client.clientAuthenticationScheme=form 14 | security.oauth2.resource.userInfoUri=https://api.github.com/user 15 | 16 | logging.level.org.springframework.security=DEBUG -------------------------------------------------------------------------------- /OAuthDemo/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Demo 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

Demo

16 |
17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringCloudTutorials -------------------------------------------------------------------------------- /RabbitMqDemo/src/main/java/com/yq/RabbitMQApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @Slf4j 9 | public class RabbitMQApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(RabbitMQApplication.class, args); 13 | log.info("RabbitMQApplication Start done."); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /RabbitMqDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/RabbitMqDemo/src/main/resources/application.properties -------------------------------------------------------------------------------- /RedisCacheBoot15Demo/README_redisCacheSpringBoot15.md: -------------------------------------------------------------------------------- 1 | ##spring-data-redis cache 2 | 3 | 4 | > [官方文档](#official_docs) 5 | > 6 | > [注意问题](#notes_faq) 7 | > 8 | 9 | https://www.journaldev.com/18141/spring-boot-redis-cache 10 | post man , get 11 | http://127.0.0.1:8080/1 12 | http://127.0.0.1:8080/1 13 | http://127.0.0.1:8080/2 14 | http://127.0.0.1:8080/2 15 | 16 | 17 | put http://127.0.0.1:8080/update 18 | 19 | {"id":4,"name":"ZhangSan","followers":500} 20 | 21 | Redis Cache Limits 22 | 23 | Although Redis is very fast, it still has no limits on storing any amount of data on a 64-bit system. It can only store 3GB of data on a 32-bit system. More available memory can result into a more hit ratio but this will tend to cease once too much memory is occupied by Redis. 24 | When cache size reaches the memory limit, old data is removed to make place for new one. 25 | 26 | 27 | -------------------------------------------------------------------------------- /RedisCacheBoot15Demo/src/main/java/com/yq/RedisCacheApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import com.yq.domain.User; 4 | import com.yq.service.UserRepository; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.CommandLineRunner; 9 | import org.springframework.boot.SpringApplication; 10 | import org.springframework.boot.autoconfigure.SpringBootApplication; 11 | import org.springframework.cache.annotation.EnableCaching; 12 | 13 | @SpringBootApplication 14 | @EnableCaching 15 | public class RedisCacheApplication implements CommandLineRunner { 16 | 17 | private final Logger LOG = LoggerFactory.getLogger(getClass()); 18 | 19 | @Autowired 20 | private UserRepository userRepository; 21 | 22 | 23 | public static void main(String[] args) { 24 | SpringApplication.run(RedisCacheApplication.class, args); 25 | } 26 | 27 | @Override 28 | public void run(String... strings) { 29 | //Populating embedded database here 30 | LOG.info("Saving users. Current user count is {}.", userRepository.count()); 31 | User shubham = new User("Shubham", 2000); 32 | User pankaj = new User("Pankaj", 29000); 33 | User lewis = new User("Lewis", 550); 34 | 35 | userRepository.save(shubham); 36 | userRepository.save(pankaj); 37 | userRepository.save(lewis); 38 | LOG.info("Done saving users. Data: {}.", userRepository.findAll()); 39 | } 40 | } -------------------------------------------------------------------------------- /RedisCacheBoot15Demo/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import javax.persistence.SequenceGenerator; 10 | import java.io.Serializable; 11 | /** 12 | * Simple to Introduction 13 | * className: User 14 | * 15 | * @author EricYang 16 | * @version 2018/8/5 18:43 17 | */ 18 | 19 | @Entity 20 | @Data 21 | public class User implements Serializable { 22 | 23 | private static final long serialVersionUID = 7156526077883281623L; 24 | 25 | @Id 26 | @SequenceGenerator(name = "SEQ_GEN", sequenceName = "SEQ_USER", allocationSize = 1) 27 | @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN") 28 | private Long id; 29 | private String name; 30 | private long followers; 31 | 32 | public User() { 33 | } 34 | 35 | public User(String name, long followers) { 36 | this.name = name; 37 | this.followers = followers; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return String.format("User{id=%d, name='%s', followers=%d}", id, name, followers); 43 | } 44 | //{"id":3. "name":"ZhangSan", "followers":500} 45 | } -------------------------------------------------------------------------------- /RedisCacheBoot15Demo/src/main/java/com/yq/service/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | import com.yq.domain.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * Simple to Introduction 9 | * className: UserRepository 10 | * 11 | * @author EricYang 12 | * @version 2018/8/5 18:44 13 | */ 14 | 15 | @Repository 16 | public interface UserRepository extends JpaRepository{ 17 | 18 | } 19 | -------------------------------------------------------------------------------- /RedisCacheBoot15Demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | # Redis Config 3 | spring.cache.type=redis 4 | spring.redis.host=localhost 5 | spring.redis.port=6379 -------------------------------------------------------------------------------- /RedisDemo/src/main/java/com/yq/RedisDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | 5 | 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | 9 | /** 10 | * @author Rob Winch 11 | */ 12 | @SpringBootApplication 13 | public class RedisDemoApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(RedisDemoApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /RedisDemo/src/main/java/com/yq/config/MyRedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.yq.config; 2 | 3 | import com.yq.controller.RedisController; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.data.redis.connection.RedisConnectionFactory; 9 | import org.springframework.data.redis.connection.RedisStandaloneConfiguration; 10 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; 11 | 12 | /** 13 | * Simple to Introduction 14 | * className: MyRedisConfig 15 | * 16 | * @author EricYang 17 | * @version 2018/8/5 23:05 18 | */ 19 | 20 | 21 | @Slf4j 22 | public class MyRedisConfig { 23 | 24 | @Bean 25 | public LettuceConnectionFactory connectionFactory() { 26 | LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(); 27 | log.info("myConfig LettuceConnectionFactory"); 28 | return connectionFactory; // <2> 29 | } 30 | 31 | // @Bean 32 | // public RedisConnectionFactory connectionFactory2() { 33 | // RedisStandaloneConfiguration connectionConfig = new RedisStandaloneConfiguration(); 34 | // connectionConfig.setDatabase(2); 35 | // connectionConfig.setHostName("127.0.0.1"); 36 | // LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(connectionConfig); 37 | // return connectionFactory; 38 | // } 39 | } -------------------------------------------------------------------------------- /RedisDemo/src/main/java/com/yq/service/RedisService.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | /** 4 | * Simple to Introduction 5 | * className: RedisService 6 | * 7 | * @author EricYang 8 | * @version 2018/8/4 23:00 9 | */ 10 | public interface RedisService { 11 | String get(String key); 12 | Boolean del(String key); 13 | int delByPattern(String keyPattern) ; 14 | void set(String key, String value); 15 | String getHash(String key, String hashKey); 16 | void setHash(String key, String hashKey, String value); 17 | long getRedisSequence(); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /RedisDemo/src/main/resources/application-beta.properties: -------------------------------------------------------------------------------- 1 | 2 | #beta 8083 3 | server.port=8083 4 | 5 | spring.redis.database=0 6 | spring.redis.host=127.0.0.1 7 | spring.redis.port=6379 8 | #spring.redis.password=xxxxxx 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisDemo/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | 2 | #dev 8081 3 | server.port=8081 4 | 5 | spring.redis.database=0 6 | spring.redis.host=127.0.0.1 7 | spring.redis.port=6379 8 | #spring.redis.password=xxxxxx 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisDemo/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | 2 | #prod 8084 3 | server.port=8084 4 | 5 | spring.redis.database=0 6 | spring.redis.host=127.0.0.1 7 | spring.redis.port=6379 8 | #spring.redis.password=xxxxxx 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisDemo/src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | 2 | # proflie 3 | spring.profiles.active=test 4 | 5 | #test 8082 6 | server.port=8082 7 | 8 | spring.redis.database=0 9 | spring.redis.host=127.0.0.1 10 | spring.redis.port=6379 11 | #spring.redis.password=xxxxxx 12 | spring.redis.pool.maxa-ctive=8 13 | spring.redis.pool.max-wait=-1 14 | spring.redis.pool.max-idle=8 15 | spring.redis.pool.min-idle=0 16 | spring.redis.timeout=5000 17 | 18 | -------------------------------------------------------------------------------- /RedisDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/RedisDemo/src/main/resources/application.properties -------------------------------------------------------------------------------- /RedisPubSubDemo/README_redisSpringBoot2.md: -------------------------------------------------------------------------------- 1 | ##spring-data-redis 升级到springboot2 2 | 3 | 4 | > [官方文档](#official_docs) 5 | > 6 | > [注意问题](#notes_faq) 7 | > 8 | 9 | ### 官方文档 10 | https://spring.io/guides/gs/messaging-redis/ 11 | 12 | http://127.0.0.1:8084/swagger-ui.html ---prod 13 | http://127.0.0.1:8081/swagger-ui.html --dev 14 | http://127.0.0.1:8083/swagger-ui.html --beta 15 | http://127.0.0.1:8084/swagger-ui.html 16 | --spring.profiles.active=beta 17 | redis (Windows上修改redis.windows-service.conf,然后重启)配置修改为 18 | #notify-keyspace-events Esx ---does not work for set,m only works for expired 19 | notify-keyspace-events E$x works well for set and expired 20 | ### 注意问题 21 | 22 | ``` 23 | 24 | 25 | ``` 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/MyCommandLineRunner.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | 4 | import com.yq.dist.DistLock; 5 | import com.yq.service.MyRedisPubSubListener; 6 | import io.lettuce.core.RedisClient; 7 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 8 | import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.CommandLineRunner; 12 | import org.springframework.core.annotation.Order; 13 | import org.springframework.stereotype.Component; 14 | 15 | /** 16 | * Simple to Introduction 17 | * className: MyCommandLineRunner 18 | * 19 | * @author EricYang 20 | * @version 2018/9/2 14:03 21 | */ 22 | @Component 23 | @Slf4j 24 | @Order(value = 4) 25 | public class MyCommandLineRunner implements CommandLineRunner { 26 | 27 | @Autowired 28 | private DistLock distLock; 29 | 30 | 31 | @Override 32 | public void run(String... strings) throws Exception { 33 | log.info("MyCommandLineRunner初始化 distLock={}", distLock); 34 | 35 | distLock.init(); 36 | 37 | RedisClient client = RedisClient.create("redis://127.0.0.1"); 38 | StatefulRedisPubSubConnection connection = client.connectPubSub(); 39 | connection.addListener(new MyRedisPubSubListener()); 40 | 41 | RedisPubSubAsyncCommands async = connection.async(); 42 | async.subscribe("topic1"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/RedisDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Rob Winch 8 | */ 9 | @SpringBootApplication 10 | public class RedisDemoApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(RedisDemoApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/callable/MyCallable.java: -------------------------------------------------------------------------------- 1 | package com.yq.callable; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.util.concurrent.Callable; 6 | 7 | /** 8 | * Simple to Introduction 9 | * className: MyCallable 10 | * if we use callable, program will report "java.lang.IllegalArgumentException: Task can't be created using anonymous class" 11 | * 12 | * Caused by: java.lang.IllegalArgumentException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.yq.callable.MyCallable` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) 13 | * @author EricYang 14 | * @version 2019/5/16 14:25 15 | */ 16 | @Slf4j 17 | public class MyCallable implements Callable { 18 | private int num = 30; 19 | 20 | public MyCallable(int num) { 21 | this.num = num; 22 | } 23 | 24 | @Override 25 | public String call() throws Exception { 26 | long threadId = Thread.currentThread().getId(); 27 | String jobId = "jobId_" + threadId; 28 | log.info("call jobId={}. threadId={}", jobId, threadId); 29 | try { 30 | Thread.sleep(num * 1000); 31 | } catch (Exception ex) { 32 | log.info("{} sleep exception", threadId, ex); 33 | } 34 | return jobId; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/config/ConfigRedisConfigBean.java: -------------------------------------------------------------------------------- 1 | package com.yq.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.annotation.Order; 7 | 8 | /** 9 | * Simple to Introduction 10 | * className: ConfigA 11 | * 12 | * @author EricYang 13 | * @version 2018/10/21 15:39 14 | */ 15 | @Configuration 16 | @Order(3) 17 | @Slf4j 18 | public class ConfigRedisConfigBean { 19 | 20 | @Bean 21 | public RedisConfig redisConfig() { 22 | log.info("Create a redisConfig"); 23 | return new RedisConfig(); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.yq.config; 2 | 3 | import io.lettuce.core.ClientOptions; 4 | import io.lettuce.core.resource.ClientResources; 5 | import io.lettuce.core.resource.DefaultClientResources; 6 | import lombok.Data; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.core.annotation.Order; 11 | import org.springframework.data.redis.connection.RedisStandaloneConfiguration; 12 | 13 | /** 14 | * Simple to Introduction 15 | * className: RedisConfig 16 | * 17 | * @author EricYang 18 | * @version 2019/2/23 12:32 19 | */ 20 | @Configuration 21 | @Data 22 | @Order(1) 23 | public class RedisConfig { 24 | 25 | @Value("${spring.redis.host}") 26 | private String redisHost; 27 | 28 | @Value("${spring.redis.port}") 29 | private int redisPort; 30 | 31 | // @Value("${spring.redis.password}") 32 | // private String password; 33 | 34 | @Bean(destroyMethod = "shutdown") 35 | ClientResources clientResources() { 36 | return DefaultClientResources.create(); 37 | } 38 | 39 | @Bean 40 | public RedisStandaloneConfiguration redisStandaloneConfiguration() { 41 | return new RedisStandaloneConfiguration(redisHost, redisPort); 42 | } 43 | 44 | @Bean 45 | public ClientOptions clientOptions(){ 46 | return ClientOptions.builder() 47 | .disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS) 48 | .autoReconnect(true) 49 | .build(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/config/ThreadPool.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.config; 4 | 5 | import com.alibaba.fastjson.JSON; 6 | import lombok.Data; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.config.ConfigurableBeanFactory; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Scope; 11 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.util.concurrent.Executor; 15 | 16 | 17 | 18 | @Component 19 | @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) 20 | @Slf4j 21 | @Data 22 | public class ThreadPool { 23 | 24 | private ThreadPoolTaskExecutor executor; 25 | 26 | /** 27 | * 线程池维护线程的最少数量 28 | */ 29 | private int corePoolSize = 4; 30 | 31 | /** 32 | * 线程池维护线程的最大数量 33 | */ 34 | private int maxPoolSize = 6; 35 | 36 | /** 37 | * 缓存队列 38 | */ 39 | private int queueCapacity = 100; 40 | 41 | /** 42 | * 允许的空闲时间 43 | */ 44 | private int keepAlive = 60; 45 | 46 | @Bean 47 | public Executor instanceExecutor() { 48 | executor = new ThreadPoolTaskExecutor(); 49 | executor.setCorePoolSize(corePoolSize); 50 | executor.setMaxPoolSize(maxPoolSize); 51 | executor.setQueueCapacity(queueCapacity); 52 | executor.setThreadNamePrefix("ThreadExecutor-"); 53 | executor.setKeepAliveSeconds(keepAlive); 54 | executor.initialize(); 55 | return executor; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/other/SynchronousQueueQuiz.java: -------------------------------------------------------------------------------- 1 | package com.yq.other; 2 | 3 | import java.util.concurrent.BlockingQueue; 4 | import java.util.concurrent.SynchronousQueue; 5 | 6 | /** 7 | * Created by yangqian on 2019/6/30. 8 | */ 9 | public class SynchronousQueueQuiz { 10 | public static void main(String[] args) throws Exception { 11 | BlockingQueue queue = new SynchronousQueue<>(); 12 | System.out.print(queue.offer(1) + " "); 13 | System.out.print(queue.offer(2) + " "); 14 | System.out.print(queue.offer(3) + " "); 15 | System.out.print(queue.take() + " "); 16 | System.out.println(queue.size()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/service/MyMessageListener.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.data.redis.connection.Message; 5 | import org.springframework.data.redis.connection.MessageListener; 6 | import org.springframework.lang.Nullable; 7 | 8 | /** 9 | * Simple to Introduction 10 | * className: MyMessageListener 11 | * 12 | * @author EricYang 13 | * @version 2019/2/23 13:16 14 | */ 15 | @Slf4j 16 | public class MyMessageListener implements MessageListener { 17 | @Override 18 | public void onMessage(Message message, @Nullable byte[] pattern) { 19 | byte[] bytesBody = message.getBody(); 20 | byte[] bytesChannel = message.getChannel(); 21 | String patternStr = pattern != null? new String(bytesChannel): null; 22 | //msgBody=qq, channel=__keyevent@1__:expired 23 | log.info("msgBody={}, channel={}, pattern={}", bytesBody!=null? new String(bytesBody): null, bytesChannel!=null? new String(bytesChannel): null, pattern); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/service/MyRedisPubSubListener.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | import io.lettuce.core.pubsub.RedisPubSubListener; 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | /** 7 | * Simple to Introduction 8 | * className: MyRedisPubSubListener 9 | * 10 | * @author EricYang 11 | * @version 2019/2/22 14:08 12 | */ 13 | @Slf4j 14 | public class MyRedisPubSubListener implements RedisPubSubListener { 15 | 16 | @Override 17 | public void message(String channel, String message) { 18 | log.info("msg1={} on channel {}", message, channel); 19 | } 20 | 21 | @Override 22 | public void message(String pattern, String channel, String message) { 23 | log.info("msg2={} in channel={}", message, channel); 24 | } 25 | 26 | @Override 27 | public void subscribed(String channel, long count) { 28 | log.info("sub channel={}, count={}", channel, count); 29 | } 30 | 31 | @Override 32 | public void psubscribed(String pattern, long count) { 33 | log.info("psub pattern={}, count={}", pattern, count); 34 | } 35 | 36 | @Override 37 | public void unsubscribed(String channel, long count) { 38 | log.info("unsub channel={}, count={}", channel, count); 39 | } 40 | 41 | @Override 42 | public void punsubscribed(String pattern, long count) { 43 | log.info("punsub channel={}, count={}", pattern, count); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/service/RedisService.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | import org.redisson.api.RMap; 4 | 5 | import java.util.concurrent.Future; 6 | 7 | /** 8 | * Simple to Introduction 9 | * className: RedisService 10 | * 11 | * @author EricYang 12 | * @version 2018/8/4 23:00 13 | */ 14 | public interface RedisService { 15 | Future StartRunnable(); 16 | RMap getMap(String key); 17 | RMap mapAddEntry(String key, String value) ; 18 | String mapDelEntry(String key); 19 | String get(String key); 20 | void set(String key, String value); 21 | String getHash(String key, String hashKey); 22 | void setHash(String key, String hashKey, String value); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/java/com/yq/task/RunnableTask.java: -------------------------------------------------------------------------------- 1 | package com.yq.task; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.redisson.Redisson; 5 | import org.redisson.api.RAtomicLong; 6 | import org.redisson.api.RedissonClient; 7 | import org.redisson.config.Config; 8 | 9 | /** 10 | * Created by yangqian on 2019/6/29. 11 | */ 12 | @Slf4j 13 | public class RunnableTask implements Runnable { 14 | 15 | private long param; 16 | 17 | public RunnableTask() { 18 | } 19 | 20 | public RunnableTask(long param) { 21 | this.param = param; 22 | } 23 | 24 | @Override 25 | public void run() { 26 | Config config=new Config(); 27 | config.useSingleServer() 28 | .setAddress("127.0.0.1:6379"); 29 | //.setPassword(redisConfig.getPassword()); 30 | 31 | RedissonClient redisson = Redisson.create(config); 32 | RAtomicLong atomic = redisson.getAtomicLong("myAtomic"); 33 | atomic.addAndGet(param); 34 | log.info("threadId={}, atomic={}", Thread.currentThread().getId(), atomic.get()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/resources/application-beta.properties: -------------------------------------------------------------------------------- 1 | 2 | #beta 8083 3 | server.port=8083 4 | 5 | spring.redis.database=0 6 | spring.redis.host=127.0.0.1 7 | spring.redis.port=6379 8 | #spring.redis.password=redis123 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | 2 | #dev 8081 3 | server.port=8081 4 | 5 | spring.redis.database=0 6 | spring.redis.host=127.0.0.1 7 | spring.redis.port=6379 8 | #spring.redis.password=redis123 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | 2 | #prod 8084 3 | server.port=8084 4 | 5 | spring.redis.database=0 6 | spring.redis.host=127.0.0.1 7 | spring.redis.port=6379 8 | #spring.redis.password=redis123 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | 2 | # proflie 3 | spring.profiles.active=test 4 | 5 | #test 8082 6 | server.port=8082 7 | 8 | spring.redis.database=0 9 | spring.redis.host=127.0.0.1 10 | spring.redis.port=6379 11 | #spring.redis.password=redis123 12 | spring.redis.pool.maxa-ctive=8 13 | spring.redis.pool.max-wait=-1 14 | spring.redis.pool.max-idle=8 15 | spring.redis.pool.min-idle=0 16 | spring.redis.timeout=5000 17 | 18 | -------------------------------------------------------------------------------- /RedisPubSubDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | spring.profiles.active=@spring.profiles.active@ 3 | 4 | spring.redis.database=0 5 | spring.redis.host=127.0.0.1 6 | spring.redis.port=6379 7 | 8 | #spring.redis.password=123456 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisReadWriteDemo/src/main/java/com/yq/RedisReadWriteDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | 5 | 6 | import org.springframework.boot.SpringApplication; 7 | 8 | /** 9 | * @author Rob Winch 10 | */ 11 | @SpringBootApplication 12 | public class RedisReadWriteDemoApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(RedisReadWriteDemoApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /RedisReadWriteDemo/src/main/java/com/yq/service/RedisService.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | /** 4 | * Simple to Introduction 5 | * className: RedisService 6 | * 7 | * @author EricYang 8 | * @version 2018/8/4 23:00 9 | */ 10 | public interface RedisService { 11 | String get(String key); 12 | void set(String key, String value); 13 | String getHash(String key, String hashKey); 14 | void setHash(String key, String hashKey, String value); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /RedisReadWriteDemo/src/main/resources/application-beta.properties: -------------------------------------------------------------------------------- 1 | 2 | #beta 8083 3 | server.port=8083 4 | 5 | spring.redis.database=0 6 | spring.redis.host=127.0.0.1 7 | spring.redis.port=6379 8 | #spring.redis.password=redis123 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisReadWriteDemo/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | 2 | #dev 8081 3 | server.port=8081 4 | 5 | spring.redis.database=0 6 | spring.redis.host=127.0.0.1 7 | spring.redis.port=6379 8 | #spring.redis.password=redis123 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisReadWriteDemo/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | 2 | #prod 8084 3 | server.port=8084 4 | 5 | spring.redis.database=0 6 | spring.redis.host=127.0.0.1 7 | spring.redis.port=6379 8 | #spring.redis.password=redis123 9 | spring.redis.pool.maxa-ctive=8 10 | spring.redis.pool.max-wait=-1 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.timeout=5000 14 | 15 | -------------------------------------------------------------------------------- /RedisReadWriteDemo/src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | 2 | # proflie 3 | spring.profiles.active=test 4 | 5 | #test 8082 6 | server.port=8082 7 | 8 | spring.redis.database=0 9 | spring.redis.host=127.0.0.1 10 | spring.redis.port=6379 11 | #spring.redis.password=redis123 12 | spring.redis.pool.maxa-ctive=8 13 | spring.redis.pool.max-wait=-1 14 | spring.redis.pool.max-idle=8 15 | spring.redis.pool.min-idle=0 16 | spring.redis.timeout=5000 17 | 18 | -------------------------------------------------------------------------------- /RedisReadWriteDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | spring.profiles.active=@spring.profiles.active@ 3 | 4 | server.port=8081 5 | 6 | spring.redis.database=0 7 | #spring.redis.host=127.0.0.1 8 | spring.redis.port=6379 9 | #spring.redis.password=redis123 10 | spring.redis.pool.maxa-ctive=8 11 | spring.redis.pool.max-wait=-1 12 | spring.redis.pool.max-idle=8 13 | spring.redis.pool.min-idle=0 14 | spring.redis.timeout=5000 15 | 16 | -------------------------------------------------------------------------------- /RestTemplateDemo/src/main/java/com/yq/RestTemplateApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @Slf4j 9 | public class RestTemplateApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(RestTemplateApplication.class, args); 13 | log.info("RestTemplateApplication Start done."); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /RestTemplateDemo/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /RestTemplateDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | server.port=9901 3 | spring.application.name=resttemplate-demo 4 | 5 | server.ssl.key-store=classpath:keystore.p12 6 | server.ssl.key-store-password=123456 7 | server.ssl.keyStoreType=PKCS12 8 | server.ssl.keyAlias=yqdemo 9 | 10 | -------------------------------------------------------------------------------- /RestTemplateDemo/src/main/resources/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/RestTemplateDemo/src/main/resources/keystore.p12 -------------------------------------------------------------------------------- /SecurityDemo/src/main/java/com/yq/SecurityDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 9 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; 10 | 11 | 12 | @SpringBootApplication 13 | @EnableOAuth2Client 14 | @Slf4j 15 | public class SecurityDemoApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(SecurityDemoApplication.class, args); 19 | log.info("Start SecurityDemoApplication Done"); 20 | } 21 | 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /SecurityDemo/src/main/java/com/yq/config/UnauthorizedEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.yq.config; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | import org.springframework.security.web.AuthenticationEntryPoint; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | 11 | public class UnauthorizedEntryPoint implements AuthenticationEntryPoint { 12 | @Override 13 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 14 | if(isAjaxRequest(request)){ 15 | response.sendError(HttpServletResponse.SC_UNAUTHORIZED,authException.getMessage()); 16 | }else{ 17 | request.getSession().invalidate(); 18 | //response.sendRedirect(ConfigMapCache.initMap.get("unlogin").toString()); 19 | response.sendError(450,"unlogin"); 20 | } 21 | } 22 | 23 | public static boolean isAjaxRequest(HttpServletRequest request) { 24 | String ajaxFlag = request.getHeader("X-Requested-With"); 25 | return ajaxFlag != null && "XMLHttpRequest".equals(ajaxFlag); 26 | } 27 | } -------------------------------------------------------------------------------- /SecurityDemo/src/main/java/com/yq/controller/MainController.java: -------------------------------------------------------------------------------- 1 | package com.yq.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | /** 8 | * Simple to Introduction 9 | * className: MainController 10 | * 11 | * @author EricYang 12 | * @version 2018/7/31 19:11 13 | */ 14 | @Controller 15 | public class MainController { 16 | 17 | @RequestMapping("/") 18 | public String root() { 19 | return "redirect:/index"; 20 | } 21 | 22 | @RequestMapping("/index") 23 | public String index() { 24 | return "index"; 25 | } 26 | 27 | @RequestMapping("/user/index") 28 | public String userIndex() { 29 | return "user/index"; 30 | } 31 | 32 | @RequestMapping("/login") 33 | public String login() { 34 | return "login"; 35 | } 36 | 37 | @RequestMapping("/login-error") 38 | public String loginError(Model model) { 39 | model.addAttribute("loginError", true); 40 | return "login"; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /SecurityDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/SecurityDemo/src/main/resources/application.properties -------------------------------------------------------------------------------- /SecurityDemo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8181 3 | 4 | logging: 5 | level: 6 | root: WARN 7 | org.springframework.web: INFO 8 | org.springframework.security: INFO 9 | 10 | spring: 11 | thymeleaf: 12 | cache: false 13 | -------------------------------------------------------------------------------- /SecurityDemo/src/main/resources/static/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans; 3 | font-size: 1em; 4 | } 5 | 6 | p.error { 7 | font-weight: bold; 8 | color: red; 9 | } 10 | 11 | div.logout { 12 | float: right; 13 | } -------------------------------------------------------------------------------- /SecurityDemo/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello Spring Security 5 | 6 | 7 | 8 | 9 |
10 | Logged in user: | 11 | Roles: 12 |
13 |
14 | 15 |
16 |
17 |
18 |

Hello Spring Security

19 |

This is an unsecured page, but you can access the secured pages after authenticating.

20 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /SecurityDemo/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Login page 5 | 6 | 7 | 8 | 9 |

Login page

10 |

Example user: user / password

11 |

Wrong user or password

12 |
13 | : 14 |
15 | : 16 |
17 | 18 |
19 |

Back to home page

20 | 21 | 22 | -------------------------------------------------------------------------------- /SecurityDemo/src/main/resources/templates/user/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello Spring Security 5 | 6 | 7 | 8 | 9 |
10 |

This is a secured page!

11 |

Back to home page

12 | 13 | 14 | -------------------------------------------------------------------------------- /StaticResDemo/README_staticResource.md: -------------------------------------------------------------------------------- 1 | # static resource access demo 2 | 3 | http://localhost:6608 4 | 5 | 如果不使用thyleleaf、FreeMaker、Velocity,不讲将index.html页面放在在src/main/resources/templates,或者src/main/resources 6 | 只能放在src/main/resources/static目录下面或者src/main/resources/public目录下面, image文件也可以在public目录下 7 | 8 | static下的index.html比public的index.html优先 9 | 10 | 11 | https://docs.spring.io/spring-boot/docs/1.5.12.RELEASE/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-static-content -------------------------------------------------------------------------------- /StaticResDemo/src/main/java/com/yq/StaticResDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | 8 | @SpringBootApplication 9 | 10 | @Slf4j 11 | public class StaticResDemoApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(StaticResDemoApplication.class, args); 15 | log.info("Spring Boot start done!"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /StaticResDemo/src/main/java/com/yq/controller/UserController.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.controller; 4 | 5 | import com.yq.domain.User; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.Collection; 14 | import java.util.Date; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | 19 | @RestController 20 | @RequestMapping("/user") 21 | public class UserController { 22 | private Logger logger = LoggerFactory.getLogger(UserController.class); 23 | 24 | private Map userMap = new HashMap<>(); 25 | { 26 | for(int i=0;i < 5; i++) { 27 | User user = new User(); 28 | user.setId(i + ""); 29 | user.setMail("qq" + i + "@163.com"); 30 | user.setName("Tom" + i ); 31 | user.setRegDate(new Date()); 32 | userMap.put(i+ "",user ); 33 | } 34 | 35 | } 36 | 37 | @GetMapping(value = "/users/{userId}", produces = "application/json;charset=UTF-8") 38 | public User getUser(@PathVariable String userId) { 39 | 40 | User user = userMap.get(userId); 41 | return user; 42 | } 43 | 44 | @GetMapping(value = "/users", produces = "application/json;charset=UTF-8") 45 | public Iterable findAllUsers() { 46 | Collection users = userMap.values(); 47 | return users; 48 | } 49 | } -------------------------------------------------------------------------------- /StaticResDemo/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /StaticResDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | 3 | #application 4 | server.port=6608 5 | 6 | # Path pattern used for static resources. 7 | #spring.mvc.static-path-pattern=/** 8 | #spring.resources.chain.strategy.content.enabled=true 9 | #spring.resources.chain.strategy.content.paths=/** 10 | #spring.resources.static-locations=classpath:/newLocation1/,classpath:/newLocation2/ 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /StaticResDemo/src/main/resources/public/img/cloud02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/StaticResDemo/src/main/resources/public/img/cloud02.jpg -------------------------------------------------------------------------------- /StaticResDemo/src/main/resources/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello 静态资源访问演示程序2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 |

The user id is

18 |

The user name is

19 |
20 | 21 | -------------------------------------------------------------------------------- /StaticResDemo/src/main/resources/static/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #f5f5f5; 3 | } 4 | 5 | #main-content { 6 | max-width: 940px; 7 | padding: 2em 3em; 8 | margin: 0 auto 20px; 9 | background-color: #fff; 10 | border: 1px solid #e5e5e5; 11 | -webkit-border-radius: 5px; 12 | -moz-border-radius: 5px; 13 | border-radius: 5px; 14 | } -------------------------------------------------------------------------------- /StaticResDemo/src/main/resources/static/hello.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | $.ajax({ 3 | url: "http://localhost:6608/user/users/2" 4 | }).then(function(data, status, jqxhr) { 5 | console.log(data); 6 | $('.user-id').append(data.id); 7 | $('.user-name').append(data.name); 8 | console.log(jqxhr); 9 | }); 10 | }); -------------------------------------------------------------------------------- /StaticResDemo/src/main/resources/static/img/cloud01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/StaticResDemo/src/main/resources/static/img/cloud01.jpg -------------------------------------------------------------------------------- /StaticResDemo/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hello 静态资源访问演示程序2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 |

The user id is

18 |

The user name is

19 |
20 | 21 | -------------------------------------------------------------------------------- /WebClientDemo/README.md: -------------------------------------------------------------------------------- 1 | #webClient 2 | 3 | http://127.0.0.1:9902/swagger-ui.html 4 | 5 | http://127.0.0.1:9902/client/requestByWebClient/2 post 6 | 7 | http://127.0.0.1:9902/user/hello get 8 | 9 | 10 | https://www.baeldung.com/spring-5-webclient -------------------------------------------------------------------------------- /WebClientDemo/src/main/java/com/yq/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | //package com.yq; 2 | // 3 | //import org.springframework.context.annotation.Bean; 4 | //import org.springframework.context.annotation.Configuration; 5 | // 6 | //import org.springframework.web.reactive.config.ResourceHandlerRegistry; 7 | //import springfox.documentation.builders.ApiInfoBuilder; 8 | //import springfox.documentation.builders.PathSelectors; 9 | //import springfox.documentation.builders.RequestHandlerSelectors; 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 | // 16 | //@Configuration 17 | //@EnableSwagger2 18 | //public class SwaggerConfig { 19 | // 20 | // @Bean 21 | // public Docket createRestApi() { 22 | // return new Docket(DocumentationType.SWAGGER_2) 23 | // .apiInfo(apiInfo()) 24 | // .select() 25 | // .apis(RequestHandlerSelectors.basePackage("com.yq.controller")) 26 | // .paths(PathSelectors.any()) 27 | // .build(); 28 | // } 29 | // 30 | // private ApiInfo apiInfo() { 31 | // return new ApiInfoBuilder() 32 | // .title("RESTful APIs") 33 | // .description("description") 34 | // .termsOfServiceUrl("yqbjtu") 35 | // .version("1.0") 36 | // .build(); 37 | // } 38 | //} 39 | -------------------------------------------------------------------------------- /WebClientDemo/src/main/java/com/yq/WebClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @Slf4j 9 | public class WebClientApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(WebClientApplication.class, args); 13 | log.info("WebClientApplication Start done."); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebClientDemo/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.yq.domain; 4 | 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Simple to Introduction 11 | * className: User 12 | * 13 | * @author EricYang 14 | * @version 2018/6/29 23:43 15 | */ 16 | @Data 17 | public class User { 18 | String id; 19 | String name; 20 | String mail; 21 | Date regDate; 22 | } 23 | -------------------------------------------------------------------------------- /WebClientDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | server.port=9903 3 | spring.application.name=webclient-service 4 | 5 | -------------------------------------------------------------------------------- /WebSocket/src/main/java/com/yq/Swagger2.java: -------------------------------------------------------------------------------- 1 | package com.yq; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class Swagger2 { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.yq.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Spring Boot 测试使用 Swagger2 构建WebSocket send RESTful API") .contact(new Contact("EricYang", "https://github.com/yqbjtu/SpringCloudTutorials.git", "test@163.com")) .version("1.0") .description("User API 描述") .build(); } } -------------------------------------------------------------------------------- /WebSocket/src/main/java/com/yq/WebSocketApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class WebSocketApplication { 10 | private static final Logger log = LoggerFactory.getLogger(WebSocketApplication.class); 11 | 12 | public static void main(String[] args) { 13 | 14 | SpringApplication.run(WebSocketApplication.class, args); 15 | log.info("Spring Boot start done!"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /WebSocket/src/main/java/com/yq/config/MyWebSocketConfig.java: -------------------------------------------------------------------------------- 1 | // 2 | //package com.yq.config; 3 | // 4 | //import org.springframework.context.annotation.Bean; 5 | //import org.springframework.context.annotation.Configuration; 6 | //import org.springframework.web.socket.WebSocketHandler; 7 | //import org.springframework.web.socket.config.annotation.EnableWebSocket; 8 | //import org.springframework.web.socket.config.annotation.WebSocketConfigurer; 9 | //import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; 10 | // 11 | ///** 12 | // * Simple to Introduction 13 | // * className: MyWebSocketConfig 14 | // * 15 | // * @author EricYang 16 | // * @version 2018/5/20 14:39 17 | // */ 18 | // 19 | //@Configuration 20 | //@EnableWebSocket 21 | //public class MyWebSocketConfig implements WebSocketConfigurer { 22 | // 23 | // @Override 24 | // public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 25 | // registry.addHandler(myHandler(), "/myHandler").addInterceptors(new WebSocketInterceptor()); 26 | // } 27 | // 28 | // @Bean 29 | // public WebSocketHandler myHandler() { 30 | // return new MyHandler(); 31 | // } 32 | //} 33 | -------------------------------------------------------------------------------- /WebSocket/src/main/java/com/yq/domain/Greeting.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | public class Greeting { 4 | 5 | private String content; 6 | 7 | public Greeting() { 8 | } 9 | 10 | public Greeting(String content) { 11 | this.content = content; 12 | } 13 | 14 | public String getContent() { 15 | return content; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /WebSocket/src/main/java/com/yq/domain/HelloMessage.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | public class HelloMessage { 4 | 5 | private String name; 6 | 7 | public HelloMessage() { 8 | } 9 | 10 | public HelloMessage(String name) { 11 | this.name = name; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WebSocket/src/main/java/com/yq/service/MyRunnable.java: -------------------------------------------------------------------------------- 1 | package com.yq.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.messaging.simp.SimpMessagingTemplate; 5 | 6 | /** 7 | * Simple to Introduction 8 | * className: MyRunnable 9 | * 10 | * @author EricYang 11 | * @version 2018/10/25 18:11 12 | */ 13 | @Slf4j 14 | public class MyRunnable implements Runnable { 15 | private SimpMessagingTemplate simpMessagingTemplate; 16 | private String deviceId; 17 | 18 | public MyRunnable(SimpMessagingTemplate simpMessagingTemplate, String deviceId) { 19 | this.simpMessagingTemplate = simpMessagingTemplate; 20 | this.deviceId = deviceId; 21 | } 22 | @Override 23 | public void run() { 24 | // try { 25 | // Thread.sleep(1* 1000); 26 | // } 27 | // catch (Exception ex) { 28 | // log.warn("sleep exception", ex); 29 | // } 30 | 31 | String payload = "{\"name\":\"afterSendCompletion\"}"; 32 | simpMessagingTemplate.convertAndSend(deviceId, payload); 33 | log.info("send complete. deviceId={}", deviceId); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /WebSocket/src/main/java/com/yq/service/WebSocketSendSvc.java: -------------------------------------------------------------------------------- 1 | 2 | package com.yq.service; 3 | 4 | import com.alibaba.fastjson.JSON; 5 | import com.alibaba.fastjson.JSONObject; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.messaging.simp.SimpMessagingTemplate; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | 13 | import java.util.Map; 14 | 15 | /** 16 | * Simple to Introduction 17 | * className: WebSocketSendSvc 18 | * 19 | * @author EricYang 20 | * @version 2018/7/2 18:13 21 | */ 22 | 23 | @Service 24 | public class WebSocketSendSvc { 25 | private static final Logger logger = LoggerFactory.getLogger(WebSocketSendSvc.class); 26 | 27 | @Autowired 28 | private SimpMessagingTemplate messagingTemplate; 29 | 30 | public void send(String topic, String messageBody) { 31 | logger.debug("messageBody={}", messageBody); 32 | messagingTemplate.convertAndSend(topic, messageBody); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WebSocket/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | 3 | #application 4 | server.port=8086 5 | 6 | 7 | #security.require-ssl=true 8 | #server.ssl.key-store=classpath:keystore.p12 9 | #server.ssl.key-store-password=123456 10 | #server.ssl.key-store-type=PKCS12 11 | #server.ssl.key-alias=tomcat 12 | 13 | logging.config=classpath:logback-spring.xml 14 | 15 | -------------------------------------------------------------------------------- /WebSocket/src/main/resources/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/WebSocket/src/main/resources/keystore.p12 -------------------------------------------------------------------------------- /WebSocket/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | [%-5level] %d{HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | log/base.log 13 | 14 | log/base.%d.%i.log 15 | 16 | 1 MB 17 | 18 | 19 | 20 | 21 | [%-5level] %d{HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n 22 | 23 | UTF-8 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /WebSocket/src/main/resources/static/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #f5f5f5; 3 | } 4 | 5 | #main-content { 6 | max-width: 940px; 7 | padding: 2em 3em; 8 | margin: 0 auto 20px; 9 | background-color: #fff; 10 | border: 1px solid #e5e5e5; 11 | -webkit-border-radius: 5px; 12 | -moz-border-radius: 5px; 13 | border-radius: 5px; 14 | } -------------------------------------------------------------------------------- /WebSocket2/src/main/java/com/yq/Swagger2.java: -------------------------------------------------------------------------------- 1 | package com.yq; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class Swagger2 { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.yq.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Spring Boot 测试使用 Swagger2 构建WebSocket send RESTful API") .contact(new Contact("EricYang", "https://github.com/yqbjtu/SpringCloudTutorials.git", "test@163.com")) .version("1.0") .description("User API 描述") .build(); } } -------------------------------------------------------------------------------- /WebSocket2/src/main/java/com/yq/WebSocket2Application.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | 9 | @SpringBootApplication 10 | public class WebSocket2Application { 11 | private static final Logger log = LoggerFactory.getLogger(WebSocket2Application.class); 12 | 13 | public static void main(String[] args) { 14 | 15 | SpringApplication.run(WebSocket2Application.class, args); 16 | log.info("Spring Boot start done!"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WebSocket2/src/main/java/com/yq/domain/Greeting.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | public class Greeting { 4 | 5 | private String content; 6 | 7 | public Greeting() { 8 | } 9 | 10 | public Greeting(String content) { 11 | this.content = content; 12 | } 13 | 14 | public String getContent() { 15 | return content; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /WebSocket2/src/main/java/com/yq/domain/HelloMessage.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | public class HelloMessage { 4 | 5 | private String name; 6 | 7 | public HelloMessage() { 8 | } 9 | 10 | public HelloMessage(String name) { 11 | this.name = name; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WebSocket2/src/main/java/com/yq/service/WebSocketSendSvc.java: -------------------------------------------------------------------------------- 1 | 2 | package com.yq.service; 3 | 4 | import com.alibaba.fastjson.JSON; 5 | import com.alibaba.fastjson.JSONObject; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.messaging.simp.SimpMessagingTemplate; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.web.bind.annotation.RequestBody; 13 | 14 | import java.util.Map; 15 | 16 | /** 17 | * Simple to Introduction 18 | * className: WebSocketSendSvc 19 | * 20 | * @author EricYang 21 | * @version 2018/7/2 18:13 22 | */ 23 | 24 | @Service 25 | @Slf4j 26 | public class WebSocketSendSvc { 27 | @Autowired 28 | private SimpMessagingTemplate messagingTemplate; 29 | 30 | public void send(String topic, String messageBody) { 31 | log.debug("topic={}, messageBody={}", messageBody); 32 | messagingTemplate.convertAndSend(topic, messageBody); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /WebSocket2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #profile 2 | 3 | #application 4 | 5 | server.port=8088 6 | 7 | spring.application.name=WebSocketDemo 8 | 9 | security.user.password=none 10 | security.basic.enabled=false 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /WebSocket2/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | [%-5level] %d{HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | log/base.log 13 | 14 | log/base.%d.%i.log 15 | 16 | 1 MB 17 | 18 | 19 | 20 | 21 | [%-5level] %d{HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n 22 | 23 | UTF-8 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /WebSocket2/src/main/resources/static/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #f5f5f5; 3 | } 4 | 5 | #main-content { 6 | max-width: 940px; 7 | padding: 2em 3em; 8 | margin: 0 auto 20px; 9 | background-color: #fff; 10 | border: 1px solid #e5e5e5; 11 | -webkit-border-radius: 5px; 12 | -moz-border-radius: 5px; 13 | border-radius: 5px; 14 | } -------------------------------------------------------------------------------- /ZKClientDemo/a.txt: -------------------------------------------------------------------------------- 1 | abc -------------------------------------------------------------------------------- /ZKClientDemo/src/main/java/com/yq/ZKClientApp.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import com.yq.service.MyZooKeeper; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | /** 8 | * Simple to Introduction 9 | * className: ZKDemoOneApplication 10 | * 11 | * @author EricYang 12 | * @version 2018/8/24 23:43 13 | */ 14 | 15 | public class ZKClientApp { 16 | private static final Logger log = LoggerFactory.getLogger(ZKClientApp.class); 17 | private static final String ZK_SERVERS = "127.0.0.1:2181"; 18 | private static final String PATH_NAME_TEST = "/test001"; 19 | 20 | public static void main(String[] args) { 21 | 22 | MyZooKeeper zk = new MyZooKeeper(); 23 | zk.connect(ZK_SERVERS); 24 | zk.createPath(PATH_NAME_TEST, "hello world!"); 25 | String value = zk.readData(PATH_NAME_TEST); 26 | log.info("znode={}, data={}", PATH_NAME_TEST, value); 27 | zk.detelePath(PATH_NAME_TEST); 28 | try { 29 | Thread.sleep(1000 * 120); 30 | } 31 | catch (Exception ex){ 32 | log.info("start ex={}.", ex); 33 | } 34 | 35 | log.info("start done."); 36 | } 37 | } -------------------------------------------------------------------------------- /ZKClientDemo/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Simple to Introduction 9 | * className: User 10 | * 11 | * @author EricYang 12 | * @version 2018/8/24 23:57 13 | */ 14 | @Data 15 | public class User implements Serializable { 16 | 17 | private Integer id; 18 | private String name; 19 | } -------------------------------------------------------------------------------- /ZKClientDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | server.port=8080 -------------------------------------------------------------------------------- /ZKClientDemo/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, stdout, R 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | 6 | log4j.appender.stdout.layout.ConversionPattern=%5p - %m%n 7 | 8 | log4j.appender.R=org.apache.log4j.RollingFileAppender 9 | log4j.appender.R.File=zkinfo.log 10 | 11 | log4j.appender.R.MaxFileSize=100KB 12 | log4j.appender.R.MaxBackupIndex=1 13 | 14 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 15 | log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n 16 | 17 | log4j.logger.com.yq=INFO -------------------------------------------------------------------------------- /ZKClientDemo/zk_readme.md: -------------------------------------------------------------------------------- 1 | 2 | 访问http://127.0.0.1:8080 3 | 4 | https://github.com/sgroschupf/zkclient 5 | 6 | http://127.0.0.1:8081/swagger-ui.html 7 | ``` 8 | 9 | org.apache.zookeeper 10 | zookeeper 11 | 3.4.9 12 | 13 | 14 | com.github.sgroschupf 15 | zkclient 16 | 0.1 17 | 18 | ``` 19 | -------------------------------------------------------------------------------- /ZKDistLock/README.md: -------------------------------------------------------------------------------- 1 | # curator demo for distribution 2 | 3 | 4 | http://curator.apache.org/curator-recipes/distributed-atomic-long.html 5 | 6 | http://curator.apache.org/curator-recipes/distributed-atomic-long.html -------------------------------------------------------------------------------- /ZKDistLock/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ZKDistLock/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, stdout, R 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | 6 | log4j.appender.stdout.layout.ConversionPattern= %-d{yyyy-MM-dd HH:mm:ss,SSS} [ %t:%r:%c:%L ] - [ %p ] %m%n 7 | 8 | log4j.appender.R=org.apache.log4j.RollingFileAppender 9 | log4j.appender.R.File=zkLockInfo.log 10 | 11 | log4j.appender.R.MaxFileSize=100KB 12 | log4j.appender.R.MaxBackupIndex=1 13 | 14 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 15 | log4j.appender.R.layout.ConversionPattern= %-d{yyyy-MM-dd HH:mm:ss,SSS} [ %t:%r:%c:%L] - [ %p ] %m%n 16 | 17 | log4j.logger.com.yq=INFO -------------------------------------------------------------------------------- /eureka/readme.txt: -------------------------------------------------------------------------------- 1 | This for euraka project 2 | -------------------------------------------------------------------------------- /rocketmqDemo/README.md: -------------------------------------------------------------------------------- 1 | # 2 | 3 | http://127.0.0.1:5001/swagger-ui.html -------------------------------------------------------------------------------- /rocketmqDemo/src/main/java/com/yq/RocketMQApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @Slf4j 9 | public class RocketMQApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(RocketMQApplication.class, args); 13 | log.info("RocketMQApplication Start done."); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /rocketmqDemo/src/main/java/com/yq/producer/SyncProducer.java: -------------------------------------------------------------------------------- 1 | package com.yq.producer; 2 | 3 | import org.apache.rocketmq.client.producer.DefaultMQProducer; 4 | import org.apache.rocketmq.client.producer.SendResult; 5 | import org.apache.rocketmq.common.message.Message; 6 | import org.apache.rocketmq.remoting.common.RemotingHelper; 7 | 8 | /** 9 | * Simple to Introduction 10 | * className: SyncProducer 11 | * 12 | * @author EricYang 13 | * @version 2019/1/29 15:03 14 | */ 15 | public class SyncProducer { 16 | public static void main(String[] args) throws Exception { 17 | //Instantiate with a producer group name. 18 | DefaultMQProducer producer = new 19 | DefaultMQProducer("please_rename_unique_group_name"); 20 | // Specify name server addresses. 21 | producer.setNamesrvAddr("localhost:9876"); 22 | //Launch the instance. 23 | producer.start(); 24 | for (int i = 0; i < 100; i++) { 25 | //Create a message instance, specifying topic, tag and message body. 26 | Message msg = new Message("TopicTest" /* Topic */, 27 | "TagA" /* Tag */, 28 | ("Hello RocketMQ " + 29 | i).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */ 30 | ); 31 | //Call send message to deliver message to one of brokers. 32 | SendResult sendResult = producer.send(msg); 33 | System.out.printf("%s%n", sendResult); 34 | } 35 | //Shut down once the producer instance is not longer in use. 36 | producer.shutdown(); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /rocketmqDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yqbjtu/SpringCloudTutorials/70d7f28da93541e3dfd11ebb31209bc701684e1f/rocketmqDemo/src/main/resources/application.properties -------------------------------------------------------------------------------- /zookeeperDemo1/src/main/java/com/yq/ZKDemoOneApplication.java: -------------------------------------------------------------------------------- 1 | package com.yq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | /** 9 | * Simple to Introduction 10 | * className: ZKDemoOneApplication 11 | * 12 | * @author EricYang 13 | * @version 2018/8/24 23:43 14 | */ 15 | 16 | 17 | @SpringBootApplication 18 | public class ZKDemoOneApplication { 19 | private static final Logger log = LoggerFactory.getLogger(ZKDemoOneApplication.class); 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(ZKDemoOneApplication.class, args); 23 | log.info("Spring Boot start done."); 24 | } 25 | } -------------------------------------------------------------------------------- /zookeeperDemo1/src/main/java/com/yq/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.yq.domain; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Simple to Introduction 9 | * className: User 10 | * 11 | * @author EricYang 12 | * @version 2018/8/24 23:57 13 | */ 14 | @Data 15 | public class User implements Serializable { 16 | 17 | private Integer id; 18 | private String name; 19 | } -------------------------------------------------------------------------------- /zookeeperDemo1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | server.port=8080 -------------------------------------------------------------------------------- /zookeeperDemo1/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=debug, stdout, R 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | 6 | log4j.appender.stdout.layout.ConversionPattern=%5p - %m%n 7 | 8 | log4j.appender.R=org.apache.log4j.RollingFileAppender 9 | log4j.appender.R.File=zkinfo.log 10 | 11 | log4j.appender.R.MaxFileSize=100KB 12 | log4j.appender.R.MaxBackupIndex=1 13 | 14 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 15 | log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n 16 | 17 | log4j.logger.com.yq=INFO -------------------------------------------------------------------------------- /zookeeperDemo1/zk_readme.md: -------------------------------------------------------------------------------- 1 | 2 | 访问http://127.0.0.1:8080 3 | 4 | https://github.com/sgroschupf/zkclient 5 | 6 | http://127.0.0.1:8081/swagger-ui.html 7 | 8 | 目前不支持topic中有/, 如果有/需要递归创建 9 | ``` 10 | 11 | org.apache.zookeeper 12 | zookeeper 13 | 3.4.9 14 | 15 | 16 | com.github.sgroschupf 17 | zkclient 18 | 0.1 19 | 20 | ``` 21 | 22 | ``` 23 | zkClient.subscribeDataChanges("/node", new IZkDataListener(){ 24 | public void handleDataChange(String arg0, Object arg1) 25 | throws Exception { 26 | System.out.println("节点名称:"+arg0+"-->修改后的值:"+arg1); 27 | } 28 | 29 | public void handleDataDeleted(String arg0) throws Exception { 30 | System.out.println("删除节点"+arg0+"成功"); 31 | } 32 | }); 33 | ``` --------------------------------------------------------------------------------