<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>Fun with ones and zeros - erlang</title>
<description><![CDATA[Barry's notes on computer software and hardware]]></description>
<link>/blog/tags/erlang</link>
<lastBuildDate>Tue, 05 May 2026 21:45:17 -0700</lastBuildDate>
<item>
<title>Erlang-inspired improvements to amqplib</title>
<link>/blog/entries/erlang-inspired-improvements-amqplib</link>
<pubDate>Mon, 09 Jun 2008 16:10:44 -0700</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[
<p><a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FProgramming-Erlang-Software-Concurrent-World%2Fdp%2F193435600X%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1213051196%26sr%3D8-1&amp;tag=funwithonesan-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325" target="_blank"><img style="float:right; border:none;" src="http://ecx.images-amazon.com/images/I/41PZoINyrRL._SL500_AA240_.jpg" alt="Programming Erlang cover"  title="View on Amazon" /></a>
   I've been reading Joe Armstrong's <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FProgramming-Erlang-Software-Concurrent-World%2Fdp%2F193435600X%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1213051196%26sr%3D8-1&amp;tag=funwithonesan-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325" target="_blank" title="View on Amazon">Programming Erlang</a><img src="http://www.assoc-amazon.com/e/ir?t=funwithonesan-20&amp;l=ur2&amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> book, and it's been a real eye-opener.   I've been intrigued by functional programming languages like Haskell and OCaml for some time, but it's been hard seeing how they'd be used for <em>real</em> programs, instead of just silly little factorial or quicksort examples.  Joe's book is awfully well written and gives lot of very clear examples, so now when I look at bits of code like RabbitMQ, it doesn't seem like a bunch of gibberish :)
</p>
<p>Haven't finished the book yet, but one thing I picked up from it already was the interesting way Erlang handles messages sent to processes, in how they're pattern-matched and saved for later if they're not what the process is looking for right at that moment.
</p>
<p>At the heart of <a href="http://barryp.org/software/py-amqplib/">amqplib</a> versions 0.3 or lower is a terrible mess that tries to deal with waiting for particular AMQP frames.  Previously it would raise exceptions in some situations when it really shouldn't have.  Specifically: if you had called <code>basic_consume</code> on a channel, and then called some other synchronous method like another <code>basic_consume</code> call - while it was expecting a <code>basic_consume_ok</code> response a <code>basic_deliver</code> could arrive and the library would raise an Exception because that wasn't expected.   <br />
</p>
<p>A lame workaround is to use the <code>nowait</code> option most calls have, but I've now reworked things, cleaning up a lot of ugly code, and saving unexpected messages for later, similar to how Erlang does it.  So now I believe the client library behaves in the way you'd generally expect.  The improved code is currently in the <a href="http://hg.barryp.org/py-amqplib/">Mercurial repository</a>, and will be put out as a new release after it's had a chance to settle.
</p>


]]></description>
</item>
</channel>
</rss>