Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a F# and programming newbie and I need some guidance on an issue reading data into F# from a RabbitMQ message queue.

I have been able to write a F# script which subscribes to a message queue(s) and receives data in a similar format to the below.
Received onData;FeedQ1;7.488;7.48813;1427315602762;8.61;8.31

I now need to learn how to split the 'string' message received from the message queue into Variables or an Array which can then be stored and/or used within my F# script. As you can see, the message above actually contains 7 fields which are separated by ; characters.

I have tried searching the web and RabbitMQs resources but everything I have found seems to just detail making the actual connection to RabbiTMQ from F# and it doesn't go any further in terms of information on processing message data received from the MQ queue....

Any help is very much appreciated, Thank you!



Actual F# fsx script shown below:




#r "RabbitMQ.Client.dll"

open System
open RabbitMQ.Client
open RabbitMQ.Client.Events
open System.Text

let factory = new ConnectionFactory(HostName = "localhost")
(
use connection = factory.CreateConnection()
use channel = connection.CreateModel()
use channel1 = connection.CreateModel()

channel.QueueDeclare("FeedQ1", false, false, false, null) |> ignore
channel1.QueueDeclare("FeedQ2", false, false, false, null) |> ignore

let consumer = new QueueingBasicConsumer(channel)
channel.BasicConsume("FeedQ1", true, consumer) |> ignore
channel.BasicConsume("FeedQ2", true, consumer) |> ignore


printfn " [*] Waiting for messages. To exit press CTRL+C"

let rec loop () : unit =
let ea = consumer.Queue.Dequeue();

let body = ea.Body
let message = Encoding.UTF8.GetString(body)
printfn " [x] Received %s" message

loop ()

loop ()
)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900