서비스 지향 아키텍처(SOA)는 애플리케이션의 기능을 서비스 단위로 분리하여 유연하게 통합 및 재사용할 수 있도록 설계된 아키텍처 패턴이다.
각 서비스는 표준 인터페이스를 통해 독립적으로 제공되며, 다양한 애플리케이션에서 이를 호출할 수 있다.
다음과 같은 문제를 해결하기 위해 SOA가 도입된다:
금융 플랫폼은 다음과 같은 서비스로 구성될 수 있다:
SOA를 사용하면 각 서비스를 독립적으로 관리하고 다른 시스템에서도 동일한 서비스를 재사용할 수 있다.
[Service Consumer]
|
[Service Registry] <---> [Service Provider]
|
[Messaging Protocols]
SOAP 기반의 SOA에서는 WSDL(Web Services Description Language)로 서비스 계약을 정의한다.
<definitions name="AccountService"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/account"
targetNamespace="http://example.com/account">
<message name="GetAccountRequest">
<part name="accountId" type="xsd:string"/>
</message>
<message name="GetAccountResponse">
<part name="accountDetails" type="xsd:string"/>
</message>
<portType name="AccountServicePortType">
<operation name="GetAccount">
<input message="tns:GetAccountRequest"/>
<output message="tns:GetAccountResponse"/>
</operation>
</portType>
<binding name="AccountServiceBinding" type="tns:AccountServicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetAccount">
<soap:operation soapAction="http://example.com/account/GetAccount"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="AccountService">
<port name="AccountServicePort" binding="tns:AccountServiceBinding">
<soap:address location="http://example.com/accountService"/>
</port>
</service>
</definitions>
@WebService
public class AccountService {
@WebMethod
public String getAccount(String accountId) {
// 예제: ID에 따라 계좌 정보 반환
return "Account details for ID: " + accountId;
}
}
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.URL;
public class AccountClient {
public static void main(String[] args) throws Exception {
URL url = new URL("http://example.com/accountService?wsdl");
QName qname = new QName("http://example.com/account", "AccountService");
Service service = Service.create(url, qname);
AccountService accountService = service.getPort(AccountService.class);
String accountDetails = accountService.getAccount("12345");
System.out.println(accountDetails);
}
}
서비스 지향 아키텍처는 이질적인 시스템 통합과 재사용성을 극대화하는 데 적합하다.
아래 글에서 다른 아키텍쳐 패턴들을 확인할 수 있다.
아키텍처 패턴 모음