You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Symfony provides a straightforward component, built on top of
18
18
`the Mercure protocol`_, specifically designed for this class of use cases.
19
19
20
-
Mercure is an open protocol designed from the ground to publish updates from
20
+
Mercure is an open protocol designed from the ground up to publish updates from
21
21
server to clients. It is a modern and efficient alternative to timer-based
22
22
polling and to WebSocket.
23
23
24
24
Because it is built on top `Server-Sent Events (SSE)`_, Mercure is supported
25
-
out of the box in most modern browsers (old versions of Edge and IE require
25
+
out of the box in modern browsers (old versions of Edge and IE require
26
26
`a polyfill`_) and has `high-level implementations`_ in many programming
27
27
languages.
28
28
@@ -42,49 +42,44 @@ generated using the API Platform client generator.
42
42
Installation
43
43
------------
44
44
45
-
Running a Mercure Hub
46
-
~~~~~~~~~~~~~~~~~~~~~
45
+
Installing the Symfony Bundle
46
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
+
48
+
Run this command to install the Mercure support:
49
+
50
+
.. code-block:: terminal
51
+
52
+
$ composer require mercure
47
53
48
54
To manage persistent connections, Mercure relies on a Hub: a dedicated server
49
55
that handles persistent SSE connections with the clients.
50
56
The Symfony app publishes the updates to the hub, that will broadcast them to
51
57
clients.
52
58
53
-
.. image:: /_images/mercure/schema.png
54
-
55
-
An official and open source (AGPL) Hub based on the Caddy web server
56
-
can be downloaded as a static binary from `Mercure.rocks`_.
57
-
A Docker image, a Helm chart for Kubernetes
58
-
and a managed, High Availability Hub are also provided.
59
-
60
-
If you use `Symfony Docker`_ or the `API Platform distribution`_, a Mercure Hub
61
-
is automatically installed and your Symfony application is automatically
62
-
configured to use it. You can jump directly to the next section.
59
+
Thanks to :ref:`the Docker integration of Symfony </setup/docker>`,
60
+
:ref:`Flex <symfony-flex>` proposes to install a Mercure hub.
61
+
Run ``docker-compose up`` to start the hub if you have chosen this option.
63
62
64
63
If you use the :doc:`Symfony Local Web Server </setup/symfony_server>`,
65
-
a Mercure hub will be automatically available as a Docker service thanks to its
66
-
:ref:`Docker integration <symfony-server-docker>.
67
-
68
-
Be sure that recent versions of Docker and Docker Compose are properly installed
69
-
on your computer and to start the Symfony Local Web Server with the ``--no-tls``
70
-
option:
64
+
you must start it with the ``--no-tls`` option.
71
65
72
66
.. code-block:: terminal
73
67
74
68
$ symfony server:start --no-tls -d
75
69
76
-
Installing the Symfony Bundle
77
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
-
79
-
Run this command to install the Mercure support before using it:
70
+
Running a Mercure Hub
71
+
~~~~~~~~~~~~~~~~~~~~~
80
72
81
-
.. code-block:: terminal
73
+
.. image:: /_images/mercure/schema.png
82
74
83
-
$ composer require mercure
75
+
If you use the Docker integration, a hub is already up and running,
76
+
and you can go straight to the next section.
84
77
85
-
:ref:`Symfony Flex <symfony-flex>` has automatically installed and configured
86
-
MercureBundle. It also created (if needed) and configured a Docker Compose
87
-
definition that provides a Mercure service. Run ``docker-compose up`` to start it.
78
+
Otherwise, and in production, you have to install a hub by yourself.
79
+
An official and open source (AGPL) Hub based on the Caddy web server
80
+
can be downloaded as a static binary from `Mercure.rocks`_.
81
+
A Docker image, a Helm chart for Kubernetes
82
+
and a managed, High Availability Hub are also provided.
88
83
89
84
Configuration
90
85
-------------
@@ -95,23 +90,26 @@ The preferred way to configure MercureBundle is using
95
90
When MercureBundle has been installed, the ``.env`` file of your project
96
91
has been updated by the Flex recipe to include the available env vars.
97
92
98
-
If you use the Symfony Local Web Server, Symfony Docker or the API Platform
99
-
distribution, the Symfony app is automatically configured and you can skip
100
-
straight to the next section.
93
+
Also, if you are using the Docker integration with the Symfony Local Web Server,
94
+
`Symfony Docker`_ or the `API Platform distribution`_,
95
+
the proper environment variables have been automatically set.
96
+
Skip straight to the next section.
101
97
102
98
Otherwise, set the URL of your hub as the value of the ``MERCURE_URL``
103
99
and ``MERCURE_PUBLIC_URL`` env vars.
104
100
Sometimes a different URL must be called by the Symfony app (usually to publish),
105
101
and the JavaScript client (usually to subscribe). It's especially common when
106
102
the Symfony app must use a local URL and the client-side JavaScript code a public one.
107
-
In this case, ``MERCURE_URL`` must contain the local URL that will be used by the
103
+
In this case, ``MERCURE_URL`` must contain the local URL used by the
108
104
Symfony app (e.g. ``https://mercure/.well-known/mercure``), and ``MERCURE_PUBLIC_URL``
109
105
the publicly available URL (e.g. ``https://example.com/.well-known/mercure``).
110
106
111
107
The clients must also bear a `JSON Web Token`_ (JWT)
112
108
to the Mercure Hub to be authorized to publish updates and, sometimes, to subscribe.
113
109
114
-
This token must be signed with the same secret key as the one used by the Hub to verify the JWT (``!ChangeMe!`` in you use the Local Web Server or Symfony Docker), which should be stored in the ``MERCURE_JWT_SECRET`` environment variable.
110
+
This token must be signed with the same secret key as the one used by the Hub to verify the JWT (``!ChangeMe!`` in you use the Docker integration).
111
+
This secret key must be stored in the ``MERCURE_JWT_SECRET`` environment variable.
112
+
MercureBundle will use it to automatically generate and sign the needed JWTs.
115
113
116
114
If you don't want to use the provided environment variables,
117
115
use the following configuration:
@@ -155,6 +153,68 @@ use the following configuration:
155
153
],
156
154
]);
157
155
156
+
Alternatively, it's also possible to pass directly the JWT to use:
0 commit comments