Код: Выделить всё
~$ docker exec -it blopa-kafka-1 /bin/bash
I have no name!@8b166cb3a647:/$ kafka-topics.sh --bootstrap-server 127.0.0.1:9092 --list
__consumer_offsets
boton_topic
dht_topic
gps_topic
pulso_topic
Код: Выделить всё
KAFKA_BOOTSTRAP_SERVERS = os.getenv('KAFKA_BOOTSTRAP_SERVERS', '192.168.1.211:9092')
app = FastAPI()
def ckeck_conectivity_kafka(kafka_bootstrap_servers):
kafka_host, kafka_port = kafka_bootstrap_servers.split(':')
try:
with socket.create_connection((kafka_host, int(kafka_port)), timeout=10) as sock:
except Exception as e:
error_message = f"[ERROR datos_kafka] Not conection {kafka_bootstrap_servers}: {e}"
logger.error(error_message))
check_conectivity_kafka(KAFKA_BOOTSTRAP_SERVERS)
@asynccontextmanager
async def lifespan(app: FastAPI):
global producer
try:
producer = AIOKafkaProducer(
bootstrap_servers=KAFKA_BOOTSTRAP_SERVERS
)
await producer.start()
except Exception as e:
await asyncio.sleep(5)
yield
return
yield
...
app.router.lifespan_context = lifespan
Код: Выделить всё
INFO: Started server process [135789]
INFO: Waiting for application startup.
ERROR:aiokafka:Unable connect to node with id 0: [Errno -2] Name or service not known
KafkaConnectionError: No connection to node with id 0
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8001 (Press CTRL+C to quit)
Это мой . yaml:
Код: Выделить всё
services:
kafka:
image: 'bitnami/kafka:latest'
environment:
- KAFKA_CFG_NODE_ID=0
- KAFKA_CFG_PROCESS_ROLES=controller,broker
- KAFKA_CFG_LISTENERS=PLAINTEXT://0.0.0.0:9092,CONTROLLER://:9093
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT>
- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:9093
- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.1.211:9092
volumes:
- kafka-data:/bitnami/kafka/data
tty: true
restart: always
ports:
- "9092:9092"
- "9093:9093"
- "9094:9094"
volumes:
kafka-data:
driver: local
Код: Выделить всё
telnetКод: Выделить всё
nc -zv 192.168.1.211 9092
192.168.1.211: inverse host lookup failed: Unknown host
(UNKNOWN) [192.168.1.211] 9092 (?) open
но я предполагаю, что какая-то проблема в конфигурации не позволяет моему коду работать.
Подробнее здесь: https://stackoverflow.com/questions/790 ... s-problems