Open
Description
Discussed in #2519
Originally posted by viacheslavbondarchukk November 9, 2024
Hi, I am trying to integrate the Atmosphere Framework with Srping Boot, all work as well.
But bean of BroadcasterFactory is creating before initialization of SpirngAtmosphereServlet and AtmosphereFramework.
This leads to ignor passed configuration in SringAthomsphereContex for bean BroadcasterFactory.
Am I doing something wrong?
I followed this tutorial:
https://github.com/Atmosphere/atmosphere/wiki/Configuring-Atmosphere-as-a-Spring-Bean
Code:
@configuration
public class AtmosphereAutoConfiguration {
private static final String ATMOSPHERE_SERVLET_NAME = "AtmosphereServlet";
private static final Map<String, String> CONFIG = Map.of(// TODO: externalize it in external configuration
ApplicationConfig.BROADCASTER_LIFECYCLE_POLICY, IDLE_EMPTY_DESTROY.name(),
ApplicationConfig.USE_FORJOINPOOL, "false",
ApplicationConfig.BROADCASTER_SHARABLE_THREAD_POOLS, "true",
ApplicationConfig.BROADCASTER_ASYNC_WRITE_THREADPOOL_MAXSIZE, "200",
ApplicationConfig.BROADCASTER_MESSAGE_PROCESSING_THREADPOOL_MAXSIZE, "100",
ApplicationConfig.BROADCASTER_WAIT_TIME, "5",
ApplicationConfig.BROADCASTER_FACTORY, DefaultBroadcasterFactory.class.getName(),
ApplicationConfig.BROADCASTER_CACHE, DefaultBroadcasterCache.class.getName()
);
@Bean
public ServletRegistrationBean<AtmosphereSpringServlet> atmosphereSpringServlet() {
ServletRegistrationBean<AtmosphereSpringServlet> servletRegistrationBean = new ServletRegistrationBean<>();
servletRegistrationBean.setServlet(new AtmosphereSpringServlet());
servletRegistrationBean.setAsyncSupported(true);
servletRegistrationBean.setUrlMappings(Collections.singletonList(AtmosphereUtil.path("*")));
servletRegistrationBean.setBeanName(ATMOSPHERE_SERVLET_NAME);
servletRegistrationBean.setName(ATMOSPHERE_SERVLET_NAME);
servletRegistrationBean.setLoadOnStartup(0);
servletRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return servletRegistrationBean;
}
@Bean
public AtmosphereFramework atmosphereFramework() {
return new AtmosphereFramework(false, false);
}
@Bean
public BroadcasterFactory broadcasterFactory(AtmosphereFramework framework) {
return framework.getAtmosphereConfig()
.getBroadcasterFactory();
}
@Bean
public AtmosphereSpringContext atmosphereSpringContext() {
AtmosphereSpringContext atmosphereSpringContext = new AtmosphereSpringContext();
atmosphereSpringContext.setConfig(CONFIG);
return atmosphereSpringContext;
}
@Bean
public AtmosphereStreamServiceRegistrar serviceRegistrar() {
return new AtmosphereStreamServiceRegistrar();
}
}
Metadata
Metadata
Assignees
Labels
No labels
Activity