Single Bank Platform: F# RFQAgent (Part 6)

The RFQ workflow fits ideally with the agent pattern. Obviously in the below I’ve missed out the appropriate credit check. I also probably want to return a better price than “1″, which should be the banks tiered price with an added margin based on client.

type RFQAgent(session : Agent<SessionMessage>) =
    let rfqNum = System.Threading.Interlocked.Increment(rfqCount)

    let rfq = Agent<RFQConversationMessage>.Start(fun inbox ->
        let inBus = 
            MessageBus.Instance.CreateOrFind<CommandDto>(sprintf "RFQ%d-In" rfqNum).Channel.Subscribe(fun (payload:CommandDto) ->
                                match payload.Command with
                                | CommandDto.CommandType.RequestPrice -> 
                                    inbox.Post(RequestPrice(payload.Data.ToString()))
                                | CommandDto.CommandType.AcceptPrice -> 
                                    inbox.Post(AcceptPrice(payload.Data))
                                | CommandDto.CommandType.RejectPrice ->
                                    inbox.Post(RejectPrice)
                            )
        let rec loop() =
            async {
                let! msg = inbox.Receive()
                match msg with
                | CreateRFQ (payload,session) ->
                    session.Post(StartedRFQ(sprintf "RFQ%d" rfqNum))
                    return! loop()
                | RequestPrice payload ->
                    MessageBus.Instance.CreateOrFind(sprintf "RFQ%d-Out" rfqNum).Post("Price for RFQ is 1")
                    return! loop()
                | AcceptPrice payload ->
                    session.Post(RouteOrder(payload))
                    return! loop()
                | RejectPrice ->
                    inBus.Dispose()
            }
        loop())

Taking a slight tangent, it would be interesting to leverage Solace persisted messaging in a similar way to how LMAX has leverage 29West – agent recovery and snapshot’ing.

Finally, had Nomadic Developer appears to have identified a few more advantages to F#

Advertisement

~ by mdavey on October 27, 2010.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 272 other followers