3

SpringIntegrationは初めてです。

Springファイルのinbound-channel-adapterを構成しました。例:

<file:inbound-channel-adapter channel="channel1" directory="${location}" prevent-duplicates="true" filename-pattern="*.csv">
        <si:poller>
            <si:interval-trigger interval="1000"/>
        </si:poller>
</file:inbound-channel-adapter>

<si:service-activator input-channel="channel1" output-channel="channel2" ref="filenameGenerator" method="generate"/>

現在、これは正常に機能しています。ただし、これはクラスター環境にデプロイする必要があります。クラスタ内の複数のインスタンスが同じファイルを読み取ろうとしないようにしたいと思います。それで、これはそのような環境で機能しますか?

いいえの場合、次のようなQuartzスケジューラを使用できますか?

    <file:inbound-channel-adapter channel="channel1" directory="${location}" prevent-duplicates="true" filename-pattern="*.csv">
             <si:poller task-executor="taskExecutor" fixed-rate="1000"/>
    </file:inbound-channel-adapter>

    <si:service-activator input-channel="channel1" output-channel="channel2" ref="filenameGenerator" method="generate"/>

    <bean id="taskExecutor" class="org.springframework.scheduling.quartz.SimpleThreadPoolTaskExecutor">
        <property name="threadCount" value="20"/>
        <property name="threadNamePrefix" value="consumer"/>
    </bean>

これはうまくいき、私の問題を解決しますか?または、トランザクションを使用する必要がありますか?

質問が明確であることを願っています。

ありがとう、アディ

4

2 に答える 2

2

複数のプロセスが同じディレクトリから読み取っている場合、ファイルが同時に取得されないようにファイルをロックすることが望ましい場合があります。これを行うには、FileLockerを使用できます

ここでファイルロッカーに関するドキュメントを確認してください。あなたはこのような何かをすることができるようです:

<file:inbound-channel-adapter ... >
  <file:nio-locker/>
</file:inbound-channel-adapter>

複数のプロセスが同じディレクトリから読み取っている場合、ファイルが同時に取得されないようにファイルをロックすることが望ましい場合があります。これを行うには、FileLockerを使用できます

于 2012-01-17T16:45:31.090 に答える
1

クォーツスケジュールジョブがクラスター内で1回だけ実行されるようにするには、永続的なクラスター化クォーツジョブスケジュールを構成します。Quartz1.6.6の設定例は次のとおりです。

  <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <!--        Set whether any jobs defined on this SchedulerFactoryBean should
            overwrite existing job definitions.
      --> 
    <property name="overwriteExistingJobs" value="true" /> 
  <property name="dataSource" ref="myTransactionalDataSource" /> 

<!-- nonTransactionalDataSource is only necessary with clustered Quartz with an XA DataSource.  
  --> 
  <property name="nonTransactionalDataSource" ref="myNonTransactionalDataSource" /> 

 <property name="quartzProperties">
  <props>
  <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS WITH(UPDLOCK,HOLDLOCK) WHERE LOCK_NAME = ?</prop> 
  <!-- 
    Run in cluster.  Quartz ensures persisted jobs are executed once within the 
                      cluster
  --> 
  <prop key="org.quartz.jobStore.isClustered">true</prop> 

 <!--   Each node in the cluster must have a unique instance id.  
  --> 
  <prop key="org.quartz.scheduler.instanceId">AUTO</prop> 
 <!--   Default clusterCheckinInterval is 15000 
  --> 
  <!--  <prop key="org.quartz.jobStore.clusterCheckinInterval">20000</prop> 
  --> 
 </props>
  </property>
  <property name="transactionManager" ref="transactionManager" /> 
- <!-- 
        In Quartz 1.6.6, Quartz's ThreadPool interface is used when firing job triggers, 
        in org.quartz.core.QuartzSchedulerThread. 
        Quartz 1.x still starts some unmanaged threads, notably org.quartz.impl.jdbcjobstore.JobStoreSupport's
        ClusterManager which is used when clustered=true. Quartz 2.0 should correct this problem.       
  --> 
  <property name="taskExecutor" ref="myTaskExecutor" /> 
  </bean>
于 2014-08-01T22:18:43.020 に答える