<div dir="ltr"><p class="MsoNormal">Thanks to the feedback of Simon and woodslee I found out what
the problem was. For both localhost and dev-environment we use the same
rabbitmq-cloud service and therefore I received only every second message
in the first place. As I extracted the relevant code to a main-method (as you can see above) I
obviously created yet another consumer, which is why now only every third
message was displayed. The solution was to create a different mail queue for each environment.<o:p></o:p></p><br>Am Mittwoch, 4. Dezember 2013 16:26:47 UTC+1 schrieb Tom Reineke:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr">Hi,<div><br></div><div>I seem to have a very basic problem when setting up RabbitMQ and would be grateful for any help. Ich have the following class:</div><div><br></div><div><div>public class RabbitTest {</div><div><br></div><div><span style="white-space:pre"> </span>private final static ConnectionFactory factory = new ConnectionFactory();</div><div> private final static String MAIL_QUEUE_NAME = "mailQueue";</div><div> private static Connection connection;</div><div> private static Channel channel;</div><div> private static QueueingConsumer consumer;</div><div><br></div><div><span style="white-space:pre"> </span>public static void main(final String[] args) throws IOException, KeyManagementException, NoSuchAlgorithmException, URISyntaxException, InterruptedException {</div><div> factory = new ConnectionFactory();</div><div><span style="white-space:pre"> </span>factory.setHost("localhost");</div><div> connection = factory.newConnection();</div><div> channel = connection.createChannel();</div><div> channel.queueDeclare(MAIL_<wbr>QUEUE_NAME, true, false, false, null);</div><div> consumer = new QueueingConsumer(channel);</div><div> channel.basicConsume(MAIL_<wbr>QUEUE_NAME, false, consumer);</div><div> new Thread() {</div><div> @Override</div><div> public void run() {</div><div> while (true) {</div><div> try {</div><div> // The processor stops here until something</div><div> // is in the queue. It does not continue with the next</div><div> final QueueingConsumer.Delivery delivery = consumer</div><div> .nextDelivery();</div><div> final String message = new String(delivery.getBody());</div><div> if (!StringUtils.isEmpty(message)<wbr>) {</div><div> System.out.println("########## message #############");</div><div> System.out.println(message);</div><div> }</div><div> } catch (final Exception e) {</div><div><br></div><div> }</div><div> }</div><div> }</div><div> }.start();</div><div><br></div><div> for (int i = 0; i < 10; i++) {</div><div> createMailTask("message " + i);</div><div> }</div><div><br></div><div> Thread.sleep(10000);</div><div> channel.close();</div><div> connection.close();</div><div> }</div><div><br></div><div> public static void createMailTask(final String amqpMessage)</div><div> throws IOException {</div><div> final Channel ch = connection.createChannel();</div><div> ch.queueDeclare(MAIL_QUEUE_<wbr>NAME, true, false, false, null);</div><div> ch.basicPublish("", MAIL_QUEUE_NAME,</div><div> MessageProperties.PERSISTENT_<wbr>TEXT_PLAIN, amqpMessage.getBytes());</div><div> ch.close();</div><div> }</div><div>}</div><div><br></div><div>I would have assumed that I get a log output for each of the 10 messages; instead I only get:</div><div><br></div><div>[Thread-0] INFO de.apt.utils.APTMailUtil - ########## message #############</div><div>[Thread-0] INFO de.apt.utils.APTMailUtil - message 2</div><div>[Thread-0] INFO de.apt.utils.APTMailUtil - ########## message #############</div><div>[Thread-0] INFO de.apt.utils.APTMailUtil - message 5</div><div>[Thread-0] INFO de.apt.utils.APTMailUtil - ########## message #############</div><div>[Thread-0] INFO de.apt.utils.APTMailUtil - message 8</div></div><div><br></div><div>Can you tell me where the problem is in my code?</div></div></blockquote></div>