我试图使用"spring cloud stream"向rabbitmq发送一条简单的消息.基本上代码看起来像这样:
@EnableBinding(Source.class)
@SpringBootApplication
public class SourceApplication {
public static void main(String[] args) {
SpringApplication.run(SourceApplication.class, args);
}
@Autowired Source source;
@PostConstruct
public void init() {
source.send(MessageBuilder.withPayload("payload").build());
}
}
Run Code Online (Sandbox Code Playgroud)
然后我收到此错误消息:
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=******, headers={id=c60dd5be-6576-99d5-fd1b-b1cb94c191c1, timestamp=1488651422892}]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:93)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373)
Run Code Online (Sandbox Code Playgroud)
但是,如果我添加一些延迟,在发送消息(只是第二个或几个)之前,它可以正常工作.我的问题是:如何在Spring完全初始化消息通道然后发送消息之前等待?