优化代码

This commit is contained in:
2026-01-29 15:10:58 +00:00
parent 0e9c7dfe85
commit 0bd4df686c
4 changed files with 17 additions and 6 deletions

View File

@@ -1,2 +1,2 @@
FROM python:3.11-slim FROM python:3.11-slim
RUN pip install python-binance aiokafka aioredis py-spy uvloop RUN pip install python-binance aiokafka aioredis py-spy uvloop loguru dynaconf

10
docker-compose.yml Normal file
View File

@@ -0,0 +1,10 @@
services:
data-collect:
network_mode: host
build: .
command: python main.py
extra_hosts:
- redpanda-0:10.0.0.139
volumes:
- .:/app
working_dir: /app

View File

@@ -1,7 +1,8 @@
from aiokafka import AIOKafkaProducer from aiokafka import AIOKafkaProducer
import os
kafka_nodes = os.environ.get("kafka.nodes","redpanda-0:19092")
# Kafka 配置 # Kafka 配置
KAFKA_BOOTSTRAP_SERVERS = '127.0.0.1:19092' KAFKA_BOOTSTRAP_SERVERS = kafka_nodes
# KAFKA_TOPIC = 'binance_agg_trade' # KAFKA_TOPIC = 'binance_agg_trade'
class KafkaProducerSingleton: class KafkaProducerSingleton:

View File

@@ -4,8 +4,8 @@ import asyncio
from comsumer import bn_agg_trade, order from comsumer import bn_agg_trade, order
async def main(): async def main():
a1 = bn_agg_trade.main() a1 = bn_agg_trade.main()
a2 = order.start() # a2 = order.start()
res = asyncio.gather(a1, a2) res = asyncio.gather(a1)
await res await res
if __name__ == "__main__": if __name__ == "__main__":