Add basic server setup

Add a command line tool to start a simple one node server setup
of the exchange
This commit is contained in:
Tim Kächele 2024-02-18 21:26:52 +01:00
parent 84b0cb9540
commit ede4916284
3 changed files with 78 additions and 0 deletions

22
exe/rex-server Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require "bundler/setup"
require "rex"
puts <<~STR
__
/ _)
_.----._/ /
/ /
__/ ( | ( |
/__.-'|_|--|_|
Ruby Exchange (Rex)
Author: Tim Kächele
License: AGPLv3
STR
EM.run {
Rex::Server::SimpleServerSetup.new(ARGV[0], ARGV[1].to_i).start
}

View File

@ -13,6 +13,8 @@ require_relative "server/message_processor"
require_relative "server/websocket_server"
require_relative "server/json_message_serializer"
require_relative "server/simple_server_setup"
module Rex
module Server
VERSION = "0.1.0"

View File

@ -0,0 +1,54 @@
module Rex
module Server
# Implementation of a simple one node server setup
#
# Setups/Starts
#
# - a message processor to parse and forward
# messages to the matching engine
# - a matching engine instance to process any order book related
# messages
# - a websocket server to accept websocket base connections and
# process incoming messages
class SimpleServerSetup
def initialize(host, port)
matching_engine_inbox_pipe = EventMachine::Channel.new
matching_engine_outbox_pipe = EventMachine::Channel.new
@matching_engine = MatchingEngine.new(
matching_engine_inbox_pipe,
matching_engine_outbox_pipe
)
message_processor_inflow_pipe = EventMachine::Channel.new
message_broker = MessageBroker.new(JsonMessageSerializer.new)
@message_processor = Rex::Server::MessageProcessor.new(
matching_engine_inbox_pipe,
matching_engine_outbox_pipe,
message_broker,
message_processor_inflow_pipe
)
@websocket_server = Rex::Server::WebsocketServer.new(
message_broker,
message_processor_inflow_pipe,
host: host,
port: port
)
end
def start
@message_processor.start
@matching_engine.start
@websocket_server.start
end
def stop
@matching_engine.stop
@message_processor.stop
@websocket_server.stop
end
end
end
end