[마이크로서비스] JHipster로 개발 시작하기

IMKUNYOUNG·2022년 11월 11일
0

마이크로서비스

목록 보기
1/2
post-thumbnail

JHipster

JHipster는 내외부 아키텍처 및 개발 환경 구축을 돕는다.

JHipster는 유레카, 스프링 클라우드 컨피그를 사용하여 레지스트리 및 컨피그 서비스를 제공하며, Netflix Zuul 기반의 게이트웨이, 사용자 관리 및 로그인 기능을 제공하는 프런트엔드 서비스도 통합해서 제공해준다. 따라서 게이트웨이를 만들어주는 것만으로 기본적인 사용자 관리 및 로그인 기능을 사용할 수 있음!


JHipster로 다음 순서에 따라 마이크로서비스 애플리케이션을 개발해보자!

  1. 게이트웨이 생성
  2. 레지스트리 생성
  3. 마이크로서비스 생성
  4. 생성한 마이크로서비스에 엔티티 생성
  5. 생성된 엔티티를 게이트웨이가 인식할 수 있도록 게이트웨이에 등록



게이트웨이, 레지스트리 만들기


  1. 원하는 위치에 gateway 폴더를 생성한다. mkdir gateway


  1. gateway 폴더를 JHipster 프로젝트로 설정한다 jhipster

  1. 옵션을 선택한다.

? Which type of application would you like to create? Gateway application
만들고자 하는 애플리케이션의 타입은 무엇인가요?

? Do you want to enable microfrontends? Yes
마이크로프런트 엔드를 사용하시겠습니까?

? Comma separated microfrontend app names. libraryview
마이크로프런트 앱의 이름은 무엇입니까?

? What is the base name of your application? gateway
애플리케이션의 이름은 무엇입니까?

? 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. 8080
MSA 기반에서 실행할 때 서버의 어떤 포트에서 실행하시겠습니까? 다른 포트와 충돌하지 않는 포트를 입력하세요.

? What is your default Java package name? com.mycompany.myapp
기존 자바 패키지의 이름은 무엇입니까?

? Which service discovery server do you want to use? JHipster Registry (uses Eureka, provides Spring Cloud Config support and monitoring dashboards)
디스커버리 서버로 어떤 것을 사용하고 싶으십니까?

? Which type of authentication would you like to use? JWT authentication (stateless, with a token)
사용하고자 하는 인증 타입은 무엇입니까?

? Which type of database would you like to use? SQL (H2, PostgreSQL, MySQL, MariaDB, Oracle, MSSQL)
어떤 타입의 데이터베이스를 사용하시겠습니까?

? Which production database would you like to use? MariaDB
운영용 데이터베이스로 무엇을 사용하시겠습니까?

? Which development database would you like to use? H2 with in-memory persistence
개발용 데이터베이스로 무엇을 사용하시겠습니까?

? Which cache do you want to use? (Spring cache abstraction) Hazelcast (distributed cache, for multiple nodes, supports rate-limiting for gateway applications)
Spring Cache 추상화를 사용하시겠습니까?

? Do you want to use Hibernate 2nd level cache? Yes
하이버네이트의 2단계 캐시를 사용하시겠습니까?

? Would you like to use Maven or Gradle for building the backend? Maven
백엔드 빌드를 위한 도구로 메이븐과 그레이들 중 어떤 것을 사용하시겠습니까?

? Which other technologies would you like to use? Elasticsearch as search engine, Apache Kafka as asynchronous messages broker, API first development using OpenAPI-generator
추가 기술을 사용하시겠습니까?

? Which Framework would you like to use for the client? React
클라이언트 프레임워크로 무엇을 사용하시겠습니까?

? Do you want to generate the admin UI? Yes
관리자용 UI를 생성하시겠습니까?

? Would you like to use a Bootswatch theme (https://bootswatch.com/)? Journal
Bootswatch 테마 중 어떤 테마를 사용하시겠습니까?

? Choose a Bootswatch variant navbar theme (https://bootswatch.com/)? Primary

? Would you like to enable internationalization support? Yes
국제화를 지원하십니까?

? Please choose the native language of the application Korean
애플리케이션의 주 언어를 선택하십시요

? Please choose additional languages to install English
설치할 보조 언어를 선택하십시오

? Besides JUnit and Jest, which testing frameworks would you like to use? [DEPRECATED] Protractor
테스트 프레임워크를 선택하십시오

? Would you like to install other generators from the JHipster Marketplace? No
JHipster 마켓플레이스에서 다른 제너레이터를 설치하시겠습니까


정상 설치 시

husky - Git hooks installed

added 1944 packages, and audited 1945 packages in 2m

224 packages are looking for funding
  run `npm fund` for details

2 high severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
Application successfully committed to Git from C:\Users\ur2ku\OneDrive\바탕 화면\WORKSPACE\[DDD]workspace\gateway.

If you find JHipster useful consider sponsoring the project https://www.jhipster.tech/sponsors/

Server application generated successfully.

Run your Spring Boot application:
./mvnw (mvnw if using Windows Command Prompt)

Client application generated successfully.

Start your Webpack development server with:
 npm start


> gateway@0.0.1-SNAPSHOT clean-www
> rimraf target/classes/static/app/{src,target/}

Congratulations, JHipster execution is complete!
Sponsored with ❤️  by @oktadev.

게이트웨이, 프런트엔드 서비스, 레지스트리가 모두 포함된 소스코드가 생성됨.




레지스트리 및 게이트웨이 실행


  1. 레지스트리 실행하기 (레지스트리는 도커 컨테이너로 제공되기 때문에 도커 컴포즈로 실행) docker-compose -f src/main/docker/jhipster-registry.yml up

  1. http://localhost:8761로 접속, 아이디와 패스워드 둘 다 admin 입력...


  1. 게이트웨이 실행 (메이븐 실행 명령 입력) mvn spring-boot:run

  1. http://localhost:8080으로 접속





마이크로서비스 만들기


서비스내용
도서 서비스➡️ 포트: 8081
➡️ 패키지: com.my.book
카탈로그 서비스➡️ 포트: 8082
➡️ 패키지: com.my.bookCatalog
도서 서비스➡️ 포트: 8083
➡️ 패키지: com.my.rental


도서 서비스 생성

  1. book 디렉터리 생성 mkdir book

  2. book 디렉터리에서 jhipster 명령 실행 jhipster

  3. 옵션 선택



도서 카탈로그 서비스 생성

  1. bookCatalog 디렉터리 생성 mkdir bookCatalog

  2. bookCatalog 디렉터리에서 jhipster 명령 실행 jhipster

  3. 옵션 선택



대출 서비스 생성

  1. rental 디렉터리 생성 mkdir rental

  2. rental 디렉터리에서 jhipster 명령 실행 jhipster

  3. 옵션 선택



전부 빌드 후 실행 (필요한 것은 도커 실행)

mvnw


  1. JHipster Registry


  1. Gateway






내부 아키텍처 구조 정의


엔티티 생성

  1. 도서 서비스에 book 엔티티 생성 jhipster entity book
  2. 옵션 선택

? Do you want to add a field to your entity? Yes
: 속성을 추가하시겠습니까?

? What is the name of your field? title
: 속성의 이름은 무엇입니까?

? What is the type of your field? String
속성의 타입은 무엇입니까?

? Do you want to add validation rules to your field? Yes
: 해당 속성에 검증 룰을 추가하시겠습니까?

? Which validation rules do you want to add? Required
: 어떤 검증 룰을 사용하시겠습니까?

? Do you want to use separate service class for your business logic? Yes, generate a separate service interface and implementation
: 비즈니스 로직을 위한 별도의 서비스 클래스를 만드시겠습니까?

? Do you want to use a Data Transfer Object (DTO)? Yes, generate a DTO with MapStruct
: DTO 객체를 사용하시겠습니까?

? Do you want to add filtering? Dynamic filtering for the entities with JPA Static metamodel
: 필터링 기능을 추가하시겠습니까?

? Is this entity read-only? No
: 엔티티를 읽기 전용으로 사용하시겠습니까?

? Do you want pagination and sorting on your entity? Yes, with pagination links and sorting headers
: pagination (엔티티 리스트 형식으로 반환할 때 클라이언트의 페이징 정보에 따라 리스트를 정렬해 반환) 옵션을 사용하시겠습니까?

? Overwrite src\main\resources\config\liquibase\master.xml? overwrite this and all others
: master.xml을 덮어쓰겠습니까?


  1. 도서 카탈로그 서비스에 bookCatalog 엔티티 생성 jhipster entity bookCatalog
  2. 옵션 선택


  1. Rental(대출) 서비스에 Rental, rentedItem 엔티티 생성

Rental (대출, 반납 수행)

속성역할
userId대출한 사용자 일련 번호
rentalStatus대출 가능 여부
RENT_AVAILABLE(대출 가능), RENT_UNAVAILABLE(대출 불가능)으로 열거형 처리

rentedItem (대출된 도서)

속성역할
bookId도서 일련번호
bookStatus도서 상태
rentedDate대출일
dueDate반납 예정일 (타입은 LocalDate로 정의)
  1. JDL Studio에서 JDL 형식으로 작성 (JHipster Online -> JDL Studio)
  1. ctrl+s 하여 작성한 jdl파일 내려받은 뒤 rental 디렉터리로 옮긴 후 다음 명령어를 입력 jhipster import-jdl jhipster-jdl.jdl --force



자세한 내용은 SK C&C's 의 TECH BLOG를 참고할 것!
https://engineering-skcc.github.io/

0개의 댓글