I have a jetty server running cometd. I would like to have 2 instances of Bayeux server at the same time running under different servlet paths.
Reason is I need to configure one of the instances with few extensions while the other should have no extension.
Is this achievable in some way?
UPDATE
Just tried with recommendation from sbordet from a new project started using primer section from the docu. I used Cometd 5. Result is that BayeuxServer
is created only once even when configured twice in web.xml
because CometDServlet
which is in charge of initialising BayeuxServer
has some singleton-like code:
this._bayeux = (BayeuxServerImpl)this.getServletContext().getAttribute("org.cometd.bayeux");
if (this._bayeux == null) {
export = true;
this._bayeux = this.newBayeuxServer();....
So once the server is created it seems to be stored on the Servlet Context attribute and on subsequent calls seems to be retrieved from there. This impede me to have two different configured servers as I expected.
Yes it is possible to have two (or more) different BayeuxServer
instances on the same server, under different Servlet mappings.
You just need to configure two CometDServlet
s in web.xml
, or configure two CometDHandler
s (in CometD 8) under different mappings as children of a PathMappingsHandler
.
On the client, you need to create two client instances pointing to the different URIs, depending on what BayeuxServer
you want to hit.
Note that the BayeuxServer
s will be separated: each will have its own sessions, channels, subscribers, listeners, etc.
The two BayeuxServer
s can communicate server-to-server using a Java CometD client.
UPDATE
By default, the BayeuxServer
instance is stored as a Servlet context attribute, which does not allow two different instances to be created.
However, being this a special case, it should not be difficult to write a Servlet similar to CometDServlet
that creates an instance without looking at the Servlet context.
I agree that this should be provided by CometD. I filed https://github.com/cometd/cometd/issues/1782 to fix this issue.