0

我创建了两个类:Initiator 和 Acceptor。我想将消息从发起者发送到接受者,然后处理收到的消息。我无法发送消息。

这是我的initiator.java

SocketInitiator socketInitiator = null;
String fileName = "conf/intiator.cfg";
try {
    SessionSettings initiatorSettings = new SessionSettings(new FileInputStream(fileName));
    Application initiatorApplication = new Initiator();
    FileStoreFactory fileStoreFactory = new FileStoreFactory(
            initiatorSettings);
    FileLogFactory fileLogFactory = new FileLogFactory(
            initiatorSettings);
    MessageFactory messageFactory = new DefaultMessageFactory();
    socketInitiator = new SocketInitiator(initiatorApplication, fileStoreFactory, initiatorSettings, fileLogFactory, messageFactory);
    socketInitiator.start();
    Message msg = new Message();
    msg.setString(1, "Hello this is test Message");


    SessionID sessionId = (SessionID) socketInitiator.getSessions().get(0);
    Session.lookupSession(sessionId).logon();
    initiatorApplication.onLogon(sessionId);
    initiatorApplication.toApp(msg, sessionId);
} catch (Exception e) {
    e.printStackTrace();
}

这是它的应用程序接口的覆盖消息。

public void toApp(Message message, SessionID sessionId) throws DoNotSend {
    try {
        boolean result = quickfix.Session.sendToTarget(message, sessionId);
        if (result) {
            System.out.println("Message ahs send :)");
        } else {
            System.out.println("Not Send");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

这是启动器initiator.cfg 文件

[default]
StartTime=00:00:01
EndTime=23:59:59
HeartBtInt=10
SocketUseSSL=N
MillisecondsInTimeStamp=Y
FileIncludeMilliseconds=Y
CheckLatency=N
SocketTcpNoDelay=Y 


[session]
BeginString=FIX.4.4
ConnectionType=initiator
DisableQuickFixReconnLogic=Y
AdapterUserIndex=0

SocketConnectHost=127.0.0.1

Timezone=America/New_York

SocketConnectPort=3000
UseDataDictionary=Y
DataDictionary=conf/resources/FIX44.xml
ValidateFieldsOutOfOrder=N
ValidateFieldsHaveValues=N
ValidateUserDefinedFields=N
LogonTimeout=10
FileStorePath=conf/connector
FileLogPath=conf/connector/logs
FileLogBackupPath=conf/connector
ResetOnLogout=Y
ResetOnDisconnect=N
SendResetSeqNumFlag=Y
RawData=fxall123
#SessionQualifier=FXallStream
MillisecondsInTimeStamp=Y
FileIncludeMilliseconds=Y

[session]
BeginString=FIX.4.4
ConnectionType=initiator
DisableQuickFixReconnLogic=Y
AdapterUserIndex=1
SenderCompID=initiator-id
#SenderSubID=trader1
#TargetCompID=target-id
#TargetSubID=qftrade

SocketConnectHost=127.0.0.1
Timezone=America/New_York
#SocketConnectPort=443
SocketConnectPort=3000
UseDataDictionary=Y
DataDictionary=conf/resources/FIX44.xml
ValidateFieldsOutOfOrder=N
ValidateFieldsHaveValues=N
ValidateUserDefinedFields=N
LogonTimeout=5
FileStorePath=conf/connector
FileLogPath=conf/connector
FileLogBackupPath=conf/connector/backup
ResetOnLogout=Y
ResetOnLogon=Y
ResetOnDisconnect=N
SendResetSeqNumFlag=Y
RawData=fxall123
#SessionQualifier=FXallTrade

接受者.java

String fileName = "conf/acceptor.cfg";
SocketAcceptor socketAcceptor = null;
try {
    FileInputStream is = new FileInputStream(fileName);
    SessionSettings executorSettings = new SessionSettings(is);
    Application application = new Acceptor();
    FileStoreFactory fileStoreFactory = new FileStoreFactory(
            executorSettings);
    MessageFactory messageFactory = new DefaultMessageFactory();
    FileLogFactory fileLogFactory = new FileLogFactory(executorSettings);
    socketAcceptor = new SocketAcceptor(application, fileStoreFactory,
            executorSettings, fileLogFactory, messageFactory);
    socketAcceptor.start();

    SessionID sessionId = (SessionID) socketAcceptor.getSessions().get(0);
    application.onLogon(sessionId);
    int[] i = {1, 2, 3, 4, 5};

    // application.fromApp(new Message(i), sessionId);
} catch (Exception e) {
    e.printStackTrace();
}

接受者.cfg

[default]
StartTime=00:00:00
EndTime=23:50:00
HeartBtInt=10
ReconnectInterval=6
SocketUseSSL=N
MillisecondsInTimeStamp=Y
CheckLatency=N
SocketTcpNoDelay=N
SocketAcceptAddress=127.0.0.1
SocketAcceptPort=3000

[session]
BeginString=FIX.4.4
ConnectionType=acceptor
#DisableQuickFixReconnLogic=Y
AdapterUserIndex=0
SenderCompID=target-id
#SenderSubID=qfstream
#TargetCompID=inttest
#TargetSubID=trader1
Timezone=America/New_York
UseDataDictionary=Y
DataDictionary=conf/resources/FIX44.xml
ValidateFieldsOutOfOrder=N
ValidateFieldsHaveValues=N
ValidateUserDefinedFields=N
LogonTimeout=5
FileStorePath=conf/Acceptor
FileLogPath=conf/Acceptor/logs
ResetOnLogout=Y
ResetOnDisconnect=N
SendResetSeqNumFlag=Y

谁能告诉我问题出在哪里。在配置中还是在代码中?

4

2 回答 2

5

我将指出显而易见的(这段代码有很多错误,请参阅示例以了解 quickfixj 的工作原理)。您尝试发送的Message不是有效的 FIX 消息,因此在发送之前将被引擎拒绝。您将需要创建一个真正的 FIX 消息,以便 quickfix 发送它。同样重要的是,我需要提到它toApp是一个在发送消息时调用的事件处理程序。如果你在其中调用quickfix.Session.sendToTarget它,它会在发送时再次调用toApp。由于您的代码中没有控制语句,toApp因此会导致无限循环。配置也略有错误,其他代码看起来很奇怪,但这些是你最大的问题。请查看文档和示例。

于 2012-08-06T13:27:58.987 回答
2

您需要在 xml 文件中进行更改。我猜您正在使用的字段未在 fix.4.4 文件中声明。检查您的 xml 文件并以下列方式包含该文件。

即你想用货币发送QuoteID,但在货币中没有声明QuoteID。在这种情况下,您将无法发送消息。您需要在 fix.4.4/或您正在使用的任何版本中清除该字段(QuoteID)。

<Currency>
//
//   
<field name="QuoteID" required="N" /> // N or Y depend on your requirement 
//
//
</currency>

还要检查日志,您会在那里找到错误消息。

可能是您没有包括也会产生问题的要求字段。使用以下链接检查哪些字段是必需的。 http://www.fixprotocol.org/FIXimate3.0/

于 2012-10-31T06:51:32.870 回答