-1

I am able to read the messages from activemq using camel context[xml], but i could like to read only no of the messages, for example if queue contains 10 000 messages, we want to read only first 1 000 messages, remaining shouldn't be touched.

I am new to the camel

James Z
  • 12,209
  • 10
  • 24
  • 44
  • Your question is unclear. It first says that you want to read the number of messages, but then you say you actually want to read first 1000 messages instead. Which one is it? – James Z Mar 20 '18 at 20:27

2 Answers2

0

It is not quite clear how you want your program to work. Do you want to stop the route after 1000 messages? Or your program? Or just finish them before processing the rest?

Anyway, the Jms component has a maxMessagesPerTask parameter that is the number of messages a task can receive after which it's terminated. That might do what you want.

"jms:queue:order?maxMessagesPerTask=1000"

Jan Larsen
  • 831
  • 6
  • 13
  • That option is more of an internal Spring-JMS thingy that controls how long a consumer thread may be active before its should terminate. Those options can be used to tweak Spring JMS to fine tune how quickly/slowly it reacts on scaling up/down consumers depdending on how quick/slow you can process the messages, and pending messages on the queue etc. – Claus Ibsen Mar 21 '18 at 07:57
0

What if there is only 500 messages in the queue, should you wait until you have received additional 500, so the total is 1000. And what if you restart your application etc.

It's a bit strange use-case. The Camel JMS component is designed to continuesly consume from the queue. If you want to stop then look at the Control Bus EIP where you can control Camel routes, and stop them. And also look at the RoutePolicy where you can control routes using that, for example look at the throttling route policy which can start/stop routes depending on load etc.

The CiA2 book also has coverage of managing and controlling Camel routes, you can look at in the management chapter.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65