在活动kafka中添加新创建主题到订阅

时间:2017-03-22 18:32:48

标签: akka reactive-kafka

我在我们的游戏scala项目中开发了反应性kafka,在我们创建的5个主题中,由消费者群体订阅并且工作正常,现在问题是我创建了一个新主题,如何将此主题添加到现有消费者小组(可能)  我的代码是:

val consumerSettings = ConsumerSettings(system, new ByteArrayDeserializer, new StringDeserializer)
      .withBootstrapServers(bootStrapServer)
      .withGroupId(groupId).withPollInterval(100 millis)

   Consumer.committableSource(consumerSettings, Subscriptions.topics(topicList))
            .groupedWithin(10, 15 seconds)
            .map({
              group =>
                var offSetBatch = CommittableOffsetBatch.empty
                val sessionList = group.toList.map { eachItem =>
                  offSetBatch = offSetBatch.updated(eachItem.committableOffset)
                  Json.parse(eachItem.record.value()).as[cityModel]
                }
                processRecords(cityList)
                offSetBatch
            }).mapAsync(1)(_.commitScaladsl())
            .toMat(Sink.ignore)(Keep.both)
            .run()

有什么办法可以向消费者添加主题

1 个答案:

答案 0 :(得分:0)

在消费者创造中我们可以给出主题模式i:e Subscriptions.topicPattern(" *。in")将解决问题