Skip to content

During integration of Spring Boot bean of BroadcasterFactory creating without applying configuration #2520

Open
@ViacheslavBondarchuk

Description

@ViacheslavBondarchuk

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();
}

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions