@StreamListener在Spring Boot的主应用程序类之外不可见。可能的原因是什么?

huangapple go评论89阅读模式
英文:

@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 &#39;Consumer-Slide.slideInputStream&#39;.; 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 = &quot;slideInputStream&quot;;
	
	@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&lt;?&gt; messageId) {
			System.out.println(&quot;Message consumed&quot;);
		
	}
}

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).

huangapple
  • 本文由 发表于 2020年9月5日 20:24:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63753882.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定