如何在 Camel quickfixj 组件中启用多线程

How to enable multi threading in Camel quickfixj component

我正在使用 camel quickfix 组件来获取不同货币对的市场价格。我订阅了大约 G20 货币对,所以我们得到了很多更新,我们的端点无法处理这样的负载,所以开始拒绝消息并记录错误。

Sending time accuracy problem

我正在考虑制作多线程,这样一个线程就可以处理更新的价格。我尝试了很多搜索,但没有找到满意的答案。

你能帮我解决这个问题吗?

有 3 种方法可以使用 Camel 进行多线程处理:

  • SEDA 路线:在新线程中启动路线
  • JMS/ActiveMQ 用于并行处理
  • JPA : 使用数据库作为消息代理

一个带有 activemq 解决方案的例子:

<route> // quikfix endpoint route
  <from uri="quickfix-server:META-INF/quickfix/server.cfg"/> // QuickFix engine who will receive the message from FIX gateway
  <to uri="uri="activemq:queue:fix"/>"
</route>

<route> // parralize route
  <from uri="activemq:queue:fix"/>
  <bean ref="fixService" method="treatment"/> // do your stuff
</route>

您可以使用 Threads DSL ("Using the Threads DSL")。 示例:

<bean id="threadPool" class="java.util.concurrent.Executors" factory-method="newFixedThreadPool">       
    <constructor-arg index="0" value="20"/>
</bean>

<camelContext id="myContext" xmlns="http://camel.apache.org/schema/spring">

    <route> 
      <from uri="quickfix-server:META-INF/quickfix/server.cfg"/>
      <threads executorServiceRef="threadPool">
         <process ref="someProcessor"/>"
         ....
         other logic that should be run in concurrent environment
         .... 
     </threads> 
    </route>

</camelContext>

如您所见,您可以使用 java.util.concurrent 包中的线程池。 另一种选择是您可以直接设置线程数:

    <route> 
      <from uri="quickfix-server:META-INF/quickfix/server.cfg"/>
      <threads maxPoolSize="20">
         <process ref="someProcessor"/>"
         ....
         other logic that should be run in concurrent environment
     </threads> 
    </route>

</camelContext> 

问题:SendingTime 准确性问题

根本原因分析:

上面的错误消息通常跟在 session 注销之后。这是由于客户端机器的日期和时间设置不正确造成的。


解决方案:

确认日期、时间和时区都设置​​为正确的日期和时间设置。 由于您可以独立设置时区和时间,我建议仔细检查时区(UTC 时差),与设置的时间匹配。

有一个 CheckLatency 和 MaxLatency 配置选项,请参阅 http://www.quickfixengine.org/quickfix/doc/html/configuration.html#Validation

You can use two config options to modify the behavior in relation to time synchronization issues:

This option turns the latency check on or off:

CheckLatency=[Y|N]

This option tunes the maximum latency difference (120 seconds is the default): MaxLatency=120 or >120

还有另外两种方法可以解决这个问题。

首先,这个问题可以通过

来避免
  1. 在重置 session、
  2. 之前注销客户端
  3. 从 session 天更改为每周 session

其次,这个问题可以通过清理排队的消息来解决

资源Link:

  1. https://github.com/connamara/quickfixn/issues/262
  2. QuickFix : SendingTime accuracy problem