[英]How can I send and receive messages on quickfix?
I have created two classes: Initiator and Acceptor. 我创建了两个类:发起者和接受者。 I want to send messages from the initiator to the acceptor and then process the received messages.
我想将消息从发起者发送到接受者,然后处理收到的消息。 I can't send message.
我无法发送消息。
This is my initiator.java 这是我的启动器.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();
}
Here is its overRide message of Application Interface. 这是应用程序接口的overRide消息。
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();
}
}
this is initiator initiator.cfg file 这是启动器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
Acceptor.java Acceptor.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();
}
acceptor.cfg acceptor.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
Can anyone tell me where is the problem. 谁能告诉我问题出在哪里。 Either in configuration or in code?
是配置还是代码?
I will just point out the obvious (there is a lot wrong with this code, see the examples to understand how quickfixj works). 我只是指出明显的问题(此代码有很多错误,请参见示例以了解quickfixj的工作原理)。 The
Message
that you are trying to send is not a valid FIX message and so will be rejected by the engine before it is sent. 该
Message
说你要发送的不是有效的FIX消息,并因此将发动机在发送之前被拒绝。 You will need to create a real FIX message for quickfix to send it. 您需要为quickfix创建一个真实的FIX消息以发送它。 Just as importantly I need to mention that
toApp
is an event handler that gets called when a message is sent. 同样重要的是,我需要提到
toApp
是一个事件处理程序,在发送消息时会被调用。 If you put a call to quickfix.Session.sendToTarget
in it it will then call toApp
again when it gets sent. 如果您在其中调用
quickfix.Session.sendToTarget
,它将在发送后再次调用toApp
。 Since there is no control statement in your toApp
this results in an infinite loop. 由于您的
toApp
没有控制语句,因此会导致无限循环。 The configuration is also slightly wrong, and other bits of code look hinkey, but those are your biggest problems. 配置也略有错误,其他代码看起来很麻烦,但这是您最大的问题。 Please look at the documentation and examples.
请查看文档和示例。
you need to make changes in xml file. 您需要在xml文件中进行更改。 I guess a field that you are using is not declared in fix.4.4 file.
我猜您正在使用的字段未在fix.4.4文件中声明。 Check your xml file and include that in following way.
检查您的xml文件,并通过以下方式添加它。
ie you want to send QuoteID with Currency, but in Currency QuoteID is not declared. 即您要发送带货币的QuoteID,但未声明货币QuoteID。 In that case you will not be able to send message.
在这种情况下,您将无法发送消息。 you need to decleared that field(QuoteID) in fix.4.4/or any version you are using.
您需要在fix.4.4 /或您使用的任何版本中取消该字段(QuoteID)。
<Currency>
//
//
<field name="QuoteID" required="N" /> // N or Y depend on your requirement
//
//
</currency>
also check log, You will find error message there. 同时检查日志,您将在此处找到错误消息。
May be you are not including require fields that can also create problem. 可能是您没有包括也会造成问题的必填字段。 use Following link to check which fields are required.
使用以下链接检查必填字段。 http://www.fixprotocol.org/FIXimate3.0/
http://www.fixprotocol.org/FIXimate3.0/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.