Reputation: 40428
What's the simplest way to take just the first message from a queue?
Given that there is nothing I can see in the header to filter on (no sequence numbers, or the like, at least as far as I can see), is there anything better than this?
from("webspheremq:topic:SNAPSHOTS")
.throttle(1).timePeriodMillis(1234567890L * 1000)
.to("direct:anotherqueue")
Prefer camel DSL over beans + java code :)
Edit
actually reading from a webspheremq topic.
Edit2
don't use Long.MAX_VALUE
as the time period! Try 1234567890L * 1000 instead
Upvotes: 1
Views: 371
Reputation: 16080
You could try to filter using a singleton holding first-ness state:
public static class FirstOrNot {
private static FirstOrNot _instance;
public synchronized boolean isfirst() {
if ( _instance == null ) {
_instance = new FirstOrNot();
return true;
}
return false;
}
}
FirstOrNot first = new FirstOrNot();
from("webspheremq:topic:SNAPSHOTS")
.filter().method( first , "isFirst" )
.to("direct:anotherqueue")
Perhaps you can use this as a starting point.
Cheers,
Upvotes: 1