微服务的脚手架Jhipster使用(一) - 陆陆起飞啦 - 博客园
- -随着微服务的普及以及docker容器的广泛应用,有传统的soa服务衍生出微服务的概念,微服务强调的是服务的独立性,屏蔽底层物理平台的差异,此时你会发现微服务跟容器技术完美契合. 在此基础上衍生出的云原生以及DevOps的概念,废话不多说介绍一个非常牛叉的springCloud脚手架- -jhipster.
npm install -g npm
npm install -g yo
npm install -g generator-jhipster
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | <strong>windows下:</strong><br>以下demo选择微服务应用。实际中根据自己需求生产项目。 1 : Which *type* of application would you like to create? (Use arrow keys) Monolithic application (recommended for simple projects) //简单项目 Microservice application // 微服务应用 Microservice gateway // 微服务网关 JHipster UAA server ( for microservice OAuth2 authentication) // 微服务认证 2 :What is the base name of your application? (huhuawei) 输入服务名称 3 : As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts. ( 8081 ) 设置服务的端口号 4 :What is your default Java package name? (com.mycompany.myapp) 设置包名 5 :Which service discovery server do you want to use? (Use arrow keys) JHipster Registry (uses Eureka) Consul No service discovery 选择注册中心。一般选择Registry比较多 6 :Which *type* of authentication would you like to use? (Use arrow keys) JWT authentication (stateless, with a token) // jwt OAuth 2.0 / OIDC Authentication (stateful, works with Keycloak and Okta) //Oauth2 OIDC 认证服务 Authentication with JHipster UAA server (the server must be generated separately) // Oauth2+jwt Uaa认证服务 选择授权中心 7 : Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL) MongoDB Couchbase No database Cassandra 选择数据库支持Nosql跟常见RDMB数据库 8 :? Which *production* database would you like to use? (Use arrow keys) MySQL MariaDB PostgreSQL Oracle Microsoft SQL Server 选择数据库,这边会出现两次第一次是production 第二次是devlopment 9 :Do you want to use the Spring cache abstraction? 根据需求选择缓存 10 :Do you want to use Hibernate 2nd level cache? (Y/n) 是否支持二级缓存 11 : Would you like to use Maven or Gradle for building the backend? (Use arrow keys) Maven Gradle 12 :Which other technologies would you like to use? 安装一些其他的组件。如ES,KAFKA之类的 13 :Would you like to enable internationalization support? (Y/n) 支持国际化? 14 : Please choose the native language of the application (Use arrow keys) English Estonian Farsi French Galician ........ 选择本地支持的语言包含中文 15 :Please choose additional languages to install 可以额外安装其他语言 16 :Besides JUnit and Jest, which testing frameworks would you like to use? Gatling Cucumber 选择测试框架,针对微服务http接口测试,生成测试报告 17 :Would you like to install other generators from the JHipster Marketplace? 从jhipster市场中选择组件安装 |
选择linux服务器,安装docker; yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum list docker-ce --showduplicates | sort -r sudo yum install -y docker-ce sudo systemctl start docker sudo systemctl enable docker 拉取jhipster官方镜像 docker pull jhipster/jhipster:master 启动jhipster镜像,选择一个空文件/jhipster夹挂载到容器中 docker container run --name jhipster -v /jhipster:/home/jhipster/app -v ~/.m2:/home/jhipster/.m2 -p 8080:8080 -p 9000:9000 -p 3001:3001 -d -t jhipster/jhipster 进入容器中 docker container exec -it --user root jhipster bash 然后就可以生成项目了。与windows上操作无差别
Gateway: springcloud Zuul Proxy 进行动态路由微服务 。
Registry:主要封装了Eureka以及配置中心Config Server。
Jhipster Console:封装了Elk监控 以及 sleuth zipkin 等分布式链路监控组件。
Jhipster Uaa: 采用UAA用户登录认证 OAUTH2集中式认证,默认不使用的话则是JWT无状态认证
上述仅仅是大体的架构,Jhipster内部使用了很多插件来进行敏捷开发,包括实体类JDL快速生成从数据库到Controller代码,开发效率非常之高。适合中小型企业采用,而且Jhipster支持DockerFile与Compose 文件生成,可以帮助我们快速容器化服务部署。