Java ActiveMQ客户端接收消息失败

发布于 2024-07-09 02:07:09 字数 933 浏览 8 评论 0原文

我正在尝试在 ActiveMQ 上实现性能测试,因此设置了一个基本的生产者和消费者来跨队列发送和接收消息。 我已经创建了一个没有任何问题的生产者,让它向队列写入特定数量的消息:

 for(int i = 0; i < numberOfMessages; i++){
                try{
                    String message = generateText(sizeOfMessage);
                    produceMessage(message);
                }
                catch (Exception e) {
                    logger.error("Caught exception while sending message", e);
                }
            }

这将继续完成,没有任何问题,并且我已经通过在管理网站上检查确认了这一点,有正确数量的待处理消息。

当我尝试从队列接收消息时出现问题。 使用简单的消费者从队列中读取,它将从队列中读取各种数量的消息,但在尝试接收其中一条消息时将停止。 我可以看到队列中仍有消息需要读取,但客户端不会继续传递其中一条消息。 我正在使用一种简单的方法来接收消息:

Message message = jmsTemplate.receive();

它适用于某些消息(大约 20-30 条),但随后只是锁定。 有人向我建议消息中的某些字符可能是转义字符(我使用了不同长度的随机字符串,因为这只是一个性能测试,实际上并未发送任何内容),所以我更改了所有消息到同一个字符串,这是字符“2”的重复,但仍然没有运气。 我正在使用 Spring 配置来加载访问 ActiveMQ 队列所需的所有组件,并且该队列正在我的本地主机上运行。

I am trying to implement performance testing on ActiveMQ, so have setup a basic producer and consumer to send and receive messages across a queue. I have created a producer with no problems, getting it to write a specific number of messages to the queue:

 for(int i = 0; i < numberOfMessages; i++){
                try{
                    String message = generateText(sizeOfMessage);
                    produceMessage(message);
                }
                catch (Exception e) {
                    logger.error("Caught exception while sending message", e);
                }
            }

This continues to completion with no problems and I have confirmed this with checks on the admin website, that have the correct number of messages pending.

The problem occurs when I try to receive the messages from the queue. Using a simple consumer to read from the queue, it will read a various number of messages from the queue, but then will stop when trying to receive one of the messages. I can see that there are still messages in the queue to be read, but the client will not progress passed one of the messages.
I am using a simple method to receive the messages:

Message message = jmsTemplate.receive();

and it works for some messages(about 20-30) but then just locks. It was suggested to me that some of the characters in the message may be an escape character (I was using a random string of varying length, due to this just being a performance test, not actually sending over any content) so I changed all messages to the same string, which is a repetition of the char '2' and still no luck.
I am using Spring configuration to load all of the components needed to access the ActiveMQ queue, and the queue is running on my localhost.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独木成林 2024-07-16 02:07:10

目前对此的看法还不是很多,但为了以后有人遇到同样问题时参考,我已经找到了解决方案。 activeMQ 的配置限制了发送者和接收者使用的内存量,然后减慢了发送者和接收者的速度,给我的默认值是:

<systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="20 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="1 gb" name="foo"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="100 mb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

我完全删除了这个配置,现在它可以正常工作了。 我正在进行性能测试,所以你可能想要加入自己的约束,但这绝对是我的问题的原因!

Not many views on this yet, but for future reference if anyone has the same problem, I have found the solution. The configuration for activeMQ limits the amount of memory used by the senders and receivers before slowing them down, the default values given to me were:

<systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="20 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="1 gb" name="foo"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="100 mb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

I removed this configuration completely and now it works a dream. I'm carrying out performance testing, so you may want to put your own constraints in, but this was definitely the cause of my problems!

榆西 2024-07-16 02:07:10

这是消息传递的一个经典问题; 如何对待缓慢的消费者。 FWIW 最近的 ActiveMQ 版本(例如 5.2)允许您在内存不足时后台打印到磁盘而不是阻塞生产者

Its a classic issue with messaging; what to do with slow consumers. FWIW more recent ActiveMQ releases such as 5.2 allow you to spool to disk rather than blocking producers when memory gets low

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文