Spring/[인프런] Spring Cloud

Catalogs, Orders Microservice

쵼쥬 2022. 6. 19. 15:26
기능 마이크로서비스 URI(API Gateway 사용시) HTTP Method
상품 목록 조회 Catalogs Microservice /catalog-service/catalogs GET
사용자별 상품 주문 Orders Microservice /order-service/{user_id}/orders POST
사용자별 주문 내역 조회 Orders Microservice /order-service/{user_id}/orders GET

Catalogs Microservice 프로젝트 생성

Dependencies

DevTools, Lombok, Spring Web, Spring Data JPA, Eureka Discovery Client, H2, modelmapper

 

application.yml

server:
  port: 0 # random port 실행함

spring:
  application:
    name: datalog-service
  h2:
    console:
      enabled: true
      settings:
        web-allow-others: true
      path: /h2-console
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:mem:testdb
  jpa:
    hibernate:
      ddl-auto: create-drop
    show-sql: true
    generate-ddl: true
    database: h2
    defer-datasource-initialization: true


eureka:
  instance:
    instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}

  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://127.0.0.1:8761/eureka

logging:
  level:
    com.example.catalogservice: DEBUG

Orders Microservice 프로젝트 생성

Dependencies

DevTools, Lombok, Spring Web, Spring Data JPA, Eureka Discovery Client, H2, modelmapper

 

application.yml

server:
  port: 0 # random port 실행함

spring:
  application:
    name: order-service
  h2:
    console:
      enabled: true
      settings:
        web-allow-others: true
      path: /h2-console
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:mem:testdb
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    generate-ddl: true
    database: h2


eureka:
  instance:
    instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}

  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://127.0.0.1:8761/eureka

logging:
  level:
    com.example.orderservice: DEBUG

 

Entity를 직렬화 (마샬링, 언마샬링하기 위해)