How to create a LIFO Queue ChannelHow do I efficiently iterate over each entry in a Java Map?Create ArrayList from arrayHow do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How can I create an executable JAR with dependencies using Maven?How do I create a file and write to it in Java?How do I convert a String to an int in Java?How do I fix 'android.os.NetworkOnMainThreadException'?Creating a memory leak with JavaError sending message to a QueueChannel from chain in spring integration
Slow query when having 'contains' and '=' together in where clause
Which version of the Pigeonhole principle is correct? One is far stronger than the other
Why has the UK has not yet signed a continuity trade agreement with Turkey?
What was the earliest microcomputer Logo language implementation?
Wrong Schengen Visa exit stamp on my passport, who can I complain to?
Do household ovens ventilate heat to the outdoors?
Can Brexit be undone in an emergency?
How do you determine which representation of a function to use for Newton's method?
Very lazy puppy
Story/1980s sci fi anthology novel where a man is sucked into another world through a gold painting
In Bb5 systems against the Sicilian, why does White exchange their b5 bishop without playing a6?
Plot irregular circle in latex
Could the Orion project pusher plate model be used for asteroid deflection?
Where did Otto von Bismarck say "lying awake all night, hating"?
What is the word for a person who destroys monuments?
Talk about Grandpa's weird talk: Who are these folks?
Explanation of 申し訳ございません
Applications of mathematics in clinical setting
How do rulers get rich from war?
Delete empty subfolders, keep parent folder
What's the purpose of autocorrelation?
Can I separate garlic into cloves for storage?
What does the Free Recovery sign (UK) actually mean?
Why are there no programmes / playbills for movies?
How to create a LIFO Queue Channel
How do I efficiently iterate over each entry in a Java Map?Create ArrayList from arrayHow do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How can I create an executable JAR with dependencies using Maven?How do I create a file and write to it in Java?How do I convert a String to an int in Java?How do I fix 'android.os.NetworkOnMainThreadException'?Creating a memory leak with JavaError sending message to a QueueChannel from chain in spring integration
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Currently I am using a Queue Channel in my Integration flow but it uses a FIFO way of extraction. Is there a way to change it to LIFO?
Also, is there a way to remove messages from the Queue based on a property?
I suspect I will need to use a PriorityChannel for switching from FIFO to LIFO but I can't figure out how it would be accomplished.
@Bean
fun notificationChannel(): MessageChannel
return MessageChannels.queue().get()
For example, my QueueChannel will be filled with messages containing userId. Since I'm only interested in the latest state of the userId message I want to use LIFO and remove all messages with the same userId as the latest message.
java spring kotlin spring-integration
add a comment
|
Currently I am using a Queue Channel in my Integration flow but it uses a FIFO way of extraction. Is there a way to change it to LIFO?
Also, is there a way to remove messages from the Queue based on a property?
I suspect I will need to use a PriorityChannel for switching from FIFO to LIFO but I can't figure out how it would be accomplished.
@Bean
fun notificationChannel(): MessageChannel
return MessageChannels.queue().get()
For example, my QueueChannel will be filled with messages containing userId. Since I'm only interested in the latest state of the userId message I want to use LIFO and remove all messages with the same userId as the latest message.
java spring kotlin spring-integration
add a comment
|
Currently I am using a Queue Channel in my Integration flow but it uses a FIFO way of extraction. Is there a way to change it to LIFO?
Also, is there a way to remove messages from the Queue based on a property?
I suspect I will need to use a PriorityChannel for switching from FIFO to LIFO but I can't figure out how it would be accomplished.
@Bean
fun notificationChannel(): MessageChannel
return MessageChannels.queue().get()
For example, my QueueChannel will be filled with messages containing userId. Since I'm only interested in the latest state of the userId message I want to use LIFO and remove all messages with the same userId as the latest message.
java spring kotlin spring-integration
Currently I am using a Queue Channel in my Integration flow but it uses a FIFO way of extraction. Is there a way to change it to LIFO?
Also, is there a way to remove messages from the Queue based on a property?
I suspect I will need to use a PriorityChannel for switching from FIFO to LIFO but I can't figure out how it would be accomplished.
@Bean
fun notificationChannel(): MessageChannel
return MessageChannels.queue().get()
For example, my QueueChannel will be filled with messages containing userId. Since I'm only interested in the latest state of the userId message I want to use LIFO and remove all messages with the same userId as the latest message.
java spring kotlin spring-integration
java spring kotlin spring-integration
asked Mar 28 at 13:23
Radoslav HubenovRadoslav Hubenov
691 silver badge6 bronze badges
691 silver badge6 bronze badges
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
It sounds like you don't really want LIFO, you just want the latest for a given condition.
But, regardless, Queue is a pretty simple interface; it only has a handful of methods and the QueueChannel only uses poll(), offer() and size().
So it should be simple to create a custom queue, e.g. based on a thread-safe ConcurrentHashMap<String, Message<?>> with the key being your condition.
How would I have to proceed so that the older messages with the same userId in the queue are discarded?
– Radoslav Hubenov
Mar 28 at 13:49
1
If it's based on aMap, new entries with the same key will be replaced and it will only have the last one.
– Gary Russell
Mar 28 at 13:54
1
If you want to retain order for different userIds, you can use a combination of aLinkedHashSet<String>for the userIds andMap<String, Message<?>>for the messages. TheLinkedHashSetretains the original order when an element is replaced.
– Gary Russell
Mar 28 at 14:33
add a comment
|
Queue channel takes Queue as a constructor parameter public QueueChannel(Queue<Message<?>> queue) and spring-integration DSL provides public static QueueChannelSpec queue(Queue<Message<?>> queue). So you can use Collections.asLifoQueue(..) as an argument to the above factory method to get the behavior you want.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55398745%2fhow-to-create-a-lifo-queue-channel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It sounds like you don't really want LIFO, you just want the latest for a given condition.
But, regardless, Queue is a pretty simple interface; it only has a handful of methods and the QueueChannel only uses poll(), offer() and size().
So it should be simple to create a custom queue, e.g. based on a thread-safe ConcurrentHashMap<String, Message<?>> with the key being your condition.
How would I have to proceed so that the older messages with the same userId in the queue are discarded?
– Radoslav Hubenov
Mar 28 at 13:49
1
If it's based on aMap, new entries with the same key will be replaced and it will only have the last one.
– Gary Russell
Mar 28 at 13:54
1
If you want to retain order for different userIds, you can use a combination of aLinkedHashSet<String>for the userIds andMap<String, Message<?>>for the messages. TheLinkedHashSetretains the original order when an element is replaced.
– Gary Russell
Mar 28 at 14:33
add a comment
|
It sounds like you don't really want LIFO, you just want the latest for a given condition.
But, regardless, Queue is a pretty simple interface; it only has a handful of methods and the QueueChannel only uses poll(), offer() and size().
So it should be simple to create a custom queue, e.g. based on a thread-safe ConcurrentHashMap<String, Message<?>> with the key being your condition.
How would I have to proceed so that the older messages with the same userId in the queue are discarded?
– Radoslav Hubenov
Mar 28 at 13:49
1
If it's based on aMap, new entries with the same key will be replaced and it will only have the last one.
– Gary Russell
Mar 28 at 13:54
1
If you want to retain order for different userIds, you can use a combination of aLinkedHashSet<String>for the userIds andMap<String, Message<?>>for the messages. TheLinkedHashSetretains the original order when an element is replaced.
– Gary Russell
Mar 28 at 14:33
add a comment
|
It sounds like you don't really want LIFO, you just want the latest for a given condition.
But, regardless, Queue is a pretty simple interface; it only has a handful of methods and the QueueChannel only uses poll(), offer() and size().
So it should be simple to create a custom queue, e.g. based on a thread-safe ConcurrentHashMap<String, Message<?>> with the key being your condition.
It sounds like you don't really want LIFO, you just want the latest for a given condition.
But, regardless, Queue is a pretty simple interface; it only has a handful of methods and the QueueChannel only uses poll(), offer() and size().
So it should be simple to create a custom queue, e.g. based on a thread-safe ConcurrentHashMap<String, Message<?>> with the key being your condition.
answered Mar 28 at 13:40
Gary RussellGary Russell
94.5k9 gold badges59 silver badges86 bronze badges
94.5k9 gold badges59 silver badges86 bronze badges
How would I have to proceed so that the older messages with the same userId in the queue are discarded?
– Radoslav Hubenov
Mar 28 at 13:49
1
If it's based on aMap, new entries with the same key will be replaced and it will only have the last one.
– Gary Russell
Mar 28 at 13:54
1
If you want to retain order for different userIds, you can use a combination of aLinkedHashSet<String>for the userIds andMap<String, Message<?>>for the messages. TheLinkedHashSetretains the original order when an element is replaced.
– Gary Russell
Mar 28 at 14:33
add a comment
|
How would I have to proceed so that the older messages with the same userId in the queue are discarded?
– Radoslav Hubenov
Mar 28 at 13:49
1
If it's based on aMap, new entries with the same key will be replaced and it will only have the last one.
– Gary Russell
Mar 28 at 13:54
1
If you want to retain order for different userIds, you can use a combination of aLinkedHashSet<String>for the userIds andMap<String, Message<?>>for the messages. TheLinkedHashSetretains the original order when an element is replaced.
– Gary Russell
Mar 28 at 14:33
How would I have to proceed so that the older messages with the same userId in the queue are discarded?
– Radoslav Hubenov
Mar 28 at 13:49
How would I have to proceed so that the older messages with the same userId in the queue are discarded?
– Radoslav Hubenov
Mar 28 at 13:49
1
1
If it's based on a
Map, new entries with the same key will be replaced and it will only have the last one.– Gary Russell
Mar 28 at 13:54
If it's based on a
Map, new entries with the same key will be replaced and it will only have the last one.– Gary Russell
Mar 28 at 13:54
1
1
If you want to retain order for different userIds, you can use a combination of a
LinkedHashSet<String> for the userIds and Map<String, Message<?>> for the messages. The LinkedHashSet retains the original order when an element is replaced.– Gary Russell
Mar 28 at 14:33
If you want to retain order for different userIds, you can use a combination of a
LinkedHashSet<String> for the userIds and Map<String, Message<?>> for the messages. The LinkedHashSet retains the original order when an element is replaced.– Gary Russell
Mar 28 at 14:33
add a comment
|
Queue channel takes Queue as a constructor parameter public QueueChannel(Queue<Message<?>> queue) and spring-integration DSL provides public static QueueChannelSpec queue(Queue<Message<?>> queue). So you can use Collections.asLifoQueue(..) as an argument to the above factory method to get the behavior you want.
add a comment
|
Queue channel takes Queue as a constructor parameter public QueueChannel(Queue<Message<?>> queue) and spring-integration DSL provides public static QueueChannelSpec queue(Queue<Message<?>> queue). So you can use Collections.asLifoQueue(..) as an argument to the above factory method to get the behavior you want.
add a comment
|
Queue channel takes Queue as a constructor parameter public QueueChannel(Queue<Message<?>> queue) and spring-integration DSL provides public static QueueChannelSpec queue(Queue<Message<?>> queue). So you can use Collections.asLifoQueue(..) as an argument to the above factory method to get the behavior you want.
Queue channel takes Queue as a constructor parameter public QueueChannel(Queue<Message<?>> queue) and spring-integration DSL provides public static QueueChannelSpec queue(Queue<Message<?>> queue). So you can use Collections.asLifoQueue(..) as an argument to the above factory method to get the behavior you want.
answered Mar 28 at 13:42
Oleg ZhurakouskyOleg Zhurakousky
2,3908 silver badges10 bronze badges
2,3908 silver badges10 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55398745%2fhow-to-create-a-lifo-queue-channel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown