使用某个速率的消费者队列通道(QueueChannel)如何?

huangapple 未分类评论55阅读模式
英文:

How consumer QueueChannel with some rate?

问题

这里是一个示例,展示了如何填充和处理队列。但是如何按速率处理消息?比如每秒处理N条消息?

更新
这里的“处理”是指“出队”。例如,如何每秒出队N条消息?

英文:

Here is example how fill and process queue. But how process message with rate? Like process N messages per second?

UPDATE
Here by "porcess": I meant "dequeue". E.g. how to dequeue N messages per second?

答案1

得分: 0

你可以像我之前提到的那样编写一个循环,配合某种速率控制(例如,通过Thread.sleep作为最基本的方法)。
你还可以尝试使用@Scheduled注解。

这里有一个示例方法,它将每秒调用100次:

@Scheduled(fixedRate = 10)
public void dequeue() {
    //queue.poll(..)
}
英文:

You can wrote a loop as I mentioned earlier with some kind of rate control (e.g, via Thread.sleep as the most rudimentary).
You can also try to use @Scheduled annotation.

Here is the example of a method that will be invoked 100 times per second

@Scheduled(fixedRate = 10)
public void dequeue() {
		//queue.poll(..)
}

huangapple
  • 本文由 发表于 2020年4月8日 16:59:17
  • 转载请务必保留本文链接:https://java.coder-hub.com/61096936.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定