symfonymercure

Symfony Mercure : Failed to send an update


Since now 2 days I'm trying to setup mercure and Symfony project to be able to talk together

My Mercure server is a container behind nginx and seems to works :

curl -d 'topic=https://example.com/books/1' -d 'data={"foo": "updated value"}' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdfX0.5zgB1OBh7fwae_97lhU-3u59c2z0Q0vknvN3zuP7yfs' -X POST -k https://10.145.90.xxx/mercure

The output is :

urn:uuid:d6dcf0b5-9c87-4ef0-9400-e9496bbe71b6

Now in my .env file into symfony :

MERCURE_PUBLIC_URL=https://10.145.90.xxx/mercure
MERCURE_URL=https://10.145.90.xxx/mercure
MERCURE_JWT_SECRET="2gtdpkx8AzLL0FBsCBmKEa66qIrccMW6LeRX"

My Mercure config is the default one :

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

And My framework to don't check the certificate:

framework:
    ...
    http_client:
        default_options:
            verify_peer: false

With this curl commands works I can GET and POST data but not symfony.

I get the following error "Handling \"Symfony\\Component\\Mercure\\Update\" failed: Failed to send an update.",

This is how I build the update:

$update = new Update(
    $entity->mercureTopic(),
    json_encode([
        'user' => $user === null ? 'UNDEFINED' : $user->getUserIdentifier(),
        'action' => 'version_incremented',
        'orderId' => $entity->getId()
    ])
);
$this->getMessageBus()->dispatch($update);

Any idea what I missed ? Do you have a way to see more details on the issue ?

Thank you for your help


Solution

  • Try using the container name in your .env file:

    MERCURE_PUBLIC_URL=https://container-name/mercure
    MERCURE_URL=https://container-name/mercure