[英]quickfix.Message cannot be cast to quickfix.fix50sp2.Message
I'm using the latest quickfix version which is 1.6.0. 我正在使用最新的Quickfix版本1.6.0。 I already have code which is written against 1.5.3 and what I'm trying to do is upgrade that to 1.6.0
我已经有针对1.5.3编写的代码,而我想做的就是将其升级到1.6.0
The problem I have is when I use the crack(msg,sessionID) method it throws quickfix.Message cannot be cast to quickfix.fix50sp2.Message
error. 我遇到的问题是当我使用crack(msg,sessionID)方法时,它会抛出
quickfix.Message cannot be cast to quickfix.fix50sp2.Message
错误。 I'm sending a correct FIX50SP2 MarketDataSnapshotFullRefresh message from verifix. 我从verifix发送了正确的FIX50SP2 MarketDataSnapshotFullRefresh消息。 An extract of the exception is below
摘录如下
java.lang.ClassCastException: quickfix.Message cannot be cast to quickfix.fix50sp2.Message at quickfix.fix50sp2.MessageCracker.crack(MessageCracker.java:1555) at com.****.fixserver.FixMessageListener.fromApp(FixMessageListener.java:162) at quickfix.Session.fromCallback(Session.java:1731) at quickfix.Session.verify(Session.java:1682)
How can I crack the incoming message to the correct SP2 message? 如何将传入消息破解为正确的SP2消息?
There is a crack50() method, but that requires a SP2 message which is unavailable in the fromApp callback. 有crack50()方法,但是它需要一条SP2消息,该消息在fromApp回调中不可用。
When the begin string is FIXT.1.1 quickfix will treat the message as FIX50 with the DefaultMessageFactory
. 当开始字符串为FIXT.1.1时,quickfix将使用
DefaultMessageFactory
将消息视为FIX50。 So it will automatically generate a FIX.5.0 message. 因此它将自动生成FIX.5.0消息。
The resolution is to write your own custom message factory to generate a SP2 message when the transport is FIXT.1.1. 解决方案是编写自己的自定义消息工厂,以在传输为FIXT.1.1时生成SP2消息。 Here's how I did it.
这是我的方法。
Write a custom message factory implementing quickfix.MessageFactory
interface. 编写一个实现
quickfix.MessageFactory
接口的自定义消息工厂。 You can copy the DefaultMessageFactory
code and change the create() method as follows. 您可以复制
DefaultMessageFactory
代码并按如下所示更改create()方法。
public Message create(String beginString, String msgType) {
MessageFactory messageFactory = messageFactories.get(beginString);
if (beginString.equals(BEGINSTRING_FIXT11)) {
// The default message factory assumes that only FIX 5.0 will be
// used with FIXT 1.1 sessions. A more flexible approach will require
// an extension to the QF JNI API. Until then, you will need a custom
// message factory if you want to use application messages prior to
// FIX 5.0 with a FIXT 1.1 session.
//
// TODO: how do we support 50/50SP1/50SP2 concurrently?
//
// If you need to determine admin message category based on a data
// dictionary, then use a custom message factory and don't use the
// static method used below.
if (!MessageUtils.isAdminMessage(msgType)) {
messageFactory = messageFactories.get(FIX50SP2);
}
}
if (messageFactory != null) {
return messageFactory.create(beginString, msgType);
}
Message message = new Message();
message.getHeader().setString(MsgType.FIELD, msgType);
return message;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.