1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Traefik: Stream dataflow between application does not work

Discussão em 'Python' iniciado por Stack, Setembro 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following and basic docker setup where the factory-service creates a continues dataflow which is exposed through Fast API and shall be consumed by another container verification-service. Between both container I want to use Traefik to function as Load Balancer.

    I'm able to consume the data stream directly using http://localhost:8001/stream and also through Traefik http://factory.localhost/stream. But unfortunately I'm not able to consume the stream in another docker container.

    FastAPI in factory-service:

    @app.get("/stream")
    async def stream_data():
    return StreamingResponse(generate_sensor_data(), media_type="text/event-stream")


    verification-service:

    import requests

    print("Connecting ...")
    response = requests.get("http://factory.localhost/stream", stream=True)
    print(response.status_code, response.text)


    Docker-compose:

    services:
    factory-service:
    build:
    context: ./factory
    dockerfile: Dockerfile
    container_name: factory_service
    ports:
    - "8001:8001"
    labels:
    - "traefik.enable=true"
    - "traefik.http.routers.factory.rule=Host(`factory.localhost`)"
    - "traefik.http.services.factory.loadbalancer.server.port=8001"
    - "traefik.http.middlewares.sse.headers.customResponseHeaders.Access-Control-Allow-Origin=*"
    - "traefik.http.middlewares.sse.headers.customResponseHeaders.Cache-Control=no-cache"
    - "traefik.http.middlewares.sse.headers.customResponseHeaders.Connection=keep-alive"
    - "traefik.http.routers.factory.middlewares=sse"
    - "traefik.http.routers.factory.entrypoints=web"
    networks:
    - app-network

    verification-service:
    build:
    context: ./verification
    dockerfile: Dockerfile
    container_name: verification_service
    depends_on:
    factory-service:
    condition: service_started
    networks:
    - app-network

    traefik:
    image: traefik:v3.3
    command:
    - "--log.level=DEBUG"
    - "--api.insecure=true"
    - "--providers.docker"
    - "--providers.docker.exposedbydefault=false"
    - "--entryPoints.web.address=:80"
    ports:
    - "80:80"
    - "8080:8080"
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    networks:
    - app-network

    networks:
    app-network:
    driver: bridge


    I already saw the following questions and good documentation from flexguse but I'm not able to translate their solution into my case

    Traefik: HTTPS access between applications does not work

    https://github.com/flexguse/traefik-inter-container-routing

    Continue reading...

Compartilhe esta Página