Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

어읽로꾸거

[Python] Fast Api 에서 Eureka 연결하기 본문

정리

[Python] Fast Api 에서 Eureka 연결하기

어읽로꾸거 2022. 8. 27. 20:43

FastApi로 MSA 서비스를 만들었다.

 

이걸 Eureka에 연결해보자

 

pip install py_eureka_client

pip에서 py_eureka_client를 설치해주고

from fastapi import FastAPI

import py_eureka_client.eureka_client as eureka_client
import py_eureka_client.logger as logger

app = FastAPI()

@app.on_event("startup")
async def startup_event():
	await eureka_client.init_async(eureka_server="유레카 서버의 IP",
                                   app_name="서비스의 이름", 
                                   instance_port=포트, 
                                   instance_host="이 서버가 있는 IP"
                                   )

이렇게 설정하면 된다.

 

async로 연결한 이유는 sync로 연결시 에러가 발생하기 때문