微服務的腳手架Jhipster使用(一)

隨着微服務的普及以及docker容器的普遍應用,有傳統的soa服務衍生出微服務的概念,微服務強調的是服務的獨立性,屏蔽底層物理平臺的差別,此時你會發現微服務跟容器技術完美契合。在此基礎上衍生出的雲原生以及DevOps的概念,廢話很少說介紹一個很是牛叉的springCloud腳手架- -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  進行動態路由微服務html

  Registry:主要封裝了Eureka以及配置中心Config Server。java

       Jhipster Console:封裝了Elk監控 以及 sleuth zipkin 等分佈式鏈路監控組件。node

       Jhipster Uaa:  採用UAA用戶登陸認證 OAUTH2集中式認證,默認不使用的話則是JWT無狀態認證linux

      

  •          總結

          上述僅僅是大致的架構,Jhipster內部使用了不少插件來進行敏捷開發,包括實體類JDL快速生成從數據庫到Controller代碼,開發效率很是之高。適合中小型企業採用,並且Jhipster支持DockerFile與Compose                    文件生成,能夠幫助咱們快速容器化服務部署。web

相關文章
相關標籤/搜索