gpt4 book ai didi

java - 将列 append 到 QuickFix/J 日志数据库(自定义 QuickFix/J 记录器)

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:09 29 4
gpt4 key购买 nike

QuickFix/J 提供将其日志存储在数据库中的功能。

是否可以将另一列(业务 ID) append 到其中一个表,从而不会在 QuickFix/J 的内部消息记录中引起问题?

如果可能的话,也请提及执行此操作的程序。

最佳答案

解决方案是创建您自己的 Logger 和 LoggerFactory,类似于 QuickFix/J 提供的那些。

您可以通过实现“quickfix.Log”接口(interface)创建一个Logger,通过实现“quickfix.LogFactory”接口(interface)创建一个LoggerFactory。

最简单的方法是使用来自 QuickFix/J 的私有(private) AbstractLog。

创建日志类:

  1. Copy the AbstractLog class as it is from QuickFix/J's source and include it in your project.
  2. Create a class which extends the AbstractLog class and implement all the abstract methods.
  3. Create member variables for any extra field you want to append to the logs (e.g. business ID), and provide a constructor which takes is as an argument and sets its value.
  4. The "logIncoming" and "logOutgoing" methods take a String parameter. This is the data you want to log. At this point you can append your own fields (added in point 3) to the logs. You can format the log as you wish and you are free to use any method of output, i.e. Console, database etc. as you will have to implement it yourself.

创建 LoggerFactory:

  1. Create a LoggerFactory that implements the quickfix.LogFactory interface.

  2. In the "create" method, create and return the instance of the Logger you created before using the constructor you require.

  3. The values that you need to be passed to the constructor can be kept as member variables of the LoggerFactory and set in LoggerFactory's constructor.

您现在有一个自定义记录器,可以像使用 QuickFix/J 自己的记录器一样使用它,并且 QuickFix/J 将使用您的记录器自动记录。

ApplicationAdapter application = new FixInitiator();
SessionSettings settings = new SessionSettings("./config/initiator.cfg");
CustomLogFactory customLogFactory = new CustomLogFactory(settings, myCustomID);
DefaultMessageFactory messageFactory = new DefaultMessageFactory();
FileStoreFactory fileStoreFactory = new FileStoreFactory(settings);
socketInitiator = new SocketInitiator(application, fileStoreFactory, settings, customLogFactory, messageFactory);
socketInitiator.start();

查看 QuickFix/J 自己的 Logger 和 LoggerFactory 实现以获得帮助是个好主意。例如在控制台上登录的记录器:ScreenLog , ScreenLogFactory

QuickFix/J 来源:

https://github.com/quickfix-j/quickfixj

关于java - 将列 append 到 QuickFix/J 日志数据库(自定义 QuickFix/J 记录器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33033629/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com