AP Fritts
AP Fritts

Reputation: 475

Spring Integration MessageDeliveryException

I am trying to test my Spring Integration setup, but am receiving

"MessageDeliveryException: Dispatcher has no subscribers for channel".

I'm using a QueueChannel and I don't think it needs a handler (from what I can see in the docs).

I'm using Spring Integration Java DSL to define the integration flow programmatically, rather than using a context.

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.channel.MessageChannels;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
public class SimplifiedIntegrationTest {
    @Test
    public void simpleTest() {
        MessageChannel inputChannel = MessageChannels.direct().get();
        QueueChannel outputChannel = MessageChannels.queue().get();
        IntegrationFlows.from(inputChannel).channel(outputChannel).get();

        inputChannel.send(MessageBuilder.withPayload("payload").build());

        Message<?> outMessage = outputChannel.receive(0);
        Assert.notNull(outMessage);
    }
}

Upvotes: 1

Views: 331

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

The IntegrationFlow must always be registered in the context as a bean. I’m not sure what is the source making you think differently, but since you don’t register it as a bean in context, there is no that flow configuration magic done by the particular BeanPostProcessor. And that’s why you get that "Dispatcher has no subscribers for channel” error.

See IntegrationFlowContext if you register your Integration Flows manually: https://docs.spring.io/spring-integration/docs/5.0.0.BUILD-SNAPSHOT/reference/html/java-dsl.html#java-dsl-runtime-flows.

That doc is for Spring Integration 5.0, but IntegrationFlowContext behaves the same way in Java DSL 1.2.x.

Upvotes: 2

Related Questions