Thanks for the answers! But If the producer is launched first and then the consumer, i'm losing all the initial messages until the consumer is created. I attach you the code snippets with the test.<div><br></div><div>
<br></div><div>/** Producer **/</div><div><br></div><div><div>ConnectionFactory factory = new ConnectionFactory();</div><div><br></div><div> factory.setUsername("guest");</div><div> factory.setPassword("guest");</div>
<div> factory.setVirtualHost("/");</div><div> factory.setRequestedHeartbeat(0);</div><div> factory.setHost("127.0.0.1");</div><div> factory.setPort(5672);</div><div><br></div>
<div> Connection conn = factory.newConnection();</div><div><br></div><div> Channel channel = conn.createChannel();</div><div> String exchangeName = "myExchangeFanOut";</div><div> String routingKey = "testRoute";</div>
<div><br></div><div> for(int i= 0; i<1000000;i++){</div><div> StringBuilder miCadena = new StringBuilder("Message num: ");</div><div> miCadena.append(i);</div><div> byte[] messageBodyBytes = miCadena.toString().getBytes();</div>
<div> channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes) ;</div><div> System.out.println("Sending message num: " + i);</div><div> }</div>
<div> channel.close();</div><div> conn.close();</div></div><div><br></div><div>/** Consumer **/</div><div><br></div><div><div>ConnectionFactory factory = new ConnectionFactory();</div><div><br></div><div> factory.setUsername("guest");</div>
<div> factory.setPassword("guest");</div><div> factory.setVirtualHost("/");</div><div> factory.setRequestedHeartbeat(0);</div><div> factory.setHost("127.0.0.1");</div>
<div> factory.setPort(5672);</div><div><br></div><div> Connection conn = factory.newConnection();</div><div><br></div><div> Channel channel = conn.createChannel();</div><div> String exchangeName = "myExchangeFanOut";</div>
<div> String queueName = "myQueue";</div><div> String routingKey = "testRoute";</div><div> boolean durable = true;</div><div> channel.exchangeDeclare(exchangeName, "fanout", durable);</div>
<div> channel.queueDeclare(queueName, durable, true, true,null); // parametros</div><div> channel.queueBind(queueName, exchangeName, routingKey);</div><div><br></div><div> boolean noAck = false;</div>
<div> QueueingConsumer consumer = new QueueingConsumer(channel);</div><div> channel.basicConsume(queueName, noAck, consumer);</div><div> boolean runInfinite = true;</div><div><br></div><div> while (runInfinite) {</div>
<div> QueueingConsumer.Delivery delivery;</div><div> try {</div><div> delivery = consumer.nextDelivery();</div><div> } catch (InterruptedException ie) {</div><div> continue;</div>
<div> }</div><div> System.out.println("Processing received message. " + new String(delivery.getBody()));</div><div> channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);</div>
<div> }</div><div><br></div><div> channel.close();</div><div> conn.close();</div></div><div><br></div><div><br></div><div>In addition i have another question , is it possible to make that not all the consumers get all the messages with a fanout exchange, i mean is it possible to balance the messages in between the consumers. Thanks a lot. regards!<br clear="all">
<br>Francisco González-Blanch Rodríguez<br>
<br><br><div class="gmail_quote">On Fri, Jul 9, 2010 at 1:39 PM, Ovidiu Deac <span dir="ltr"><<a href="mailto:ovidiudeac@gmail.com">ovidiudeac@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
If nobody extracts the message from the queue the message won't be lost.<br>
<div><div></div><div class="h5"><br>
On Fri, Jul 9, 2010 at 1:09 PM, Francisco Gonzalez-Blanch<br>
<<a href="mailto:fblanch@gmail.com">fblanch@gmail.com</a>> wrote:<br>
> Hi all,<br>
> I'm a newbie in rabbitmq and i'm working on a distributed data processing<br>
> application using rabbitmq as distributed task queue. I want to ask you<br>
> about where can i find information about how to make persistent queues, and<br>
> how to make that, if a producer sends messages to queue and no one is listen<br>
> to it and then a consumer is attached , the consumer gets all the messages,<br>
> even the ones that were produced before the consumer was attached. Thank you<br>
> very much.<br>
><br>
><br>
><br>
</div></div><div><div></div><div class="h5">> _______________________________________________<br>
> rabbitmq-discuss mailing list<br>
> <a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
> <a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
><br>
><br>
</div></div></blockquote></div><br></div>