public interface StreamClient { String input= "message"; @Input(StreamClient.input) SubscribableChannel input(); @Output(StreamClient.input) MessageChannel output(); }
以上是定义的接口
@Component @EnableBinding(StreamClient.class) @Slf4j public class StreamReceiver { @StreamListener(StreamClient.input) public void process(Object message) { log.info("StreamReceiver: {}", message); } }
以上是定义的接受消息的监听类
@RestController public class SendMessageController { @Autowired private StreamClient streamClient; @GetMapping("/sendMessage") public void process() { String message = "now " + new Date(); streamClient.output().send(MessageBuilder.withPayload(message).build()); } }
这是定义的发送消息的接口
我是用的stream + rabbitmq,想做消息异步,上面这么写的话项目一运行就会报错,如下
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'input' defined in org.fish.order.message.StreamClient: bean definition with this name already exists - Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.fish.order.message.StreamClient; factoryMethodName=output; initMethodName=null; destroyMethodName=null
搞了好久没搞出来,十分沮丧,求各位大佬帮帮我!!!
@Input
(StreamClient.input)和
@Output(StreamClient.input)
通道名不能一样