[Quickfix-developers] Message creation
Brought to you by:
orenmnero
|
From: <gar...@su...> - 2003-01-03 19:25:04
|
I am using the Quickfix library to build a FIX engine that other
applications could connect to and receive / send messages for any
particular session. Basically, I would like to create a Middleware
solution where FIX messages are processed by my primary application and not
by the Quickfix application itself. My trading application would connect
to my FIX engine (via RMI) and send and receive messages via the RMI
interface of the FIX engine.
However, one of the issues I must address is handling the case where my
primary application loses the RMI connection to my FIX engine while that
same FIX engine remains connected to the 3rd party FIX engine. By the time
my primary application reconnects to my FIX engine, my FIX engine may have
received messages from the 3rd party FIX engine that need to get sent to
and processed by my primary application.
In order to deal with this, I am using a FileMessageStore in my Application
implementation to store every inbound FIX message for that session. When
my primary application reconnects via RMI, it always requests all messages
since the last one the primary application received through the last one
that the FIX engine received.
The problem I'm having is when I retrieve the messages from the
MessageStore, I get the text format of the FIX message. I then need to
instantiate the appropriate Message instance and there doesn't seem to be
any easy way to do this. While the org.quickfix.Message constructor with a
String parameter does take that string value and construct a Message
object, it doesn't create the appropriate Message object based on the
BeginString and message type. When I try to resend that message, I get a
ClassCastException because the crack method in MessageCracker only deals
with explicit Message types (not the Message parent class).
The only way around this has been for me to do the following:
// Instantiate the Message object
org.quickfix.Message msg = new org.quickfix.Message
(msgStr);
// Get the BeginString
BeginString beginString = new BeginString();
msg.getHeader().getField (beginString);
// Get the MsgType
MsgType msgType = new MsgType();
msg.getHeader().getField (msgType);
// Instantiate a second Message object using the DefaultMessageFactory
org.quickfix.Message fMsg = msgFactory.create
(beginString.getValue(), msgType.getValue());
// Then initializte that new Message with the original message string
(stored from the MessageStore)
fMsg.initFromString (msgStr, false);
// Now crack can understand the Message object
Application.getInstance().recrack (fMsg, sessId);
It would be nice if the Message constructor (taking a String value) could
do this automatically. In order to this, I needed to make the
Message.initFromString(String str) method public instead of protected.
Is this a reasonable request? Or is there an easier way to create a
message object?
Another related question is what happens if you request a message (via
sequence number) from the MessageStore but it doesn't exists? I'm going to
have the client basically ask for all messages since (lastMsgRecvd + 1).
Thanks,
Gary Mui
Prescient Markets, Inc 914-989-3118 (W)
445 Hamilton Avenue 914-422-3693 (F)
White Plains, NY 10601
Please visit us at http://www.cpmarket.com
|