微服务的脚手架Jhipster使用(一)

时间:2021-02-12 02:59:29

随着微服务的普及以及docker容器的广泛应用,有传统的soa服务衍生出微服务的概念,微服务强调的是服务的独立性,屏蔽底层物理平台的差异,此时你会发现微服务跟容器技术完美契合。在此基础上衍生出的云原生以及DevOps的概念,废话不多说介绍一个非常牛叉的springCloud脚手架- -jhipster。

  微服务的脚手架Jhipster使用(一)

  •     安装 
  1. 安装Java 8 from the Oracle website.
  2. 安装Node.js from the Node.js website (请安装 64-bit version)
  3. 安装npm包: npm install -g npm
  4. 如果你想使用jhipster应用市场, 请安装 Yeoman: npm install -g yo
  5. 最后安装JHipster: npm install -g generator-jhipster
  •          生成项目
  1. 选择一个空的文件夹打开cmd:jhipster 
  2. 根据一步步step提示选择构建自己的服务项目
    windows下:
    以下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市场中选择组件安装
     
  3. 如果你觉得安装这些环境太麻烦,你又熟悉docker的基本命令,那建议使用docker去生成项目;
    选择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使用(一)微服务的脚手架Jhipster使用(一)

  •          总结

          上述仅仅是大体的架构,Jhipster内部使用了很多插件来进行敏捷开发,包括实体类JDL快速生成从数据库到Controller代码,开发效率非常之高。适合中小型企业采用,而且Jhipster支持DockerFile与Compose                    文件生成,可以帮助我们快速容器化服务部署。