2

I have a symfony / api PLatform server. I added Mercure to send SSE to API clients. On my client side I subscribe using event Source Polyfill.

I manage to receive the messages, but I have the following error :

Error: No activity within 45000 milliseconds. 2 chars received. Reconnecting.

I read that a heartbeat was needed to kieep connection alive and avoid this error.

I then added the heartbeat instruction to the hub command line :

SERVER_NAME=:3000 MERCURE_PUBLISHER_JWT_KEY='toto' MERCURE_SUBSCRIBER_JWT_KEY=$(cat ../config/jwt/public.pem) MERCURE_SUBSCRIBER_JWT_ALG=RS256 HEARTBEAT_INTERVAL=15s READ_TIMEOUT=2m ./mercure run -config Caddyfile.dev

but nothing changed. I still have this error.

What did I miss?

thank you for your help

Alexglvr
  • 427
  • 5
  • 18

1 Answers1

1

You need to add the following config in Caddyfile => heartbeat 15s

route {
    encode zstd gzip

    mercure {
        # Transport to use (default to Bolt)
        transport_url {$MERCURE_TRANSPORT_URL:bolt://mercure.db}
        # Publisher JWT key
        publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
        # Subscriber JWT key
        subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY} {env.MERCURE_SUBSCRIBER_JWT_ALG}
        
        heartbeat 15s
        
        # Extra directives
        {$MERCURE_EXTRA_DIRECTIVES}
    }

    respond /healthz 200

    respond "Not Found" 404
}
radu c
  • 4,138
  • 7
  • 30
  • 45