[rabbitmq-discuss] Basic question on message delivery problem
Tom Reineke
reineke at apt-solutions.de
Thu Dec 5 07:42:58 GMT 2013
Thank you very much for your feedback, Simon and woodslee. I now have an idea what the problem might be. For both localhost and dev-environment we use the same rabbitmq-cloud service. This might explain, why I got only every second message in the first place. As I extracted the relevant code to a main-method I obviously created yet another consumer, which is why now only every third message was displayed.
I'm going to try this out. Thanks a lot!
Von meinem iPhone gesendet
Am 05.12.2013 um 02:48 schrieb "woodslee" <woodslee at 126.com<mailto:woodslee at 126.com>>:
Hi Tom
I run the test in my computer, and I got all the messages form 0 to 9.
but i comment the statement
if (!StringUtils.isEmpty(message))
Is the static method "isEmpty" wrong?
----- Original Message -----
From: Tom Reineke<mailto:tom.reineke at googlemail.com>
To: rabbitmq-discuss<mailto:rabbitmq-discuss at googlegroups.com>
Sent: 2013-12-04, 23:26:47
Subject: [rabbitmq-discuss] Basic question on message delivery problem
Hi,
I seem to have a very basic problem when setting up RabbitMQ and would be grateful for any help. Ich have the following class:
public class RabbitTest {
private final static ConnectionFactory factory = new ConnectionFactory();
private final static String MAIL_QUEUE_NAME = "mailQueue";
private static Connection connection;
private static Channel channel;
private static QueueingConsumer consumer;
public static void main(final String[] args) throws IOException, KeyManagementException, NoSuchAlgorithmException, URISyntaxException, InterruptedException {
factory = new ConnectionFactory();
factory.setHost("localhost");
connection = factory.newConnection();
channel = connection.createChannel();
channel.queueDeclare(MAIL_QUEUE_NAME, true, false, false, null);
consumer = new QueueingConsumer(channel);
channel.basicConsume(MAIL_QUEUE_NAME, false, consumer);
new Thread() {
@Override
public void run() {
while (true) {
try {
// The processor stops here until something
// is in the queue. It does not continue with the next
final QueueingConsumer.Delivery delivery = consumer
.nextDelivery();
final String message = new String(delivery.getBody());
if (!StringUtils.isEmpty(message)) {
System.out.println("########## message #############");
System.out.println(message);
}
} catch (final Exception e) {
}
}
}
}.start();
for (int i = 0; i < 10; i++) {
createMailTask("message " + i);
}
Thread.sleep(10000);
channel.close();
connection.close();
}
public static void createMailTask(final String amqpMessage)
throws IOException {
final Channel ch = connection.createChannel();
ch.queueDeclare(MAIL_QUEUE_NAME, true, false, false, null);
ch.basicPublish("", MAIL_QUEUE_NAME,
MessageProperties.PERSISTENT_TEXT_PLAIN, amqpMessage.getBytes());
ch.close();
}
}
I would have assumed that I get a log output for each of the 10 messages; instead I only get:
[Thread-0] INFO de.apt.utils.APTMailUtil - ########## message #############
[Thread-0] INFO de.apt.utils.APTMailUtil - message 2
[Thread-0] INFO de.apt.utils.APTMailUtil - ########## message #############
[Thread-0] INFO de.apt.utils.APTMailUtil - message 5
[Thread-0] INFO de.apt.utils.APTMailUtil - ########## message #############
[Thread-0] INFO de.apt.utils.APTMailUtil - message 8
Can you tell me where the problem is in my code?
_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com<mailto:rabbitmq-discuss at lists.rabbitmq.com>
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20131205/c679e8d5/attachment.html>
More information about the rabbitmq-discuss
mailing list