Sample Number |
|
Level |
|
Description |
This sample demonstrates the usage of UltraESB to proxy FIX messages |
I want to proxy a FIX message over FIX transport protocol with the ESB.
As shown in the above diagram, instead of directly talking to the FIX service , UltraESB acts as the proxy for all the fix messages going to the back-end fix endpoint.
The configuration for this use case consists of a proxy service identified as "fix-proxy", exposed on the FIX transport and forwards the incoming message into the target back-end service configured using the in destination of the proxy service.
FIX proxy configuration with mediation
1<!--This sample service receives FIX messages from 'BANZAI' through acceptor type session established with 'BANZAI'
2 and forward it to FIX endpoint 'EXEC' from initiator type session established with 'EXEC'.-->
3 <u:proxy id="fix-proxy">
4 <u:transport id="fix-lsnr">
5 <!-- settings related to one session need to be defined under same u:property name suffix
6 eg: session settings end with u:property name .BANZAISession1 belogs to one session
7 These sessions are added to the acceptor initiated with fix-lsnr-->
8 <u:property name="ultra.fix.session.begin_string.BANZAISession1" value="FIX.4.2"/>
9 <u:property name="ultra.fix.session.target_comp_id.BANZAISession1" value="BANZAI"/>
10 </u:transport>
11 <u:target>
12 <u:inSequence>
13 <u:java import="org.adroitlogic.ultraesb.api.transport.fix.FIXConstants; java.util.Date;"><![CDATA[
14 mediation.sendToEndpoint(msg, "fix-endpoint");
15 ]]></u:java>
16 </u:inSequence>
17 <u:outDestination>
18 <u:address type="response"/>
19 </u:outDestination>
20 </u:target>
21 </u:proxy>
Fix Transport listener work as the fix message acceptor in UltraESB. Configuration properties you define in the transport listener <property> tags are used as [Default] properties for creating socket acceptor in QuickFix/j. All the messages receive through this transport listener will actually accept fix messages with socket acceptor created with using default properties same to properties given in transport-listener. There are essential properties need to set in order to create a QuickFIX/j socket acceptor, and other properties can be configured in the map named 'otherSettings'.
FIX transport listener
1<!--Define FIX transport listener
2These are the [Default] configuration settings for the FIX acceptor. FIX messages receive by this fix transport listener
3will receive through acceptor sessions which has following default settings-->
4<bean id="fix-lsnr" class="org.adroitlogic.ultraesb.transport.fix.FIXTransportListener">
5 <!--Essential settings for the acceptor-->
6 <property name="socketAcceptPort" value="12000"/>
7 <property name="heartBeatIntervalSec" value="30"/>
8 <property name="senderCompID" value="UESB"/>
9 <property name="messageStoreFactory" ref="acc-fileMessageStore"/>
10 <property name="logFactory" ref="acc-fileLogFactory"/>
11 <property name="startTime" value="00:00:00"/>
12 <property name="endTime" value="23:00:00"/>
13 <!--Optional settings for the acceptor. Use a valid configuration ID as the key of each entry-->
14 <property name="otherSettings">
15 <map>
16 <entry key="AcceptorTemplate" value="Y" />
17 <entry key="UseDataDictionary" value="N" />
18 </map>
19 </property>
20</bean>
If you want to create several sessions through same acceptor those [Session] properties are configured within the proxy service under transport properties.
eg: If you have 2 sessions, one with FIX version 4.2 and other with FIX version 4.3, in proxy service define properties as following.
[Session] properties withn proxy service
1<u:transport id="fix-lsnr">
2 <u:property name="ultra.fix.session.begin_string.BANZAISession1" value="FIX.4.2"/> // begin_string of session with name 'BANZAISession1'
3 <u:property name="ultra.fix.session.target_comp_id.BANZAISession1" value="BANZAI"/> // target_comp_id of session with name 'BANZAISession1'
4
5 <u:property name="ultra.fix.session.begin_string.BANZAISession2" value="FIX.4.3"/> // begin_string of session with name 'BANZAISession2'
6 <u:property name="ultra.fix.session.target_comp_id.BANZAISession2" value="BANZAI"/> // target_comp_id of session with name 'BANZAISession2'
7</u:transport>
Property name suffixes are only to indicate the settings belong to a same session. Property name prefix must be 'ultra.fix.session.' + property_name. To find allowed properties, refer 'FIX Transport' |
Fix Transport sender act as the initiator in UltraESB which initiate a session with a external fix endpoint and send fix messages it received. Configuration properties you define in the transport sender <property> tags are used as [Default] properties for creating socket initiator in QuickFix/j. All the messages send via this transport sender will actually send fix messages with socket initiator created with using default properties same to properties given in transport-sender. There are essential properties need to set in order to create a QuickFIX/j socket initiator, and other properties can be configured in the map named 'otherSettings'.
FIX Transport sender
1<!--Define FIX transport sender
2 These are the [Default] settings for the initiator. FIX messages send through this fix transport sender will send
3 through initiator sessions which has following default settings-->
4 <bean id="fix-sender" class="org.adroitlogic.ultraesb.transport.fix.FIXTransportSender">
5 <property name="reconnectInterval" value="5"/>
6 <property name="heartBeatIntervalSec" value="30"/>
7 <property name="startTime" value="00:00:00"/>
8 <property name="endTime" value="23:00:00"/>
9 <property name="messageStoreFactory" ref="ini-fileMessageStore"/>
10 <property name="logFactory" ref="ini-fileLogFactory"/>
11 <!--Optional settings for the acceptor. Use a valid configuration ID as the key of each entry-->
12 <property name="otherSettings">
13 <map>
14 <entry key="LogonTimeout" value="6" />
15 </map>
16 </property>
17 </bean>
This defines the final destination that the fix-message should receive.
There are three mandatory parameters (BeginString, SenderCompID and TargetCompID) need to create a new session. These three parameters must be given in the endpoint address in the format - fix://<host>:<port>?BeginString=<>&SenderCompID=<>&TargetCompID=< > . Other optional properties can be configured as <u:property.. in endpoint with property name , ultra.fix.endpoint.session.+ property_id.
property_id property_id should be given in the same syntax defined in QuickFIX/J configuration. Refer QuickFIX/J configuration to find the exact IDs. |
FIX endpoint
1<u:endpoint id="fix-endpoint">
2 <u:address>fix://localhost:9879?BeginString=FIX.4.2&SenderCompID=UESB&TargetCompID=EXEC</u:address>
3 <!--Other setting properties need to add to session can be added under <u.property with giving correct
4 fix configuration ID as the suffix and 'ultra.fix.endpoint.session.' as the prefix-->
5 <u:property name="ultra.fix.endpoint.session.DefaultMarketPrice" value="12.30"/>
6</u:endpoint>
New initiator is created for each endpoint you define with using endpoint properties you define as [Session] settings and transport-sender properties as [Default] settings.
Make sure you don’t define values for same property within the transport sender and , endpoint. |
In QuickFIX/J logging can be done file base(fileLogFactory) or by saving to database(jdbcLogFactory). In this sample transport-listener and transport-sender configured to use file base logs (acc-fileLogFactory and ini-fileLogFactory). Following is how to configure fileLogfactory beans. Give the location of where to save the logs in fileLogPath property, here it is configured to '/tmp/fixTest'.
FileLogFactory beans for initiator and acceptor
1<bean id="acc-fileLogFactory" class="org.adroitlogic.ultraesb.transport.fix.FileLogFactoryImpl">
2 <property name="fileLogPath" value="${java.io.tmpdir}/fixTest"/>
3</bean>
4
5<bean id="ini-fileLogFactory" class="org.adroitlogic.ultraesb.transport.fix.FileLogFactoryImpl">
6 <property name="fileLogPath" value="${java.io.tmpdir}/fixTest"/>
7</bean>
To persist loggin information to a database, define a 'dataSource' and 'fix-jdbcLogFactory' by setting required database information and give reference to 'logFactory' property in FIX transport listener and FIX transport sender. Sample configuration is included in sample-550 which you can un-comment and use.
The message store is used by a fix session to store and retrieve messages for resend purposes. QhickFIX/J allow to store messages in file base(FileMessageStoreFactory) or in a database(JDBCMessageStoreFactory). In this sample transport-listener and transport-sender configured to use file base messageStores (acc-fileMessageStore and ini-fileMessageStore). Following is how to configure JDBCMessageStoreFactory beans. Give the location of where to save the messages in 'messageStoreFactory' property, here it is configured to '/tmp/fixTest'.
FileMessageStoreFactory beans for initiator and acceptor
1<bean id="acc-fileMessageStore" class="org.adroitlogic.ultraesb.transport.fix.FileMessageStoreFactoryImpl">
2 <property name="fileStorePath" value="${java.io.tmpdir}/fixTest"/>
3</bean>
4<bean id="ini-fileMessageStore" class="org.adroitlogic.ultraesb.transport.fix.FileMessageStoreFactoryImpl">
5 <property name="fileStorePath" value="${java.io.tmpdir}/fixTest"/>
6</bean>
To persist messages in a database, define a 'dataSource' and 'fix-jdbcMessageStore' by setting required database information and giving reference to 'messageStoreFactory' property in FIX transport listener and FIX transport sender. Sample configuration is included in sample-550 which you can un-comment and use.
To issue a fix message you may refer the unit test FIXMessageExchangeTest.java.
Following is how to send a sample fix message through a external client, mediate message with UltraESB and forwarding to the destination fix endpont. To send and receive a sample fix message you can use samples provided by QuickFIX/J, BANZAI and EXECUTOR.
Since UltraESB do not ship required jars to FIX transport, you need to add following jars in to 'lib/custom'
quickfixj-all-1.5.3.jar mina-core-1.1.7.jar
Start the UltraESB sample configuration 550 via the ToolBox or on the command line as follows.
*Running the sample from startup script*
$ cd /opt/ultraesb-2.6.1/bin $ ./ultraesb.sh -sample 550
Proper starting of FIX transport listener and FIX transport sender will log as follow.
2014-04-09 11:45:05,348 [-] [main] [system] [000000I] INFO FIXTransportSender Started FIX Transport sender : fix-sender... 2014-04-09 11:45:05,358 [-] [main] [system] [000000I] INFO SimpleQueueWorkManager Started Work Manager : default 2014-04-09 11:45:05,359 [-] [main] [system] [000000I] INFO ServerManager Initializing transport listeners 2014-04-09 11:45:05,364 [-] [main] [system] [000000I] INFO ServerManager Starting Proxy Services, Endpoints and Sequences 2014-04-09 11:45:05,371 [-] [main] [system] [000000I] INFO Address Started Address : address of endpoint : fix-endpoint 2014-04-09 11:45:05,371 [-] [main] [system] [000000I] INFO fix-endpoint Endpoint : fix-endpoint started 2014-04-09 11:45:05,376 [-] [main] [system] [000000I] INFO Address Started Address : address of endpoint : mediation.response 2014-04-09 11:45:05,376 [-] [main] [system] [000000I] INFO Endpoint Endpoint : mediation.response started 2014-04-09 11:45:07,391 [-] [main] [system] [000000I] INFO fix-proxy-inSequence Sequence : fix-proxy-inSequence started 2014-04-09 11:45:07,394 [-] [main] [system] [000000I] INFO Address Started Address : address of endpoint : fix-proxy-outDestination 2014-04-09 11:45:07,394 [-] [main] [system] [000000I] INFO fix-proxy-outDestination Endpoint : fix-proxy-outDestination started 2014-04-09 11:45:07,396 [-] [main] [system] [000000I] INFO fix-proxy Proxy service : fix-proxy started 2014-04-09 11:45:07,396 [-] [main] [system] [000000I] INFO ServerManager UltraESB root deployment unit started successfully 2014-04-09 11:45:07,396 [-] [main] [system] [000000I] INFO ServerManager Starting transport listeners 2014-04-09 11:45:11,142 [-] [main] [system] [000000I] INFO FIXSessionFactory Created new socket acceptor for transport listener: fix-lsnr 2014-04-09 11:45:11,234 [-] [main] [system] [000000I] INFO FIXTransportListener Socket acceptor for fix transport listener: fix-lsnr started 2014-04-09 11:45:11,234 [-] [main] [system] [000000I] INFO FIXTransportListener Started FIX Listener : fix-lsnr
Download QuickFIX/J and run the sample they have provided(Banzai-Executor) with modifying configuration as bellow.
Here we are sending a message from Banzai(initiator to port 12000) to UltraESB(working as an acceptor listening in port 12000) over session FIX.4.2. After receiving the message from Banzai UltraESB(working as an initiator) will forward the message to Executor(acceptor listening in port 9879)
Initiator configuration for Banzai (banzai.cfg)
banzai.cfg
[default] FileStorePath=examples/target/data/banzai ConnectionType=initiator TargetCompID=UESB SocketConnectHost=localhost StartTime=00:00:00 EndTime=23:00:00 HeartBtInt=30 ReconnectInterval=5 SocketConnectPort=12000 [session] BeginString=FIX.4.2 SenderCompID=BANZAI
Acceptor configuration for Executor(executor.cfg)
executor.cfg
[default] FileStorePath=examples/target/data/executor ConnectionType=acceptor StartTime=00:00:00 EndTime=23:00:00 HeartBtInt=30 ValidOrderTypes=1,2,F SenderCompID=EXEC TargetCompID=UESB UseDataDictionary=Y DefaultMarketPrice=12.30 [session] BeginString=FIX.4.2 SocketAcceptPort=9879
Following is the UI provided by QuickFIX/J sample, you can send a message with this UI over session FIX.4.2:BANZAI→UESB.
Banzai console output
// initiating session and sending order message <20140409-06:24:38, FIX.4.2:BANZAI->UESB, event> (Session FIX.4.2:BANZAI->UESB schedule is daily, 00:00:00-UTC - 23:00:00-UTC) <20140409-06:24:38, FIX.4.2:BANZAI->UESB, event> (Session state is not current; resetting FIX.4.2:BANZAI->UESB) <20140409-06:24:38, FIX.4.2:BANZAI->UESB, event> (Created session: FIX.4.2:BANZAI->UESB) <20140409-06:24:39, FIX.4.2:BANZAI->UESB, outgoing> (8=FIX.4.29=6535=A34=149=BANZAI52=20140409-06:24:39.48856=UESB98=0108=3010=243) <20140409-06:24:39, FIX.4.2:BANZAI->UESB, event> (Initiated logon request) <20140409-06:24:39, FIX.4.2:BANZAI->UESB, incoming> (8=FIX.4.29=6535=A34=149=UESB52=20140409-06:24:39.56456=BANZAI98=0108=3010=238) <20140409-06:24:39, FIX.4.2:BANZAI->UESB, event> (Received logon) <20140409-06:25:09, FIX.4.2:BANZAI->UESB, outgoing> (8=FIX.4.29=12935=D34=249=BANZAI52=20140409-06:25:09.24456=UESB11=139702470918721=138=1040=154=155=dell59=060=20140409-06:25:09.24210=206) <20140409-06:25:10, FIX.4.2:BANZAI->UESB, incoming> (8=FIX.4.29=5335=034=249=UESB52=20140409-06:25:10.15656=BANZAI10=181) // receiving acknowledgement from Executor via UltraESB <20140409-06:25:10, FIX.4.2:BANZAI->UESB, incoming> (8=FIX.4.29=12435=834=349=UESB52=20140409-06:25:10.68756=BANZAI6=011=139702470918714=017=120=037=139=054=155=dell150=2151=010=061) <20140409-06:25:10, FIX.4.2:BANZAI->UESB, incoming> (8=FIX.4.29=14835=834=449=UESB52=20140409-06:25:10.68856=BANZAI6=12.311=139702470918714=1017=220=031=12.332=1037=238=1039=254=155=dell150=2151=010=130)
UltraESB console output
// receiving message from Banzai and sending to Executor 2014-04-09 11:54:39,537 [-] [SocketAcceptorIoProcessor-0.0] [system] [000000I] INFO FIXTransportListener FIX session with SessionID: FIX.4.2:UESB->BANZAI created for fix listener: fix-lsnr 2014-04-09 11:54:39,578 [-] [QF/J Session dispatcher: FIX.4.2:UESB->BANZAI] [system] [000000I] INFO FIXTransportListener FIX session with SessionID: FIX.4.2:UESB->BANZAI logged in via fix listener: fix-lsnr 2014-04-09 11:55:09,539 [-] [QF/J Session dispatcher: FIX.4.2:UESB->BANZAI] [system] [000000I] INFO FIXSessionFactory Started initiator for endpoint address: FIX.4.2:UESB->EXEC with session ID: fix://localhost:9879?BeginString=FIX.4.2&SenderCompID=UESB&TargetCompID=EXEC 2014-04-09 11:55:09,540 [-] [QF/J Session dispatcher: FIX.4.2:UESB->BANZAI] [system] [000000I] INFO FIXTransportSender Fix message sent to target over session: FIX.4.2:UESB->EXEC // receiving acknowledgement from Executor and sending back to Banzai 2014-04-09 11:55:10,687 [-] [QF/J Session dispatcher: FIX.4.2:UESB->EXEC] [system] [000000I] INFO FIXTransportSender Acknowledgement message received from:UESB sent to message sender: BANZAI 2014-04-09 11:55:10,689 [-] [QF/J Session dispatcher: FIX.4.2:UESB->EXEC] [system] [000000I] INFO FIXTransportSender Acknowledgement message received from:UESB sent to message sender: BANZAI
Executor console output
// receiving order message from UESB <20140409-07:08:34, FIX.4.2:EXEC->UESB, incoming> (8=FIX.4.29=15435=D34=143=Y49=UESB52=20140409-07:08:34.55056=EXEC122=20140409-07:08:3311=139702731319321=138=1040=154=155=dell59=060=20140409-07:08:33.21610=109) <20140409-07:08:34, FIX.4.2:EXEC->UESB, incoming> (8=FIX.4.29=8935=434=243=Y49=UESB52=20140409-07:08:34.55256=EXEC122=20140409-07:08:3436=3123=Y10=125) <20140409-07:08:34, FIX.4.2:EXEC->UESB, event> (ResendRequest for messages FROM 1 TO 1 has been satisfied.) // sending acknowledgement to UESB <20140409-07:08:34, FIX.4.2:EXEC->UESB, outgoing> (8=FIX.4.29=12235=834=349=EXEC52=20140409-07:08:34.59056=UESB6=011=139702731319314=017=120=037=139=054=155=dell150=2151=010=163) <20140409-07:08:34, FIX.4.2:EXEC->UESB, outgoing> (8=FIX.4.29=14635=834=449=EXEC52=20140409-07:08:34.59256=UESB6=12.311=139702731319314=1017=220=031=12.332=1037=238=1039=254=155=dell150=2151=010=233)<20140409-07:08:34, FIX.4.2:EXEC->UESB, incoming> (8=FIX.4.29=15435=D34=143=Y49=UESB52=20140409-07:08:34.55056=EXEC122=20140409-07:08:3311=139702731319321=138=1040=154=155=dell59=060=20140409-07:08:33.21610=109) <20140409-07:08:34, FIX.4.2:EXEC->UESB, incoming> (8=FIX.4.29=8935=434=243=Y49=UESB52=20140409-07:08:34.55256=EXEC122=20140409-07:08:3436=3123=Y10=125) <20140409-07:08:34, FIX.4.2:EXEC->UESB, event> (ResendRequest for messages FROM 1 TO 1 has been satisfied.) <20140409-07:08:34, FIX.4.2:EXEC->UESB, outgoing> (8=FIX.4.29=12235=834=349=EXEC52=20140409-07:08:34.59056=UESB6=011=139702731319314=017=120=037=139=054=155=dell150=2151=010=163) <20140409-07:08:34, FIX.4.2:EXEC->UESB, outgoing> (8=FIX.4.29=14635=834=449=EXEC52=20140409-07:08:34.59256=UESB6=12.311=139702731319314=1017=220=031=12.332=1037=238=1039=254=155=dell150=2151=010=233)