'Priority channel with MessageStore and custom comparator
I have a channel witch collects messages in h2 DB:
.channel(MessageChannels.priority("jdbcChannel", jdbcChannelMessageStore(),"jdbc").capacity(5))
I need to add custom Comparator, to prioritize, witch messages to poll first.
I did like this:
.channel(MessageChannels.priority("jdbcChannel", jdbcChannelMessageStore(),"jdbc").capacity(5).comparator(comparator))
But I got an error: Only one of 'comparator' or 'messageGroupStore' can be specified.
What is this? I can add comparator only to channel without jdbc mode? And what if I need to use jdbc and comparator together?
Solution 1:[1]
That's correct. You cannot. The persistent store has a limitation for the priority functionality only via specific MESSAGE_PRIORITY column. The persistent implementation cannot do any custom comparison since there is no way to propagate it down to the store. For JDBC, for example, we do this on PriorityChannel:
public String getPriorityPollFromGroupQuery() {
return SELECT_COMMON +
"order by MESSAGE_PRIORITY DESC NULLS LAST, CREATED_DATE, MESSAGE_SEQUENCE LIMIT 1";
}
So, we sort messages in the store by that MESSAGE_PRIORITY and return only one, top record.
Does it make sense for you?
You may provide your own H2ChannelMessageStoreQueryProvider implementation, though, but again: Java Comparator is not going to be send down do DB.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Artem Bilan |
