Skip to content
Advertisement

@StreamListener is not visible when outside main Application class of Spring Boot. What could be the reason?

This is Spring Cloud Stream application. As i mention in the title, the StreamListener annotation works when inside the SpringBootApplication main class, but not when it resides in a different class with @Component annotation.

I believe it is some sort of StreamListener visibility issue.

I am publishing messages from the RabbitMQ management interface.

Below is the exception i get:

ERROR 10676 --- [Service-Group-1] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'Consumer-Slide.slideInputStream'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers

ConsumerApplication.java

@SpringBootApplication
@EnableBinding(SlideChannel.class)
public class ConsumerApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
        
    }
}

SlideChannel.java

public interface SlideChannel {
    String slideInputStream = "slideInputStream";
    
    @Input(SlideChannel.slideInputStream)
    SubscribableChannel slideInput();
}

SlideListener.java

@Component
public class SlideListener {
    
    @Autowired
    private SlideChannel slideCh;
    
    
    @Autowired
    private SlideService slideService;
    
    @StreamListener(target=SlideChannel.slideInputStream)
    public void getSingleSlideDetails(Message<?> messageId) {
            System.out.println("Message consumed");
        
    }
}

application.properties

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

spring.cloud.stream.rabbit.bindings.slideInputStream.consumer.consumerTagPrefix=SlideConsumer
spring.cloud.stream.bindings.slideInputStream.destination=EventbusRouter
spring.cloud.stream.bindings.slideInputStream.group=Slide-Consumer-Service-Group

spring.cloud.stream.rabbit.bindings.slideInputStream.consumer.exchangeDurable=false
spring.cloud.stream.rabbit.bindings.slideInputStream.consumer.bind-queue=true
spring.cloud.stream.rabbit.bindings.slideInputStream.consumer.bindingRoutingKey=SlideTopic
spring.cloud.stream.rabbit.bindings.slideInputStream.consumer.durableSubscription=false

Advertisement

Answer

I can answer myself since the Application works as expected.

Solution: Keep the Application file in the parent package so it can scan the child modules.(as I understand it).

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement