首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >调度程序没有通道'unknown.channel.name‘的订阅者

调度程序没有通道'unknown.channel.name‘的订阅者
EN

Stack Overflow用户
提问于 2019-05-26 23:41:40
回答 1查看 2.4K关注 0票数 1

我正在尝试使用spring绑定来运行发布者和订阅者。

确保在rabbit mq上本地创建目标(Exchange)。

发布者(app.yml)

代码语言:javascript
复制
spring:
  cloud:
    stream:
      bindings:
        output:
          destination: HelloDestination
  rabbitmq:
    addresses: xxx.xxx.xx.xxx

订阅者(app.yml)

代码语言:javascript
复制
spring:
  cloud:
    stream:
      bindings:
        input:
          destination: HelloDestination
  rabbitmq:
    addresses: xxx.xxx.xx.xxx
server:
  port: 8081

发布者(pom.yml)

代码语言:javascript
复制
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>

订阅者(pom.yml)

代码语言:javascript
复制
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>

publisher (源java文件)

代码语言:javascript
复制
@SpringBootApplication
@EnableBinding(Source.class)
public class Demo1Application {

    //@Autowired
    //private static MessageChannel output;

    public static void main(String[] args) {
        SpringApplication.run(Demo1Application.class, args);

        String sampleMessage = "Hello";
        Message<String> message =
                MessageBuilder.withPayload("Hello World").build();

        MessageChannel output = new DirectChannel();

        output.send(message);   

    }

}

//消费者(源文件)

代码语言:javascript
复制
@SpringBootApplication
@EnableBinding(Sink.class)
public class Demo2Application {

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

    @StreamListener(Sink.INPUT)
    public void listenerMethod(Message<String> message)
    {
        System.out.println("The Message is :"+message);
    }
}

//

完成所有操作后,我看到了创建的exchange以及exchange上的消息。消费者启动得很好。但生产者在尝试发送带有错误消息的消息时会卡住

代码语言:javascript
复制
Exception in thread "main" org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'unknown.channel.name'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=Hello World, headers={id=ccf86001-5dba-6c64-bc76-e1f58782de42, timestamp=1558883876384}], failedMessage=GenericMessage [payload=Hello World, headers={id=ccf86001-5dba-6c64-bc76-e1f58782de42, timestamp=1558883876384}]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:461)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401)
    at com.example.demo.Demo1Application.main(Demo1Application.java:29)
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=Hello World, headers={id=ccf86001-5dba-6c64-bc76-e1f58782de42, timestamp=1558883876384}]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:138)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscri

我原以为这条消息会被阅读。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56314978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档