title: ActiveMQ distribution of messages
body: <p>I have several servers that produce xml files from Python and some other servers that consume those xmls using Java. I've only recently looked into JMS and <a href="http://activemq.apache.org/" rel="nofollow noreferrer">ActiveMQ</a> and decided to try using it to pass the xml files.</p>
  
  <p>So I set up ActiveMQ daemons on the consumer servers and figured I'd implement some cycling method on the produces to distribute the xmls evenly across the consumers.</p>
  
  <pre><code>Python  -----------------------------&gt; ActiveMQ ---&gt; Java
          \                           /
           \                         /
            ---------------------------&gt; ActiveMQ ---&gt; Java
                                   /  /
  Python  ----------------------------
  </code></pre>
  
  <p>For testing, I ran one producer and one consumer and looked at the results.</p>
  
  <p>To my surprise, the messages from the producer were distributed across all the ActiveMQ servers on the network. Since I only ran one consumer it only received the xmls that got to the ActiveMQ daemon on that machine, and the rest of the xmls were waiting patiently on the other ActiveMQ daemons on other machines.</p>
  
  <pre><code>Python  -----------------------------&gt; ActiveMQ ---&gt; Java (work)
                                            |
                                            |
                                         ActiveMQ (xmls piling up)
  </code></pre>
  
  <p><strong>EDIT: This is not what actually happened, sorry. See below for details</strong></p>
  
  <p>Now, I'm not complaining, since this is what I wanted anyway, but I'm a little confused: what is the proper way to implement this many-to-many queue that I'm after?</p>
  
  <p>Should I set up ActiveMQ daemons on my producer machines as well, send the xmls to the localhost ActiveMQs and trust the automatic discovery to get the xmls to consumers?</p>
  
  <pre><code>Python ---&gt; ActiveMQ ------------------------------ ActiveMQ ---&gt; Java
                  |                                      |
                  |                                      |
                  |                                -- ActiveMQ ---&gt; Java
                  |                               |  
  Python ---&gt; ActiveMQ----------------------------
  </code></pre>
  
  <p>Should I stick to my original plan, and cycle the messages across the consumer machines, just to be safe?</p>
  
  <p>Or is there an API I should use that hide those details from my processes?</p>
  
  <p>BTW, the producers are python processes using STOMP and the consumers are java using JMS.</p>
  
  <p>I apologize if your eyes are hurting from my crappy ASCII art, I wasn't sure if I'm being clear enough with just words.</p>
  
  <h2>EDIT</h2>
  
  <p>Apparently, when I was running "one producer and one consumer" I didn't notice that the other consumers were already running. They were just not doing anything useful with the xmls they processed. That's why I was seeing partial results.</p>
  
  <p>After reading a bit more and experimenting a little, I figured out the following:</p>
  
  <p>By default, ActiveMQ will auto-discover other ActiveMQ instances on the local network, and create a store-and-forward <a href="http://activemq.apache.org/networks-of-brokers.html" rel="nofollow noreferrer">network of brokers</a>. This means that the producer can post the xmls to any ActiveMQ instance and they will find their way to consumers listening on other ActiveMQ instances on the same network. </p>
  
  <p>Note that the documentation claims that auto-discovery is not recommended for production setups.</p>
  
  <p>The accepted answer below still holds true, though. The simplest way to use ActiveMQ is just use one or two servers as "Queue Servers". Nevertheless, I chose to go with my original plan, because I <em>think</em> it will reduce network traffic (with a middle server, xmls have to go into it and the out of it again).</p>