Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

Docker mercure not sending updates with symfony

I made simple docker based application with NGINX, PHP, PostgreSQL, Node, Mercure and Symfony just to test the capabilities of Mercure. The problem is that I'm not getting any updates from Symfony publisher service, there's no errors in logs, no errors in Symfony profiler, CORS is working properly. Sending updates trough mercure ui is working just fine.

I'm using latest dunglas/mercure image along with PHP 7.4 and Symfony 5.2.2

My docker-compose file:

version: '3'

networks:
    backend:

services:

    # nginx
    nginx-service:
        image: nginx:stable-alpine
        container_name: nginx-container
        ports:
            - "8080:80"
        volumes:
            - ./app:/var/www/project
            - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
        depends_on:
            - php74-service
            - postgres11-service
        networks:
            - backend

    # php
    php74-service:
        build:
            context: .
            dockerfile: ./php/Dockerfile
        container_name: php74-container
        ports:
            - "9000:9000"
        volumes:
            - ./app:/var/www/project
        networks:
            - backend

    #postgres
    postgres11-service:
        image: postgres:11-alpine
        container_name: postgres11-container
        ports:
            - "5432:5432"
        volumes:
            - ./postgres:/var/libpostgresql/data
        restart: always
        environment:
            POSTGRES_USER: main
            POSTGRES_PASSWORD: secret
        networks:
            - backend

    # node
    node-service:
        image: node:latest
        container_name: node-container
        volumes:
            - ./app:/var/www/project
        working_dir: /var/www/project
        networks:
            - backend

    # mercure
    mercure:
        image: dunglas/mercure:latest
        volumes:
            - ./Caddyfile:/etc/caddy/Caddyfile
        container_name: mercure-container
        ports:
            - 9090:80
        networks:
            - backend

My Caddyfile configuration

{
    # Debug mode (disable it in production!)
    debug
    # HTTP/3 support
    experimental_http3
}

# The address of your server
localhost:80

# enable logs
log

route {
    # redirect to ui
    redir / /.well-known/mercure/ui/

    mercure {
        demo
        # Publisher JWT key
        publisher_jwt !ChangeMe!
        # Subscriber JWT key
        subscriber_jwt !ChangeMe!
        cors_origins http://localhost:8080
        publish_origins http://localhost:8080
        anonymous
    }

    respond "Not Found" 404
}

My .env cofiguration of mercure: (default token with !ChangeMe! key)

MERCURE_PUBLISH_URL=http://mercure/.well-known/mercure
MERCURE_JWT_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOltdfX0.Oo0yg7y4yMa1vr_bziltxuTCqb8JVHKxp-f_FwwOim0

Symfony function:

public function push(PublisherInterface $publisher): Response
{
    $update = new Update(
        'test',
        json_encode(['status' => 'new update'])
    );

    // The Publisher service is an invokable object
    $publisher($update);

    return new Response('published!');
}
question from:https://stackoverflow.com/questions/65951908/docker-mercure-not-sending-updates-with-symfony

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...