demo_config/
demo_config.rs1use std::io::{stdin, Read};
2
3use quickfix::{
4 dictionary_item::*, Acceptor, Application, ApplicationCallback, ConnectionHandler, Dictionary,
5 FixSocketServerKind, LogFactory, MemoryMessageStoreFactory, QuickFixError, SessionId,
6 SessionSettings, StdLogger,
7};
8
9#[derive(Default)]
10pub struct MyApplication;
11
12impl ApplicationCallback for MyApplication {
13 fn on_create(&self, _session: &SessionId) {
16 }
18}
19
20fn build_settings() -> Result<SessionSettings, QuickFixError> {
21 let mut settings = SessionSettings::new();
22
23 settings.set(
24 None,
25 Dictionary::try_from_items(&[
26 &ConnectionType::Acceptor,
27 &ReconnectInterval(60),
28 &FileStorePath("store"),
29 ])?,
30 )?;
31
32 settings.set(
33 Some(&SessionId::try_new("FIX.4.4", "ME", "THEIR", "")?),
34 Dictionary::try_from_items(&[
35 &StartTime("12:30:00"),
36 &EndTime("23:30:00"),
37 &HeartBtInt(20),
38 &SocketAcceptPort(4000),
39 &DataDictionary("quickfix-ffi/libquickfix/spec/FIX41.xml"),
40 ])?,
41 )?;
42
43 Ok(settings)
44}
45
46fn main() -> Result<(), QuickFixError> {
47 println!(">> Configuring application");
48 let settings = build_settings()?;
49
50 println!(">> Creating resources");
51 let store_factory = MemoryMessageStoreFactory::new();
52 let log_factory = LogFactory::try_new(&StdLogger::Stdout)?;
53 let callbacks = MyApplication;
54 let app = Application::try_new(&callbacks)?;
55
56 let mut acceptor = Acceptor::try_new(
57 &settings,
58 &app,
59 &store_factory,
60 &log_factory,
61 FixSocketServerKind::SingleThreaded,
62 )?;
63
64 println!(">> connection handler START");
65 acceptor.start()?;
66
67 println!(">> App running, press 'q' to quit");
68 let mut stdin = stdin().lock();
69 let mut stdin_buf = [0];
70 loop {
71 let _ = stdin.read_exact(&mut stdin_buf);
72 if stdin_buf[0] == b'q' {
73 break;
74 }
75 }
76
77 println!(">> connection handler STOP");
78 acceptor.stop()?;
79
80 println!(">> All cleared. Bye !");
81 Ok(())
82}