# Using YAML for inter-process communication - anything built-in?

**URL:** <https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783>\
**Category:** Ruby\
**Created:** [March 2, 2009, 1:15pm UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783 "2009-03-02T13:15:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 2, 2009, 1:15pm UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783/1 "2009-03-02T13:15:48Z")

</div>

Hi,

I’m just wondering - I implemented something ([thbar (Thibaut Barrère) · GitHub](http://github.com/thbar/)  
petite-lettre/tree/master) I believe probably already exists, can  
anyone tell me if it does ?

I’m using YAML to communicate using stdin/stdout between a Ruby MRI  
process and a JRuby process (I will soon use it to communicate between  
IronRuby and JRuby).

The parent process launches the child using:

PetiteLettre.call(“ruby child\_program.rb”, { :command  
=\> :start\_sale, :isbn =\> “1234567”, :price =\> 12.4 })

and the child responds with:

PetiteLettre.receive do |message|  
response = {}  
if message[:command] == :start\_sale  
# do something here  
raise “Price is too low” if message[:price] \< 15.0  
response[:status] = “OK”  
response[:transaction\_id] = “1235”  
else  
raise “Unknown command ‘#{message[:command]}’”  
end  
response  
end

If something already exists in Ruby to do that this way, I’d like to  
know about it.

Any idea ?

Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 2, 2009, 1:50pm UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783/2 "2009-03-02T13:50:30Z")

</div>

On 02.03.2009 13:14, Thibaut Barrère wrote:

> The parent process launches the child using:  
> raise “Price is too low” if message[:price] \< 15.0
> 
> Any idea ?

I am not sure about portability of Marshal across Ruby implementations.  
In case it is given you could achieve similar results using DRb.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 2, 2009, 3:10pm UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783/3 "2009-03-02T15:10:53Z")

</div>

Hi Robert,

> I am not sure about portability of Marshal across Ruby implementations.  
> In case it is given you could achieve similar results using DRb.

that’s a good point. I’ll try that if I stick with two ruby parties.

– Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 2, 2009, 10:35pm UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783/4 "2009-03-02T22:35:20Z")

</div>

Thibaut BarrÃ¨re wrote:

> If something already exists in Ruby to do that this way, I’d like to  
> know about it.

I came across a YAML-RPC once upon a time; you could try looking for it.

I’d avoid YAML as much as possible, as it’s horribly broken; certainly  
useless for mere humans writing YAML anyway.

irb(main):001:0\> require “yaml”  
=\> true  
irb(main):002:0\> YAML.load(“foo:bar\nbaz:”)  
=\> “foo:bar baz:”  
irb(main):003:0\> YAML.load(“foo:bar\nbaz:\n”)  
=\> {“foo:bar baz”=\>nil}  
irb(main):004:0\> YAML.load(“foo:bar\nbaz:bap\n”)  
=\> “foo:bar baz:bap”  
irb(main):005:0\> YAML.load(“foo: bar\nbaz:bap\n”)  
ArgumentError: syntax error on line 2, col -1: `' from /usr/local/lib/ruby/1.8/yaml.rb:133:in`load’  
from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load’  
from (irb):5  
irb(main):006:0\> YAML.load(“foo: bar\nbaz: bap\n”)  
=\> {“baz”=\>“bap”, “foo”=\>“bar”}

There are also examples which have been posted to this list showing  
objects serialised to YAML and immediately back again, ending up with  
different content.

But I sympathise if you want to do something DRb-like, but between two  
different Ruby implementations. XMLRPC/JSON won’t give you full Ruby  
object serialisation, and SOAP is too horrible to contemplate.

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 3, 2009, 10:19am UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783/5 "2009-03-03T10:19:56Z")

</div>

Gary Y. wrote:

> You’re missing the ‘—’ header in these examples. YAML may behave  
> more robustly with the header.

Nope, it’s exactly the same:

irb(main):001:0\> require “yaml”  
=\> true  
irb(main):002:0\> YAML.load(“—\nfoo:bar\nbaz:”)  
=\> “foo:bar baz:”  
irb(main):003:0\> YAML.load(“—\nfoo:bar\nbaz:\n”)  
=\> {“foo:bar baz”=\>nil}  
irb(main):004:0\> YAML.load(“—\nfoo:bar\nbaz:bap\n”)  
=\> “foo:bar baz:bap”  
irb(main):005:0\> YAML.load(“—\nfoo: bar\nbaz:bap\n”)  
ArgumentError: syntax error on line 3, col -1: `' from /usr/lib/ruby/1.8/yaml.rb:133:in `load’  
from /usr/lib/ruby/1.8/yaml.rb:133:in `load’  
from (irb):5  
irb(main):006:0\> YAML.load(“—\nfoo: bar\nbaz: bap\n”)  
=\> {“baz”=\>“bap”, “foo”=\>“bar”}

> Check out FastYAML on github. It’s way faster than YAML, doesn’t use  
> Syck, and is way more robust than YAML.

But is apparently not available as a gem.

$ gem sources  
\*\*\* CURRENT SOURCES \*\*\*

[http://gems.rubyforge.org/](http://gems.rubyforge.org/)  
[http://gems.github.com/](http://gems.github.com/)  
$ sudo gem search --remote YAML

\*\*\* REMOTE GEMS \*\*\*

feedtools-cache-yaml (0.0.2)  
kakutani-yaml\_waml (0.3.0)  
markbates-yamler (0.1.0)  
RbYAML (0.2.0)  
ya2yaml (0.26)  
yamlconfig (0.1.2)  
yamler (0.1.0)  
yamlrpc (1.0.4)  
yamltest (0.5.1)  
$

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 3, 2009, 9:55pm UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783/6 "2009-03-03T21:55:46Z")

</div>

Hi Brian, Gary,

yeah I’m only simple YAML, and it seems to work for me for what I’m  
doing. I’ll definitely try to have a C# or Java client consume these  
and see what happens.

Thanks for FastYAML too, interesting.

cheers!

– Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 3, 2009, 12:20am UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783/7 "2009-03-03T00:20:56Z")

</div>

You’re missing the ‘—’ header in these examples. YAML may behave  
more robustly with the header.

Check out FastYAML on github. It’s way faster than YAML, doesn’t use  
Syck, and is way more robust than YAML.

-Gary

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 3, 2009, 10:47pm UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783/8 "2009-03-03T22:47:03Z")

</div>

Thibaut BarrÃ¨re wrote:

> Hi Brian, Gary,
> 
> yeah I’m only simple YAML, and it seems to work for me for what I’m  
> doing. I’ll definitely try to have a C# or Java client consume these  
> and see what happens.
> 
> Thanks for FastYAML too, interesting.

One other thought: if it’s simple, look at JSON. It’s easy to extend to  
serialise arbitrary Ruby objects.

YAML can do things like handling multiple references to the same object,  
but it sounds like you don’t need that level of sophistication.

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 4, 2009, 10:30am UTC](https://www.ruby-forum.com/t/using-yaml-for-inter-process-communication-anything-built-in/161783/9 "2009-03-04T10:30:38Z")

</div>

> One other thought: if it’s simple, look at JSON. It’s easy to extend to  
> serialise arbitrary Ruby objects.

I’ve been thinking about that. One point that made me choose YAML  
instead is that YAML support is built-in in STD ruby, where JSON is  
not (AFAIK).

As well from my experience YAML is better covered than JSON on other  
platforms (such as .Net)…

That’s why I choosed YAML for the moment.

> YAML can do things like handling multiple references to the same object,  
> but it sounds like you don’t need that level of sophistication.

I don’t need this for the moment, but it may come 🙂

cheers and thanks for the feedback, appreciated

– Thibaut
