gpt4 book ai didi

java - 调度程序没有 channel “unknown.channel.name”的订阅者

转载 作者:行者123 更新时间:2023-12-02 05:12:59 25 4
gpt4 key购买 nike

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

确保目的地(交换)是在rabbit-mq本地创建的。

发布者 (app.yml)

spring:
cloud:
stream:
bindings:
output:
destination: HelloDestination
rabbitmq:
addresses: xxx.xxx.xx.xxx

订阅者(app.yml)

spring:
cloud:
stream:
bindings:
input:
destination: HelloDestination
rabbitmq:
addresses: xxx.xxx.xx.xxx
server:
port: 8081

发布者 (pom.yml)

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

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

发布者(源java文件)

@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);

}

}

//消费者(源文件)

@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);
}
}

//----

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

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

我预计该消息会被阅读。

最佳答案

您需要从 run() 方法返回的应用程序上下文中获取 channel “输出”,而不是创建自己的 DirectChannel。

关于java - 调度程序没有 channel “unknown.channel.name”的订阅者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56314978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com