Spring Integration SMB 入站通道适配器的性能问题

问题描述 投票:0回答:1

我正在使用 Spring Integration 6.0.5 并尝试为 smb 配置入站通道适配器。 我让它工作并读取文件,但性能很差,我似乎无法影响一次性获取多少文件。每个文件的处理之间总是有 7 秒的时间,我可以在日志中看到来自 SmbSessionFactory 的常规“SMB share init:”日志。我想知道我是否在不应该创建新会话的情况下创建了新会话。我的 Bean 配置如下所示。

@Configuration
@EnableIntegration
public class SMBConfig {

    private String host;

    private String domain;

    private String username;


    private String password;

    private int port;

    @Bean
    public SmbSessionFactory smbSessionFactory() {
        SmbSessionFactory smbSession = new SmbSessionFactory();
        smbSession.setHost(host);
        smbSession.setPort(port);
        smbSession.setDomain(domain);
        smbSession.setUsername(username);
        smbSession.setPassword(password);
        smbSession.setShareAndDir("sambashare");
        smbSession.setSmbMinVersion(DialectVersion.SMB210);
        smbSession.setSmbMaxVersion(DialectVersion.SMB311);
        return smbSession;
    }


    @Bean
    public SmbRemoteFileTemplate template(SmbSessionFactory smbSessionFactory) {
        return new SmbRemoteFileTemplate(smbSessionFactory);
    }

    @Bean
    @Transformer(inputChannel = "stream", outputChannel = "xml")
    public org.springframework.integration.transformer.Transformer transformer() {
        return new StreamTransformer("UTF-8");
    }

    @Bean
    @InboundChannelAdapter(channel = "stream", poller = @Poller(maxMessagesPerPoll = "10", fixedDelay = "1"))
    public MessageSource<InputStream> smbMessageSource(CompositeFileListFilter filter, SmbRemoteFileTemplate template) {
        SmbStreamingMessageSource messageSource = new SmbStreamingMessageSource(template);
        messageSource.setRemoteDirectory("test/");
        messageSource.setMaxFetchSize(100);
        messageSource.setFilter(filter);
        return messageSource;
    }

    @Bean
    public CompositeFileListFilter<SmbFile> compositeFileListFilter() {
        CompositeFileListFilter<SmbFile> filters = new CompositeFileListFilter<>();
        filters.addFilter(new AcceptAllFileListFilter<>());
        return filters;
    }
}

我有一个 ServiceActivator

        @ServiceActivator(inputChannel = "xml")
        void serviceActivator(String xml) {

            log.info(xml);
        }
spring spring-integration samba smb
1个回答
0
投票

我测试了你的conf,我认为由于默认范围(原型),Spring Integration 会在每个轮询周期重新创建

SmbSessionFactory
bean。您可以将
@Scope("singleton")
添加到
smbSessionFactory()
。 Spring Integration 还提供了 CachingSessionFactory ,考虑对依赖于 SmbSessionFactory 的 SmbRemoteFileTemplate 使用缓存

© www.soinside.com 2019 - 2024. All rights reserved.