command1 | command2 | command3
command1, command2 and command3 are started by the shell and the stdout of command1 is the stdin of command2 and the stdout of command2 is the stdin of command3. The data send through the pipeline are strings and every command in the pipeline have to parse the string output of the previous command to extract the information's needed.
alfacmd1 @ alfacmd2 @ alfacmd3
Only alfacmd1 is started by the shell and gets '@ alfacmd2 @ alfacmd3' as command-line arguments. libmsgque will start the both commands alfacmd2 and alfacmd3 and setup the message-queues:
Alfacmd2 receiving the output from alfacmd1 and alfacmd3 receiving the output from alfacmd2 without re-parsing the data again.
shellcmd | atool split @ ...
The split command expect input data from stdin and is sending output data as package to an alfa command. For every input data string an output package is created by splitting the input string into output objects using the the delimiter -d.
... @ join | shellcmd
or if the libmsgque object was not created by atool :
... @ atool join | shellcmd
The join tool expect data from a msgque client as input and create for every input package an stdout output string by joining the objects of the input package together using the delimiter -d .
starthost: alfacmd1 --tcp --host rmthost --port rmtport endhost: alfacmd2 --tcp --port rmtport
By default libmsgque is using unix-domain sockets (UDS) for communication but inet (TCP) sockets can be used as well. The data-flow is the same as above except that two hosts are involved using libmsgque over tcp sockets for connection. The tcp connection is buildup between alfacmd1 and alfacmd2.
echo 'hello world with text' | atool split -d " " @ cut -f 0,1 @ join -D ":"
hello:worldecho -e 'nobody 10 euro\nmanager 1000 dollar\nworker 100 pound' | \ atool split -d " " @ sort -1 D @ join -d " : " -0 "position -> %-8s" \ -1 "amount = %7.2f" -2 "%s"
position -> nobody : amount = 10.00 : euro position -> worker : amount = 100.00 : pound position -> manager : amount = 1000.00 : dollar
total.tcl does 2 things:package require TclMsgque
set total 0
proc FTR {ctx} {
foreach {position amount currency} [$ctx ReadAll] break
switch -exact $currency {
euro {set exchange 1.3541}
pound {set exchange 1.9896}
default {set exchange 1}
}
set amount [expr {$amount * $exchange}]
set currency dollar
set ::total [expr {$::total + $amount}]
$ctx SendSTART
$ctx SendC $position
$ctx SendD $amount
$ctx SendFTR
}
proc EOF {ctx} {
$ctx SendSTART
$ctx SendC total
$ctx SendD $::total
$ctx SendFTR
}
set srv [tclmsgque MqS]
$srv ConfigSetFilterFTR FTR
$srv ConfigSetFilterEOF EOF
if {[catch {
$srv LinkCreate {*}$argv
$srv ProcessEvent -wait FOREVER
}]} {
$srv ErrorSet
}
$srv Exit
echo -e "nobody 10 euro\nmanager 1000 dollar\nworker 100 pound" | \
atool split -d " " @ sort -1 D @ tclsh total.tcl @ \
atool join -d " : " -0 "%-8s" -1 "%5.2f$"
nobody : 13.54$ worker : 198.96$ manager : 1000.00$ total : 1212.50$
1.5.8