This repository was archived by the owner on Dec 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Project Tutorial(KR)
Doyun Geum edited this page Sep 14, 2020
·
1 revision
자신의 빌드툴에 따라서 아래와 같이 설정합니다.
1.1. Maven dependency
<dependency>
<groupId>io.github.ztkmkoo</groupId>
<artifactId>dss-server</artifactId>
<version>0.4.4</version>
</dependency>1.2. Gradle dependency
compile group: 'io.github.ztkmkoo', name: 'dss-server', version: '0.4.4'2.1. start server
빠르게 서버를 실행해봅니다.
code:
public class Application {
public static void main(String[] args) throws InterruptedException {
DssRestServer dssRestServer = new DssRestServer("127.0.0.1", 8181);
dssRestServer.start();
}
}console log:
May 22, 2020 12:52:48 AM io.netty.handler.logging.LoggingHandler channelRegistered
INFO: [id: 0xaa1547e9] REGISTERED
May 22, 2020 12:52:48 AM io.netty.handler.logging.LoggingHandler bind
INFO: [id: 0xaa1547e9] BIND: /127.0.0.1:8181
May 22, 2020 12:52:48 AM io.netty.handler.logging.LoggingHandler channelActive
INFO: [id: 0xaa1547e9, L:/127.0.0.1:8181] ACTIVE
telnet test:
kebron@kebron-14Z970-GA5HK:~$ telnet 127.0.0.1 8181
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.2.2 서비스 추가하기
2.2.1 서비스 클래스 생성
서비스를 처리할 클래스를 생성합니다.
2.2.1.a request 오브젝트 생성
public class MyServiceRequest implements Serializable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}2.2.1.b response 오브젝트 생성
public class MyServiceResponse implements DssRestServiceResponse {
private String result;
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}2.2.1.c myService 생성
public class MyService extends DssRestActorJsonService<MyServiceRequest> {
public MyService() {
super(new TypeReference<MyServiceRequest>() {}, "myService", "/my/service", DssRestMethodType.GET);
}
protected DssRestServiceResponse handlingRequest(DssRestServiceRequest<MyServiceRequest> dssRestServiceRequest) {
final String myName = dssRestServiceRequest.getBody().getName();
final MyServiceResponse response = new MyServiceResponse();
response.setResult("My service is " + myName + " service");
return response;
}
}2.2.2 서버에 서비스 추가하기
public class Application {
public static void main(String[] args) throws InterruptedException {
DssRestServer dssRestServer = new DssRestServer("127.0.0.1", 8181);
dssRestServer
.addDssRestService(new MyService());
dssRestServer.start();
}
}실행 로그:
2020-05-22 01:11:22 [INFO ] [DssRestServer.java]start(50) : Create actor system: akka://system
2020-05-22 01:11:22 [INFO ] [DssRestChannelInitializer.java]dssRestChannelInitializer(108) : Setup dssRestChannelInitializer
2020-05-22 01:11:22 [INFO ] [DssRestChannelInitializer.java]newAllocatedDssRestHandler(150) : freeHandlerQueue is empty. try to initialize new one: rest-handler-1
2020-05-22 01:11:22 [INFO ] [DssRestChannelInitializer.java]newAllocatedDssRestHandler(150) : freeHandlerQueue is empty. try to initialize new one: rest-handler-2
2020-05-22 01:11:22 [INFO ] [DssRestPathResolver.java]lambda$null$0(62) : Add mapping POST /your/service to yourService
2020-05-22 01:11:22 [INFO ] [DssRestPathResolver.java]lambda$null$0(62) : Add mapping GET /my/service to myService
2020-05-22 01:11:22 [INFO ] [AbstractInternalLogger.java]log(148) : [id: 0x127621ce] REGISTERED
2020-05-22 01:11:22 [INFO ] [AbstractInternalLogger.java]log(148) : [id: 0x127621ce] BIND: /127.0.0.1:8181
2020-05-22 01:11:22 [INFO ] [AbstractInternalLogger.java]log(148) : [id: 0x127621ce, L:/127.0.0.1:8181] ACTIVE
2.2.3 test
request:
## GET http://127.0.0.1:8181/my/service
{
"name" : "Kebron"
}response:
{
"result" : "My service is Kebron service"
}