HornetQ 2.2.5 嵌入示例异常
我是 HornetQ 的新手,正在测试 hornetQ 示例。我在运行示例 EmbeddedExample.java(位于:hornetq-2.2.5.Final\examples\core\embedded\src\org\hornetq\core\example 中)时遇到异常。我在该示例中做了一些更改并得到了异常。我所做的更改是,我将发送进程和消费进程放在一个 1,00,000 次迭代的 for 循环中。 代码是:
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());
生产者工作正常,消费者在读取 18K 或 13K 消息后给我一个异常。堆栈跟踪是:
[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
如何克服此异常?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该示例将仅使用 50M 启动 VM,在您的示例中,您发送 100K 消息,这对于 50M 来说可能不够。
我这里没有您的更改,但我可以使用 100K 消息运行该示例,前提是在 build.xml 上提供更多内存。
在中断通信并导致会话关闭之前,您可能会遇到一些异常。
另外,消息系统是异步的,所以我建议您将发送块更改为:
并且您还应该对消费进行确认。否则该消息仍将保留在内存中。
该示例的目的是展示如何嵌入 HornetQ。对于其他用法,例如确认和生成,还有其他示例。
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:
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.