开发者

HornetQ 2.2.5 Embeded Example Exception

I am new to HornetQ and I am testing hornetQ Examples. I am getting Exception while running the example EmbeddedExample.java(resides in : hornetq-2.2.5.Final\examples\core\embedded\src\org\hornetq\core\example). I had made some change in that example and getting Exception. The changes I had made is, I had put sending process and consuming process in a for loop of 1,00,000 iteration. The code is:

System.out.println("Producer:");
System.out.println("StartDate: "+new Date());
for (int i = 0; i < 100000; i++)
{   
    message.putStringProperty(propName, "Message: " + i);
    producer.send(message);             
}
System.out.println("EndDate: "+new Date());
// Step 7. Create the message consumer and start the connection
ClientConsumer messageConsumer = session.createConsumer(queueName);

session.start();

// Step 8. Receive the message.
System.out.println("Consumer:");
System.out.println("StartDate: "+new Date());

for (int i = 0; i < 100000; i++)            
{   
    ClientMessage messageReceived = messageConsumer.receive();
    System.out.println(messageReceived.getStringProperty(propName));
}
System.out.println("EndDate: "+new Date());            

Producer works fine,and consumer gives me an exception after reading 18K or 13K msges. The stack trace is:

[java] Message: 18384
[java] Sep 2, 2011 11:15:29 AM org.hornetq.core.logging.impl.JULLogDelegate
info
[java] INFO: HornetQ Server version 2.2.5.Final (HQ_2_2_5_FINAL_AS7, 121) [
588e32ee-d493-11e0-b759-0026b6a94d9b] stopped
[java] HornetQException[errorCode=102 message=Consumer is closed]
[java]     开发者_如何学编程at org.hornetq.core.client.impl.ClientConsumerImpl.checkClosed(C
lientConsumerImpl.java:811)
[java]     at org.hornetq.core.client.impl.ClientConsumerImpl.receive(Clien
tConsumerImpl.java:163)
[java]     at org.hornetq.core.client.impl.ClientConsumerImpl.receive(Clien
tConsumerImpl.java:364)
[java]     at org.hornetq.core.example.EmbeddedExample.main(EmbeddedExample
.java:107)
[java] Java Result: -1

BUILD FAILED
C:\hornetq-2.2.5.Final\examples\core\embedded\build.xml:40: EmbeddedExample

How do I overcome from this exception?


The example will start a VM with 50M only, and on your example you are sending 100K messages, what will probably not be enough for the 50M.

I don't have your changes here, but I could run the example with 100K messages given providing more memory on the build.xml.

You were probably getting a few exceptions before what interrupted the communication and made the session to close.

Also, Message systems are asynchronously, so I propose you to change your sending block to:

for (int i = 0; i < 100000; i++)
{ 
    message = sesison.createMessage(true); // move it   
    message.putStringProperty(propName, "Message: " + i);
    producer.send(message);             
}

And you should also ACK on the consuming. Otherwise the message will still be at the memory.

the intent of the example was to show how to embed HornetQ. For other usages such as acking and producing there are other examples.

for (int i = 0; i < 100000; i++)            
{   
    ClientMessage messageReceived = messageConsumer.receive();
    messageReceived.acknowledge();
    System.out.println(messageReceived.getStringProperty(propName));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜