2023. 9. 4. 12:03ㆍ개발/Python
Faust 이론
정리
- python용 오픈 소스 스트림처리 라이브러리이다.
- 실시간 데이터 처리 작업을 효율적으로 처리하도록 설계되어 있다.
- 데이터 파이프라인, 이벤트 기반 마이크로서비스 및 실시간 분석 등 사용가능
특징
- 스트림 처리 : 데이터 스트림 처리 개념으로 구축되어 있다.
- 기능적 API : Python 함수를 사용하여 스트림 처리 작업을 정의할 수 있는 기능적 API를 제공한다.
- kafka와의 통합 : 분상 스트리밍 플랫폼인 Apache Kafka와 원활하게 통합된다.
- 정확한 1회 처리 : 정확하게 1회 처리하며 중복 없이 안정적으로 처리되게끔 보장해 준다.
- 모니터링 및 측정항목 : 모니터링 및 측정항목에 대한 기본 지원을 제공하므로 스트림처리 애플리케이션의 성능을 쉽게 추적한다.
Faust 실습
실습 내용 : 간단한 컨슈머 워커 만들기
실습 환경
환경 | 버전 |
ubuntu | 20.04 |
python | 3.8 (최소 3.6 이상) |
kafka | 3.1.1 |
1. Kafka 설치
Docker - Kafka 설치 (UI 관리자 페이지)
✔준비물 : Linux, Docker, Kafka Kafka 설치및 설정 docker-compose.yml 작성 version: '2' # docker-compose version services: zookeeper: container_name: local-zookeeper image: wurstmeister/zookeeper:3.4.6 ports: - "2181:2181" kafka: container_name:
haay.tistory.com
2. virtualenv 가상 패키지 설치
# 구축
virtualenv venv
# 적용
. venv/bin/activate
# 설치
pip install faust
3. consumer 소스 작성 (faust_consumer.py)
import faust
import logging
# 로그 level
logging.basicConfig(level=logging.WARNING)
# app 환경 설정
app = faust.App('myapp', broker='kafka://192.168.185.215:9092',)
# topic 설정
consumer_topic = app.topic('토픽명')
@app.agent(consumer_topic)
async def process_messages(messages):
async for message in messages:
# message 출력
logging.warning(f"msg = {message}")
if __name__ == '__main__':
app.main()
4. 실행 명령어
# 실행
# -l 로그 level
python faust_consumer.py worker -l warn
5. 실행 화면

6. 메시지 받은 후 화면

결론
- celery, rabbitmq를 주로 사용하였지만 이제는 대용량 처리 속도가 월등하게 높은 kafka와 faust로 많이 사용될 것 같다.
- 구축이 어렵지 않고 이미 celery, rabbitmq 지식이 존재하면 학습하기 어렵지 않다.
출처
https://faust.readthedocs.io/en/latest/index.html
Faust - Python Stream Processing — Faust 1.9.0 documentation
Faust - Python Stream Processing # Python Streams ٩(◕‿◕)۶ # Forever scalable event processing & in-memory durable K/V store; # w/ asyncio & static typing. import faust Faust is a stream processing library, porting the ideas from Kafka Streams to Py
faust.readthedocs.io
'개발 > Python' 카테고리의 다른 글
Python - Puppeteer vs Selenium vs Playwright (0) | 2023.08.01 |
---|---|
FastAPI - Redis 연동 (0) | 2023.07.31 |
FastAPI - DB 연동 (0) | 2023.07.31 |
FastAPI - 설치 (0) | 2023.07.31 |
Python - Uvicorn (0) | 2023.07.31 |