Devas
Devas

Reputation: 1714

Spring integration websocket throws " 'outputChannel' or 'outputChannelName' is required " Exception

I'm new to Spring integration framework. While running the spring integration websocket sample code I'm getting 'outputChannel' or 'outputChannelName' is required exception.

Did I missed something ?

Following is my code,

@Configuration
@ComponentScan
@EnableAutoConfiguration
@RestController
public class Application {

    public static void main(String args[]) throws Throwable {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    ServerWebSocketContainer serverWebSocketContainer() {
        return new ServerWebSocketContainer("/names").withSockJs();
    }

    @Bean
    MessageHandler webSocketOutboundAdapter() {
        return new WebSocketOutboundMessageHandler(serverWebSocketContainer());
    }

    @Bean(name = "webSocketFlow.input")
    MessageChannel requestChannel() {
        return new DirectChannel();
    }

    @Bean
    IntegrationFlow webSocketFlow() {
        return f -> {
            Function<Message, Object> splitter = m -> serverWebSocketContainer().getSessions().keySet().stream()
                    .map(s -> MessageBuilder.fromMessage(m).setHeader(SimpMessageHeaderAccessor.SESSION_ID_HEADER, s).build()).collect(Collectors.toList());
            f.split(Message.class, splitter).channel(c -> c.executor(Executors.newCachedThreadPool())).handle(webSocketOutboundAdapter());
        };
    }

    @RequestMapping("/hi/{name}")
    public void send(@PathVariable String name) {
        requestChannel().send(MessageBuilder.withPayload(name).build());
    }
}

Exception stack,

java.lang.IllegalStateException: 'outputChannel' or 'outputChannelName' is required
    at org.springframework.util.Assert.state(Assert.java:70)
    at org.springframework.integration.endpoint.MessageProducerSupport.afterSingletonsInstantiated(MessageProducerSupport.java:153)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:781)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)

Upvotes: 2

Views: 1558

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121550

java.lang.IllegalStateException: 'outputChannel' or 'outputChannelName' is required
at org.springframework.util.Assert.state(Assert.java:70)
at org.springframework.integration.endpoint.MessageProducerSupport.afterSingletonsInstantiated(MessageProducerSupport.java:153)

Pay attention - MessageProducerSupport. Your code doesn't show any kind of that, so you just hide something in your application from us.

And I guess you might have something like:

@Bean
public WebSocketInboundChannelAdapter webSocketInboundChannelAdapter() {
    ...
}

And exactly this one must be declare with the setOutputChannel().

Or if you use it as a starting point from Java DSL - IntegrationFlows.from(webSocketInboundChannelAdapter()), - then don't declare it with the @Bean. The Framework will take care about the proper configuration and registration for you afterwards.

Upvotes: 1

Related Questions