title: Retroactive Consumers in ActiveMQ JMS API
body: <p>I'm investigating ActiveMQ to see if it will work for a project. The current use case I need to demonstrate is that late-joining subscribers will receive topics published prior to the creation of the subscription. It seemed that ActiveMQ Retroactive Consumers would satisfy this need, but I can't get the code to work.</p>
  
  <pre class="lang-java prettyprint-override"><code>ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("[url]");
  Connection connection = connectionFactory.createConnection();
  connection.start();
  
  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  
  Destination destination = session.createTopic("testAddress?consumer.retroactive=true");
  
  MessageProducer producer = session.createProducer(destination);
  
  TextMessage message = session.createTextMessage("Hello, World!");
  
  producer.send(message);
  
  Thread.sleep(5000);
  
  session.createConsumer(destination).setMessageListener(message2 -&gt; processMessage(message2));
  
  session.close();
  connection.close();
  connectionFactory.close();
  </code></pre>
  
  <p>All I'm trying to demonstrate here is that a topic can be published, and then some arbitrary amount of time later (eg. 5 seconds) a consumer can subscribe to the topic and receive the previous message.</p>
  
  <p>As far as I can tell, the issue seems to be that creating the topic creates an address but doesn't create any associated queues. If I send a topic to the address before the queue is made (either in code or manually via the web interface to the broker), the message seems to be ignored and the "un routed message count" is immediately incremented.</p>
  
  <p>The ActiveMQ documentation ( <a href="https://activemq.apache.org/retroactive-consumer" rel="nofollow noreferrer">https://activemq.apache.org/retroactive-consumer</a> ) doesn't provide any greater detail on how to set up a retroactive consumer than appending "?consumer.retroactive=true" when making the topic, so I wonder if there are some other configuration aspects I'm missing.</p>