title: Group received messages in RabbitMQ, preferably using Spring AMQP?
body: <p>I'm receiving messages from a service (S) that publishes each individual property change to an entity as a separate message. A contrived example would be an entity like this:</p>
  
  <pre><code>Person {
      id: 123
      name: "Something",
      address: {...}
  }
  </code></pre>
  
  <p>If name and address are updated in the same transaction then (S) will publish two messages, <code>PersonNameCorrected</code> and <code>PersonMoved</code>. The problem is on the receiving side where I'm storing a projection of this <code>Person</code> entity and each property change causes a write to the database. So in this example there would be two writes to the database but if I could batch messages for a short period of time and group them by id then I would only have to make a single write to the database.</p>
  
  <p>How does one typically handle this in RabbitMQ? Does Spring AMQP provide an easier abstraction?</p>
  
  <p>Note that I have looked briefly at <a href="https://www.rabbitmq.com/consumer-prefetch.html" rel="noreferrer">prefetch</a> but I'm not sure if this is the way to go. Also prefetch, if I understand it correctly, is per connection basis. I'm trying to achieve this on a <em>per-queue</em> basis, because if batching (and thus added latency) is the way to go I wouldn't like to add this latency to ALL queues consumed by my service (but only to those that need the "group-by-id" features).</p>