• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

instance_id 대신 port를 보여주는 방법은 없을까요?

21.04.14 18:35 작성 조회수 720

1

잘 설명해주신 덕분에 강의 잘 따라가고 있습니다.

혹시 ${spring.application.instance_id:${random.value}
대신 port를 보여주는 방법은 없을까요?

실행되는 클라이언트가 많아질수록 instance_id가 너무 길어져보일까봐요.

답변 1

답변을 작성해보세요.

5

안녕하세요, 이도원입니다. 

application.yml 설정 파일에서 랜덤 포트를 사용하기 위해 server.port=0라고 설정한 다음 instance-id에서 ${server.port}로 불러오게 되면, 할당 된 랜덤 포트가 아닌 "0"이라는 값이 표시됩니다. 만약 랜덤 포트도 사용하고 instance-id에서도 할당 된 램덤 포트를 사용해 보실려면 다음과 같이 해 보세요. 

server:
# port: 0
port: ${random.int(50000,51000)}

eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://127.0.0.1:8761/eureka
instance:
# instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}
instance-id: ${spring.application.name}:${server.port}


위와 같이 설정하면, 50000-51000 사이의 포트가 설정되고, 해당 값이 instance-id에 표시 됩니다.

감사합니다.

추가 답변을 아래 게시글에서 확인하실 수 있습니다, 참고하세요.

https://www.inflearn.com/questions/211844

채널톡 아이콘