실습 프로젝트 아키텍처

Untitled


Producer Web 프로젝트

  1. Spring Initializr에서 프로젝트 생성

    Untitled

  2. application.properties 파일 수정

    spring.h2.console.enabled=true
    spring.h2.console.path=/h2-console
    spring.datasource.generate-unique-name=false
    spring.jpa.show-sql=true
    spring.jpa.properties.hibernate.format_sql=true
    
  3. kafka topic 생성

    1. checkout에서 생성한 데이터를 발행하고 consume

      bin/kafka-topics.sh --create --topic checkout.complete.v1 --partitions 5 --bootstrap-server localhost:9092

    2. product id별 합산 금액 발행

      bin/kafka-topics.sh --create --topic checkout.aggregated.v1 --partitions 5 --bootstrap-server localhost:9092

  4. 코드 작성

    1. 테스트 - CheckOutSubmitControllerTest.java

      @ExtendWith(SpringExtension.class)
      @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
      @AutoConfigureMockMvc
      public class CheckOutSubmitControllerTest {
      
          @Autowired
          private MockMvc mockMvc;
      
          @Test
          public void testPostSubmitCheckOut() throws Exception {
      
              mockMvc.perform(post("/submitCheckOut")
                              .param("memberId","10001")
                              .param("productId","200001")
                              .param("amount", "33000")
                              .param("shippingAddress","546"))
                      .andExpect(status().isOk())
                      .andDo(print());
          }
      }
      
  5. 서버 실행 후 확인

    1. http://localhost:8080/checkOutForm 에서 데이터 전송

      Untitled

    2. 결과

      Untitled

      Untitled

    3. 데이터베이스 확인 - http://localhost:8080/h2-console

      Untitled

      Untitled