문제

Sorry, if it is a duplicate question.

I have a legacy web application which uses Queues (yes. normal Java Queue) and custom polling (every 500ms). A REST web service (/message) will be called, which will return the message if any otherwise empty string.

My need: If any message is available in Queue, in Real-Time, the client should get the message. So I can save 500ms.

Is there any advantage to moving to JMS from current approach? From this link JMS MessageConsumer's messageListener makes push or pull? it seems, MessageListener (process is asynchronous) uses polling which is no different from current approach.

If it is vendor based, how HornetQ/ActiveMQ supports MessageListener?

EDIT: The queue is used for integration of two systems. A web app & standlone java program.

도움이 되었습니까?

해결책

Either receive or a MessageListener will be asynchronous and will be called as soon as you receive a message.

you could control the pre-fetch size of your client.

Now, if all you need is to avoid the delay of poling every 500 ms, using a Queue system may be an overkill? It's perfect fine to use java.util.Queue (or any other subclass).

If all you need is to block until an element of a java.util.Queue is available, and you don't need distributed messaging, persistence or anything like you could simply using BlockingDequeue and your thread would unblock as soon as you have a message..

Look at this:

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingDeque.html

다른 팁

The Async MessageListener is implemented using a push based model. In ActiveMQ the broker sends a number of messages to the client based in it's set prefetch value so that messages are ready for consumption. Whether or not this helps with your particular use case is a question you need to answer for yourself.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top