英文:
@StreamListener is not visible when outside main Application class of Spring Boot. What could be the reason?
问题
这是一个Spring Cloud Stream应用程序。如标题所示,StreamListener
注解仅在SpringBootApplication主类内部起作用,而在带有@Component
注解的不同类中则不起作用。
我认为这是某种StreamListener
可见性问题。
我正在从RabbitMQ管理界面发布消息。
以下是我收到的异常:
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
英文:
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
答案1
得分: 1
我可以回答自己,因为应用程序按预期工作。
解决方案:将应用程序文件保留在父包中,以便可以扫描子模块。(据我理解)。
英文:
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论