hi <br><br><table><tbody><tr><td class="votecell"><div class="vote">
</div>
<br></td>
<td class="postcell">
<div>
<div class="post-text" itemprop="description">
<p>I am trying to understand the RabitMq server with a sender
and a receiver program. Now the entire setup works well when the sender
sends a single message and the same would be received by the receiver.</p>
<p>however when i send two messages( by running sender twice) and run
the receiver program twice i get only the first message. </p>
<p>Sender</p>
<pre><code> ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, true, false, false, null);
String message = "He12!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println("Sent "+message);
channel.close();
connection.close();
</code></pre>
<p>Receiver</p>
<pre><code> ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, true, false, false, null);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message;
if (delivery != null) {
message = new String(delivery.getBody());
System.out.println("Reciever .."+message);
}
channel.close();
connection.close();
</code></pre>
</div></div></td></tr></tbody></table><br>I dont have a infinite while loop in the receiver code (as shown in the getting started page in the rabbitMq site ) because i want to expose this receiver as a web service sending one message at a time.<br><br>I also noticed by executing the commond rabbitMqctl list_queues that the entire queue contents become zero as and when the control reaches <br><pre><code> channel.basicConsume(QUEUE_NAME, true, consumer);<br><br><br>Kindly let me know if i am missing something.<br></code></pre><br>