title: How to stack received messages and process them in batch
body: <p>I'd like to create a consumer which stacks arriving messages, and waits:</p>
  
  <ul>
  <li>until <code>n</code> messages have arrived.</li>
  <li><code>t</code> seconds are elapsed.</li>
  </ul>
  
  <p>to process the whole stack of messages.</p>
  
  <p><a href="http://activemq.apache.org/what-is-the-prefetch-limit-for.html" rel="nofollow noreferrer">Pre-fetching</a> is not what I'm looking for. What I really need is to <strong>process</strong> messages together.</p>
  
  <pre class="lang-py prettyprint-override"><code>class MyListener(stomp.ConnectionListener):
  
      def on_message(self, headers, body):
  
          print ("Just received ONE message\n"
                 "I should wait for n-1 others\n"
                 "or t seconds before processing")
  </code></pre>