问题描述
集成Spring Cloud Strem-3.2.6 时出现如下错误
A default binder has been requested, but there is no binder available
或
使用RocketMQ但是没有设置自动配置时,还是会频繁报错 未连接MQ
问题分析
1. 问题定位
一直以为是因为配置了默认binder,导致一直连接服务器。自己定义了一个默认的空白binder,但是binder的消息处理器会一直收到消息,频率和未配置时一样,消息内容是 /v2/api-docs 相关的,怀疑是Swagger的问题
2. 源码跟踪
项目继承了swagger,跟踪源码和日志发现创建了一个 "inMemorySwaggerResourcesProvider-out-0"的绑定,这个和 InMemorySwaggerResourcesProvider 有关
跟踪代码发现在类 org.springframework.cloud.function.context.catalog.BeanFactoryAwareFunctionRegistry
中,Spring Cloud会扫描项目中的函数接口 Function、Supplier等来寻找binder,InMemorySwaggerResourcesProvider 正好继承自Supplier,然后初始化了一个inMemorySwaggerResourcesProvider-out-0
要解决这个就要排除这个Provider或者让它不去找binder
解决方法
该方法中有一个 函数合规性校验,从这里入手
isFunctionDefinitionEligible()
FunctionProperties, 其中是预置了一些系统需要跳过的function名称
在BeanFactoryAwareFunctionRegistry
加载前,将 functionProperties中添加会误扫描的 “inMemorySwaggerResourcesProvider”
结束