Spring integration Spring集成-无查询结果的JDBC通道适配器

Spring integration Spring集成-无查询结果的JDBC通道适配器,spring-integration,Spring Integration,当查询在ResultSet内返回null或零结果时,我遇到了一个问题 我有一个带有行映射器的intjdbc:inbound通道适配器 <int-jdbc:inbound-channel-adapter query="SELECT * FROM ENGINE_LOGS WHERE COUNTRY_ID = 2 AND BUSINESS_ID = 100 and rownum &lt; 10" channel="oracle.db.resultSet.engineLogs

当查询在
ResultSet
内返回null或零结果时,我遇到了一个问题

我有一个带有行映射器的
intjdbc:inbound通道适配器

<int-jdbc:inbound-channel-adapter query="SELECT * FROM ENGINE_LOGS WHERE COUNTRY_ID = 2 AND BUSINESS_ID = 100 and rownum &lt; 10"   
    channel="oracle.db.resultSet.engineLogs"
    update="" 
    row-mapper="engineLogsRowMapper"
    data-source="jdbcTemplate">
    <!-- Cron Time -->
    <int:poller fixed-rate="5" time-unit="SECONDS"></int:poller>
</int-jdbc:inbound-channel-adapter>`

`
当查询返回null o零(0)结果时,行映射器类或转换器(使用输入通道:
oracle.db.resultSet.engineLogs
)从不调用

我需要在辅助数据库中执行更新,如果查询在数据库中找不到记录,是否可以添加路由器或其他东西来修复我的问题


这是正确的。带有
null
有效负载的消息对于消息传递系统(如Spring Integration)没有意义。实际上,没有一个现有的消息传递协议支持
null
payload

因此,当没有来自底层系统的数据时(如您的案例中的JDBC),许多具有结果意识的适配器什么也不做是标准行为

代码如下所示:

private Object poll() {
    List<?> payload = doPoll(this.sqlQueryParameterSource);
    if (payload.size() < 1) {
        payload = null;
    }
    if (payload != null && updateSql != null) {
        if (this.updatePerRow) {
            for (Object row : payload) {
                executeUpdateQuery(row);
            }
        }
        else {
            executeUpdateQuery(payload);
        }
    }
    return payload;
}

类似的情况。

我处于类似的情况,在一个空的结果集上,我需要停止同一个jdbc端点,所以这里有一个使用Spring Integration 5的示例

Spring上下文配置:

<int-jdbc:inbound-channel-adapter role="jdbc-endpoint" auto-startup="false"
        data-source="dbDataSource" channel="resultSetsIn"
        query="SELECT ... FROM ... WHERE ..."
        update="UPDATE ... SET ... WHERE id IN (:id)"
        max-rows-per-poll="1">

    <int:poller fixed-rate="5000">
        <int:advice-chain>
            <bean class="services.EmptySourceService" />
        </int:advice-chain>
    </int:poller>

</int-jdbc:inbound-channel-adapter>

执行建议:

package services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.aop.AbstractMessageSourceAdvice;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.messaging.Message;

public class EmptySourceService extends AbstractMessageSourceAdvice {

    @Autowired
    private SmartLifecycleRoleController roleController;

    @Override
    public boolean beforeReceive(MessageSource<?> source) {
        return true;
    }

    @Override
    public Message<?> afterReceive(Message<?> result, MessageSource<?> source) {
        if(result == null) {
            // empty query result logic
            roleController.stopLifecyclesInRole("jdbc-endpoint");
        }

        return result;
    }

}
套餐服务;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.integration.aop.AbstractMessageSourceAdvice;
导入org.springframework.integration.core.MessageSource;
导入org.springframework.integration.support.SmartLifecycleRoleController;
导入org.springframework.messaging.Message;
公共类EmptySourceService扩展了AbstractMessageSourceAdvice{
@自动连线
私人智能生命周期控制器角色控制器;
@凌驾
接收前公共布尔值(MessageSource){
返回true;
}
@凌驾
接收后的公共消息(消息结果、消息源){
如果(结果==null){
//空查询结果逻辑
stopLifecyclesInRole(“jdbc端点”);
}
返回结果;
}
}

端点停止是按照中的说明完成的。

您能为我提供一些示例,说明如何实现此类com.service.ValidateResultAdvice吗?请看中的示例,并告诉我这是否是一个正确的通知用法吗?没关系,但它与当前问题有何关系?
package services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.aop.AbstractMessageSourceAdvice;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.messaging.Message;

public class EmptySourceService extends AbstractMessageSourceAdvice {

    @Autowired
    private SmartLifecycleRoleController roleController;

    @Override
    public boolean beforeReceive(MessageSource<?> source) {
        return true;
    }

    @Override
    public Message<?> afterReceive(Message<?> result, MessageSource<?> source) {
        if(result == null) {
            // empty query result logic
            roleController.stopLifecyclesInRole("jdbc-endpoint");
        }

        return result;
    }

}