Kafka是否支持主题或消息的优先级? [英] Does Kafka support priority for topic or message?
问题描述
我正在研究Kafka是否支持任何队列或消息要处理的优先级.
I was exploring the fact whether Kafka supports priority for any queue or message to process.
似乎不支持任何此类东西.我在Google上搜索并找到了支持此功能的邮件存档:
It seems it doesn't support any such thing. I googled and found this mail archive which supports this also: http://mail-archives.apache.org/mod_mbox/incubator-kafka-users/201206.mbox/%3CCAOeJiJhVHsr=d6aSTihPsqWVg6vK5xYLam6yMDcd6UAUoXf-DQ@mail.gmail.com%3E
这里配置了Kafka的任何人都可以优先考虑任何主题或消息吗?
Does anyone here configured of Kafka to prioritize any topic or message?
推荐答案
Kafka是一种快速,可扩展的,本质上通过其设计,分区和复制的提交日志服务进行分发的应用程序,因此,主题或消息没有优先级.
Kafka is a fast, scalable, distributed in nature by its design, partitioned and replicated commit log service.So there is no priority on topic or message.
我也遇到了同样的问题.解决方法非常简单.在kafka队列中创建主题,让我们说:
I also faced same problem that you have.Solution is very simple.Create topics in kafka queue,Let say:
-
high_priority_queue
high_priority_queue
medium_priority_queue
medium_priority_queue
优先级较低的队列
在high_priority_queue中发布高优先级消息,在medium_priority_queue中发布中优先级消息.
Publish high priority message in high_priority_queue and medium priority message in medium_priority_queue.
现在您可以创建kafka使用者并为所有主题打开流.
Now you can create kafka consumer and open stream for all topic.
// this is scala code
val props = new Properties()
props.put("group.id", groupId)
props.put("zookeeper.connect", zookeeperConnect)
val config = new ConsumerConfig(props)
val connector = Consumer.create(config)
val topicWithStreamCount = Map(
"high_priority_queue" -> 1,
"medium_priority_queue" -> 1,
"low_priority_queue" -> 1
)
val streamsMap = connector.createMessageStreams(topicWithStreamCount)
您可以获得每个主题的信息流.现在,如果主题没有任何消息,则可以先阅读high_priority主题,然后回退medium_priority_queue主题.如果medium_priority_queue为空,则读取low_priority队列.
You get stream of each topic.Now you can first read high_priority topic if topic does not have any message then fallback on medium_priority_queue topic. if medium_priority_queue is empty then read low_priority queue.
这个技巧对我来说很好用.可能对您有帮助!!
This trick is working fine for me.May be helpful for you!!.
这篇关于Kafka是否支持主题或消息的优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!