0

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!');
}
Lladdmi
  • 15
  • 7
  • @Llladmi I am facing similar problem now with the same configuratio. Have you found out what cause it? – Eddy Apr 21 '21 at 20:56
  • @Eddy Unfortunatly not. I moved to the latest versions of the legacy server which is working fine (legacy-v0.11.2 at the moment) but it's deprecated and will be removed in the next version so I'm hoping they will fix this issue soon enough. – Lladdmi Apr 23 '21 at 06:56
  • If you are interested here is my question and also I posted an answer for my case: https://stackoverflow.com/questions/67214389 – Eddy Apr 23 '21 at 11:40

0 Answers0