본문 바로가기
DEV/MSA

Eureka Service 만들기

by 땅콩둘기 2021. 3. 9.
반응형

1.  Service, ServiceBase생성

2.  ServiceBase 소켓연결부분에 추가

while(true) {                                               
            Socket s = serverSocket.accept();           
                                                            
        	   OutputStream out = s.getOutputStream();
                                                                       
               DataOutputStream dos = new DataOutputStream(out);
               byte[] body = "Hello World".getBytes();
                                                              
                                                                  
               dos.writeBytes("HTTP/1.1 200 OK \r\n");
               dos.writeBytes("Content-Type: text/html;charset=utf-8\r\n");
               dos.writeBytes("Content-Length: " + body.length + "\r\n");
               dos.writeBytes("\r\n");
                                                    
               dos.write(body, 0, body.length);
               dos.writeByte(myServingPort);
               dos.writeBytes("\r\n");
               dos.flush();              
        	   System.out.println("Client got connected... processing request from the client");             
        	   processRequest(s);

3. Build.gradle runtask 생성하기

task runTestService (dependsOn: [classes], type: JavaExec) {
	group = "Run tasks"
	description = "Run the test service"
	main = "com.netflix.eureka.TestEurekaService"
	classpath = sourceSets.main.runtimeClasspath
	jvmArgs(["-Deureka.client.props=sample-eureka-service"])
}
task TestServiceStartScript(type: CreateStartScripts) {
	mainClassName = "com.netflix.eureka.TestEurekaService"
	applicationName = "TestEurekaService"
	outputDir = new File(project.buildDir, 'scripts')
	classpath = jar.outputs.files + project.configurations.runtime
	defaultJvmOpts = ["-Deureka.client.props=sample-eureka-service"]
}
from(TestServiceStartScript)
	fileMode = 0755

4. Service에서 Run as -> Gradle test

5. properties파일에 원하는 instance이름을 설정해준다.

eureka.instanceId=${eureka.name}:${eureka.port}

6. Eureka-example run task runTestService 실행

반응형

'DEV > MSA' 카테고리의 다른 글

MSA 시작하기 - Zuul  (0) 2021.03.11
MSA 시작하기 - Ribbon  (0) 2021.03.10
Spring Boot 에서 Eureka 시작하기  (0) 2021.03.08

댓글