JMS:是否可以从OnMessage()中的队列中获取多个消息而无需提交或回滚 [英] JMS: Can we get multiple messages from queue in OnMessage() withtout commit or rollback

查看:342
本文介绍了JMS:是否可以从OnMessage()中的队列中获取多个消息而无需提交或回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个JMS客户端,该客户端从远程服务器接收JMS消息. 我正在客户端的onMessage()方法中监听JMS消息.

I am using a JMS client which receives JMS messages from a remote server. I am listening to the JMS message in the onMessage() method of the client.

我面临的问题是,即使我定期在客户端使用消息,消息也在服务器端累积.

The issue I am facing is that, messages are getting accumulated on the Server side even while I am consuming the messages on Client side at regular interval.

我根据在客户端执行的处理发送rollback()或commit().

I send a rollback() or commit() depending upon the processing I am doing on the client's end.

我有一个查询,当我正在处理JMS消息并且没有将commit()发送到队列时,是否可以从服务器获取另一条消息.

I have a query that while I am processing the JMS message and I have not sent a commit() to the queue, can I get another message from the server.

请注意,对于处理,我正在等待处理同步块中收到的消息. 在我仍在处理但尚未将提交发送到队列时,我会收到一条新消息吗?

Please note that for the processing, I am doing a wait for the processing of the message received in a synchronized block. Will I get a new message while I am still processing and I have not sent a commit to the queue?

推荐答案

MessageListener#onMessage()作为会话线程的一部分执行, 因此直到从onMessage()返回之前,您都不会收到下一条消息.

MessageListener#onMessage() is executed as part of session thread, so you will not receive next message until return from onMessage().

通常,如果期望花费更多时间,则不应在onMessage()中处理消息.将消息排队到单独的数据结构中,并由其他线程对其进行处理.

In general, you should not process messages in onMessage(), if it is expected to take more time. Enqueue message into separate data structure and have some other thread process it.

您不必在每条消息后都调用commit(),您可以继续接收消息.

You do not have to call commit() after every message, you can continue to receive message.

不.不调用提交/回滚而收到的消息的数量取决于客户端缓冲区的大小-通常可以在队列/全局配置.

No. of message received without calling commit/rollback depends on client buffer size - usually configurable at queue/global.

请注意,在处理过程中,我正在等待 处理在同步块中接收到的消息.我会得到吗 我仍在处理但尚未发送提交的新消息 排队?

Please note that for the processing, I am doing a wait for the processing of the message received in a synchronized block. Will I get a new message while I am still processing and I have not sent a commit to the queue?

如果您在onMessage()中进行处理,则不会收到新消息,因此无需在onMessage()中包含同步块.

If you are processing in onMessage() you will not receive new message, so no need to have synchronized block inside onMessage().

这篇关于JMS:是否可以从OnMessage()中的队列中获取多个消息而无需提交或回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆