<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Reading through <a
href="http://rubydoc.info/github/ruby-amqp/amqp/master/file/docs/ConnectingToTheBroker.textile">http://rubydoc.info/github/ruby-amqp/amqp/master/file/docs/ConnectingToTheBroker.textile</a>
and I noticed when using the AMQP gem with Unicorn you must:<br>
<br>
<i>"start the EventMachine reactor and AMQP connection after the
master process forks workers"</i><br>
<br>
We've been using Unicorn for some time now so I'm aware of
reestablishing connections after Unicorn forks, however I have some
questions in regards to AMQP. Do I simply need to start up AMQP in a
separate thread as in the example: <br>
<br>
<meta charset="utf-8">
<pre class="code" style="color: rgb(0, 0, 0); font-family: monospace; display: block; padding-top: 5px; padding-right: 12px; padding-bottom: 5px; padding-left: 12px; margin-top: 4px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(238, 238, 255); border-right-color: rgb(238, 238, 255); border-bottom-color: rgb(238, 238, 255); border-left-color: rgb(238, 238, 255); border-image: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(245, 245, 255); font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -w
ebkit-text-stroke-width: 0px; background-position: initial initial; background-repeat: initial initial; "><span class="const" style="color: rgb(88, 92, 246); ">Thread</span><span class="period">.</span><span class="id identifier rubyid_new" style="color: rgb(0, 133, 255); ">new</span> <span class="lbrace">{</span> <span class="const" style="color: rgb(88, 92, 246); ">AMQP</span><span class="period">.</span><span class="id identifier rubyid_start">start</span> <span class="rbrace">}</span></pre>
Then in my controllers I would need to do everything inside a
next_tick block? <br>
<meta charset="utf-8">
<pre class="code" style="color: rgb(0, 0, 0); font-family: monospace; display: block; padding-top: 5px; padding-right: 12px; padding-bottom: 5px; padding-left: 12px; margin-top: 4px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(238, 238, 255); border-right-color: rgb(238, 238, 255); border-bottom-color: rgb(238, 238, 255); border-left-color: rgb(238, 238, 255); border-image: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(245, 245, 255); font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -w
ebkit-text-stroke-width: 0px; background-position: initial initial; background-repeat: initial initial; "><span class="const" style="color: rgb(88, 92, 246); ">EventMachine</span><span class="period">.</span><span class="id identifier rubyid_next_tick">next_tick</span> <span class="kw" style="color: rgb(0, 0, 255); ">do
...
end
</span></pre>
<br>
Is this all that is required? How come in the example we are
connecting to a channel/queue in the after_fork hook? Is this for
debugging purposes?<br>
<br>
I also have one other question regarding EventMachine#next_tick.
I've read that:<br>
<br>
<i>"Everything scheduled using EM#next_tick will happen
synchronously in the main thread. Any long running tasks inside
an EM#next_tick block will cause the entire program to block until
complete. Typically a bad thing."<br>
<br>
</i>Does this mean we don't gain anything by using EM in this
fashion.. ie our attempt to use AMQP asynchronously is actually
synchronous? <br>
<br>
Thanks for the clarification!<br>
<br>
- M<br>
<br>
<br>
<br>
<br>
</body>
</html>