1
version: '3.7'
services:
 db:
 image: mariadb:10.2.29
 ports:
 - "3307:3306" #outside:inside docker container from within
 environment:
 - MYSQL_DATABASE=test_db
 - MYSQL_ROOT_PASSWORD=toor
 volumes:
 - persistent:/var/lib/mysql
 - ./docker/build/db/:/docker-entrypoint-initdb.d/
 networks:
 - symfony
 nginx:
 build:
 context: ./docker
 dockerfile: Dockerfile-nginx
 volumes:
 - ./:/var/www/project/:cached
 ports:
 - 8080:80 # Ports that are exposed, you can connect to port 8001 to port 80 of the container.
 links:
 - php
 - mercure
 networks:
 - symfony
 php:
 build:
 context: ./docker
 dockerfile: Dockerfile-php
 expose:
 - 2443
 environment:
 - DATABASE_URL=mysql://root:toor@db/test_db
 volumes:
 - ./:/var/www/project/:cached # Location of the project for php-fpm. Note this should be the same for NGINX.*
 - ./docker/build/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
 - ./docker/build/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
 links:
 - mercure
 networks:
 - symfony
 ###> symfony/mercure-bundle ###
 mercure:
 image: dunglas/mercure
 restart: unless-stopped
 ports:
 - 8081:3000
 environment:
 SERVER_NAME: ':3000'
 MERCURE_PUBLISHER_JWT_KEY: ${MERCURE_JWT_SECRET}
 MERCURE_SUBSCRIBER_JWT_KEY: ${MERCURE_JWT_SECRET}
 # Set the URL of your Symfony project (without trailing slash!) as value of the cors_origins directive
 MERCURE_EXTRA_DIRECTIVES: |-
 cors_origins *
 anonymous
 command: /usr/bin/caddy run --config /etc/caddy/Caddyfile.dev
 volumes:
 - mercure_data:/data
 - mercure_config:/config
 networks:
 - symfony
volumes:
 mercure_data:
 mercure_config:
 persistent:
networks:
 symfony:

config/packages/mercure.yaml

mercure:
 hubs:
 default:
 url: '%env(MERCURE_PUBLIC_URL)%'
 jwt:
 secret: '%env(MERCURE_JWT_SECRET)%'
 publish: [ '*' ]

I have this configuration for my symfony application. The Mercure hub is running fine on localhost:8081. If I send an update over the UI of the hub, my javascript client can receive the update.

The problem is I can not publish an update with HubInterface like this.

$update = new Update('https://example.com/my-private-topic', json_encode($message));
$hub->publish($update);

This said: failed to send an update and nothing more.

I tried to use another JWT according to documentation of symfony 6.3.

// Publisher's JWT must contain this topic, a URI template it matches or * in mercure.publish or you'll get a 401
// Subscriber's JWT must contain this topic, a URI template it matches or * in mercure.subscribe to receive the update

But obvisiously it did not help.

I tried to configure in yaml file like this but nothing happend

framework:
 http_client:
 default_options:
 verify_peer: false
asked Oct 16, 2023 at 20:46
1
  • Try opening example.com:8081/.well-known/mercure. It should say: Missing "topic" parameter. If it does, that need to be your MERCURE_URL and MERCURE_PUBLILC_URL Commented Mar 13, 2024 at 13:54

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.