title: Consumer receives Single message from receive method in Apache ActiveMQ Artemis
body: <p>I am implementing Apache ActiveMQ Artemis in my project which connects to Artemis remote server. So I first decided to create a standalone project with producer and consumer.</p>
  
  <pre><code>import javax.jms.Connection;
  import javax.jms.ConnectionFactory;
  import javax.jms.Destination;
  import javax.jms.MessageConsumer;
  import javax.jms.MessageProducer;
  import javax.jms.Queue;
  import javax.jms.Session;
  import javax.jms.TextMessage;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  
  import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
  import org.apache.activemq.artemis.utils.UUIDGenerator;
  
  /**
   * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message.
   */
  public class QueueExample {
  
     public static void main(final String[] args) throws Exception {
        Connection connection = null;
  
     try {
  
           ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory("tcp://54.67.23.67:61616",  UUIDGenerator.getInstance().generateStringUUID());
           // Step 4.Create a JMS Connection
           connection = cf.createConnection("test","test123");
  
           // Step 5. Create a JMS Session
           Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  
           // Step 6. Create a JMS Message Producer
           MessageProducer producer = session.createProducer(null);
  
           // Step 7. Create a Text Message
           TextMessage message1 = session.createTextMessage("This is a text message1");
           Thread.sleep(1000l);
           TextMessage message2 = session.createTextMessage("This is a text message2");
  
  
           System.out.println("Sent message: " + message1.getText());
  
           System.out.println("Sent message: " + message2.getText());
  
           Destination destination = session.createQueue("TESTQUEUE");
  
           // Step 8. Send the Message
           producer.send(destination,message1);
           producer.send(destination,message2);
  
           // Step 9. Create a JMS Message Consumer
           MessageConsumer messageConsumer = session.createConsumer(destination);
  
           // Step 10. Start the Connection
           connection.start();
  
           // Step 11. Receive the message
           TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
  
           System.out.println("Received message: " + messageReceived.getText());
        } finally {
           // Step 12. Be sure to close our JMS resources!
           if (initialContext != null) {
              initialContext.close();
           }
           if (connection != null) {
              connection.close();
           }
        }
     }
  }
  </code></pre>
  
  <p>I send message from producer 2 times, but while consuming I receive only 1 message. Below is the output I receive:</p>
  
  <p><strong>Received</strong></p>
  
  <pre><code>Sent message: This is a text message1
  Sent message: This is a text message2
  Received message: This is a text message1 
  </code></pre>
  
  <p><strong>Expected</strong></p>
  
  <pre><code>Sent message: This is a text message1
  Sent message: This is a text message2
  Received message: This is a text message1
  Received message: This is a text message2
  </code></pre>
  
  <p>When I again run the code I get <code>Received message: This is a text message2</code>, but I want both messages Message1 and Message2 at the same time. </p>
  
  <p>What is happening here? Can anyone please guide me, because I tried searching this issue but no results found.</p>
  
  <p>Is my Artemis server not properly configured, or there is some issue with code?</p>