Lagom Core Concepts

Lagom Core Concepts

Lagom Core Concepts

이 글에서는 Lagom 프레임워크의 핵심 개념을 설명하고, 예제 코드로 MembershipService.scala를 분석합니다.

📌 Lagom 개요

Lagom은 **마이크로서비스 아키텍처(MSA)**를 구축하기 위한 Scala 기반 프레임워크입니다.

Lagom의 주요 특징

  • Service API 중심 개발: 서비스 인터페이스를 정의하고 구현을 분리할 수 있음.
  • Event Sourcing & CQRS 지원: 데이터 변경을 이벤트로 관리.
  • 비동기, 반응형 시스템: Akka와 Play 기반으로 높은 확장성 제공.
  • 개발 편의성: Lagom Dev Mode를 활용한 빠른 개발 사이클.

Lagom 구조

🏗 MembershipService 예제

아래는 Lagom에서 제공하는 MembershipService의 정의입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.example.membership.api

import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.api.transport.Method
import com.lightbend.lagom.scaladsl.api.{Descriptor, Service, ServiceCall}

trait MembershipService extends Service {
def join(name: String): ServiceCall[NotUsed, Done]
def leave(name: String): ServiceCall[NotUsed, Done]
def get(name: String): ServiceCall[NotUsed, String]

override final def descriptor: Descriptor = {
import Service._
named("membership")
.withCalls(
restCall(Method.PUT, "/membership/:name", join _),
restCall(Method.DELETE, "/membership/:name", leave _),
restCall(Method.POST, "/membership/:name", get _)
)
.withAutoAcl(true)
}
}

🛠 코드 설명

  • ServiceCall[NotUsed, Done]: 요청과 응답을 정의하는 Lagom의 핵심 개념.
  • join, leave, get: REST 엔드포인트를 제공하는 메서드.
  • descriptor: 서비스의 API 정의.
  • restCall: HTTP REST 엔드포인트 매핑.

🔗 참고 자료

🔚 결론

Lagom은 Scala 기반의 마이크로서비스 프레임워크로, 서비스 API 중심으로 개발을 진행할 수 있도록 돕습니다. 이 글에서는 MembershipService 예제를 통해 Lagom의 기본적인 구조와 특징을 살펴보았습니다. 🚀

Author

Hamin Lee

Posted on

2022-01-17

Updated on

2022-01-24

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.
You need to set client_id and slot_id to show this AD unit. Please set it in _config.yml.