title: Cometd Oort Cluster - Spring configuration
body: <p>I am trying to enable Oort with multicast in our Comet app following <a href="https://github.com/cometd/cometd/blob/master/cometd-java/cometd-java-oort/src/test/java/org/cometd/oort/spring/OortConfigurator.java" rel="nofollow noreferrer">this</a> example. I just need the Oort now. Not the Seti part. But Oort doesn't seem to be working. I have the cometd debug enabled and I don't see Oort being initialized. </p>
  
  <p>I also tested by running two instances of Oort nodes in my local(on different ports), say A and B. Have the client connect to node A. I would then publish a message from node A on <code>/user/*</code> channel and client receives it. But if I publish a message from node B, client doesn't get anything.</p>
  
  <p>Spring Configuration:</p>
  
  <pre class="lang-java prettyprint-override"><code>import org.cometd.annotation.ServerAnnotationProcessor;
  import org.cometd.bayeux.server.BayeuxServer;
  import org.cometd.oort.Oort;
  import org.cometd.oort.OortMulticastConfigServlet;
  import org.cometd.oort.OortMulticastConfigurer;
  import org.cometd.server.BayeuxServerImpl;
  import org.cometd.server.transport.AsyncJSONTransport;
  import org.cometd.server.transport.JSONTransport;
  import org.cometd.websocket.server.WebSocketTransport;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.BeansException;
  import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.context.ServletContextAware;
  
  import javax.annotation.PostConstruct;
  import javax.servlet.ServletContext;
  
  @Configuration
  public class BayeuxInitializer implements DestructionAwareBeanPostProcessor, ServletContextAware {
  
      private ServerAnnotationProcessor processor;
      private ServletContext context;
  
      @PostConstruct
      private void init() {
          BayeuxServer bayeuxServer = bayeuxServer();
          this.processor = new ServerAnnotationProcessor(bayeuxServer);
          Oort oort = oort();
          oort.observeChannel("/user/*");
      }
  
      public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
          processor.processDependencies(bean);
          processor.processConfigurations(bean);
          processor.processCallbacks(bean);
          return bean;
      }
  
      public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
          return bean;
      }
  
      public void postProcessBeforeDestruction(Object bean, String name) throws BeansException {
          processor.deprocessCallbacks(bean);
      }
  
  
      @Bean(initMethod = "start", destroyMethod = "stop")
      public BayeuxServer bayeuxServer() {
          BayeuxServerImpl bean = new BayeuxServerImpl();
          bean.setTransports(new WebSocketTransport(bean), new JSONTransport(bean), new AsyncJSONTransport(bean));
          bean.setOption("timeout", 60000);
          bean.setOption("ws.timeout", 60000);
          bean.setOption("maxSessionsPerBrowser", 20);
          bean.setOption(ServletContext.class.getName(), context);
          bean.setOption("cometdURLMapping", "/,/svc");
          context.setAttribute(BayeuxServer.ATTRIBUTE, bean);
          return bean;
      }
  
      @Bean(initMethod = "start", destroyMethod = "stop")
      public Oort oort() {
          Oort oort = new Oort(bayeuxServer(), "http://localhost:8094/comet/svc");
          context.setAttribute(Oort.OORT_ATTRIBUTE, oort);
          return oort;
      }
  
      @Override
      public void setServletContext(ServletContext servletContext) {
          this.context = servletContext;
      }
  }
  </code></pre>
  
  <p>web.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;servlet&gt;
          &lt;servlet-name&gt;cometd&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.cometd.server.CometDServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
          &lt;async-supported&gt;true&lt;/async-supported&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;cometd&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/svc/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>Oort seems to be working if I initialize it in web.xml as below:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;servlet&gt;
          &lt;servlet-name&gt;cometd&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.cometd.server.CometDServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
          &lt;async-supported&gt;true&lt;/async-supported&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;cometd&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/svc/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;oort&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.cometd.oort.OortMulticastConfigServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;oort.url&lt;/param-name&gt;
              &lt;param-value&gt;http://localhost:8094/comet/svc&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;oort.channels&lt;/param-name&gt;
              &lt;param-value&gt;/user/*&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  </code></pre>
  
  <p>But as per the documentation Oort should be initialized in Spring if BayeuxServer is being initialized in Spring. So my questions are:</p>
  
  <ol>
  <li>Is there anything wrong with my Oort Spring configuration?</li>
  <li>Considering Oort works for me with web.xml initialization, are there any problems with doing that(keeping BayeuxServer config in Spring itself)?</li>
  <li>The example <a href="https://github.com/cometd/cometd/blob/master/cometd-java/cometd-java-oort/src/test/java/org/cometd/oort/spring/OortConfigurator.java" rel="nofollow noreferrer">here</a> just initializes Oort object. How does cometd know  whether its Multicast or Static?</li>
  </ol>
  
  <p>cometd version: 3.0.10</p>
  
  <p>jetty version: 9.3.11</p>
  
  <p>Any help appreciated! </p>