<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Fun with ones and zeros - erlang</title>
<subtitle>Barry&#039;s notes on computer software and hardware</subtitle>
<link href="/blog/tags/erlang"></link>
<updated>2026-05-08T19:57:38-07:00</updated>
<id>urn:uuid:c90af1db-5562-290e-b866-0fa3f22e4105</id>
<entry>
<title>Erlang-inspired improvements to amqplib</title>
<link href="/blog/entries/erlang-inspired-improvements-amqplib"></link>
<id>urn:uuid:3fb4b652-cbf7-dec8-1e4b-4dab3fbb2f61</id>
<updated>2008-06-09T16:10:44-07:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">
&lt;p&gt;&lt;a href=&quot;http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;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;amp;tag=funwithonesan-20&amp;amp;linkCode=ur2&amp;amp;camp=1789&amp;amp;creative=9325&quot; target=&quot;_blank&quot;&gt;&lt;img style=&quot;float:right; border:none;&quot; src=&quot;http://ecx.images-amazon.com/images/I/41PZoINyrRL._SL500_AA240_.jpg&quot; alt=&quot;Programming Erlang cover&quot;  title=&quot;View on Amazon&quot; /&gt;&lt;/a&gt;
   I&#039;ve been reading Joe Armstrong&#039;s &lt;a href=&quot;http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;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;amp;tag=funwithonesan-20&amp;amp;linkCode=ur2&amp;amp;camp=1789&amp;amp;creative=9325&quot; target=&quot;_blank&quot; title=&quot;View on Amazon&quot;&gt;Programming Erlang&lt;/a&gt;&lt;img src=&quot;http://www.assoc-amazon.com/e/ir?t=funwithonesan-20&amp;amp;l=ur2&amp;amp;o=1&quot; width=&quot;1&quot; height=&quot;1&quot; border=&quot;0&quot; alt=&quot;&quot; style=&quot;border:none !important; margin:0px !important;&quot; /&gt; book, and it&#039;s been a real eye-opener.   I&#039;ve been intrigued by functional programming languages like Haskell and OCaml for some time, but it&#039;s been hard seeing how they&#039;d be used for &lt;em&gt;real&lt;/em&gt; programs, instead of just silly little factorial or quicksort examples.  Joe&#039;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&#039;t seem like a bunch of gibberish :)
&lt;/p&gt;
&lt;p&gt;Haven&#039;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&#039;re pattern-matched and saved for later if they&#039;re not what the process is looking for right at that moment.
&lt;/p&gt;
&lt;p&gt;At the heart of &lt;a href=&quot;http://barryp.org/software/py-amqplib/&quot;&gt;amqplib&lt;/a&gt; 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&#039;t have.  Specifically: if you had called &lt;code&gt;basic_consume&lt;/code&gt; on a channel, and then called some other synchronous method like another &lt;code&gt;basic_consume&lt;/code&gt; call - while it was expecting a &lt;code&gt;basic_consume_ok&lt;/code&gt; response a &lt;code&gt;basic_deliver&lt;/code&gt; could arrive and the library would raise an Exception because that wasn&#039;t expected.   &lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;A lame workaround is to use the &lt;code&gt;nowait&lt;/code&gt; option most calls have, but I&#039;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&#039;d generally expect.  The improved code is currently in the &lt;a href=&quot;http://hg.barryp.org/py-amqplib/&quot;&gt;Mercurial repository&lt;/a&gt;, and will be put out as a new release after it&#039;s had a chance to settle.
&lt;/p&gt;


</content>
</entry>
</feed>