Reputation: 1098
I have a simple quarkus project that create topic "databases" and send list of databases to it.
How can I control the partitions?
I want to have different partition per each DatabaseID so all the messages with same Id will go to the same partition.
here is my application.properties:
kafka.bootstrap.servers=localhost:9092
mp.messaging.outgoing.databases.connector=smallrye-kafka
mp.messaging.outgoing.databases.key.serializer=org.apache.kafka.common.serialization.StringSerializer
mp.messaging.outgoing.databases.value.serializer=com.secupi.dbmanager.model.DatabaseSerializer
quarkus.class-loading.removed-resources."org.slf4j\:slf4j-api"=org.slf4j.Logger.class
and my code
@Outgoing("databases")
public <T> Multi<Record<String, Database>> generate() {
Collection<Database> dbs = databaseDao.getAll(new FilterParams());
return Multi.createFrom().items(dbs.stream().map(db -> Record.of(db.getName(), db)));
}
By default as I see the topic has been created with 100 partitions.
Thanks
Upvotes: 0
Views: 443
Reputation: 474
The number of partitions in your topic depends on how you are creating it. If it is auto-created the default number of partitions is configured on Kafka broker config. IF you are in dev-mode using Quarkus devservices you can configure it to create topic-partitions for you : https://quarkus.io/guides/kafka#configuring-kafka-topics
If the topic is already created with 100 partitions, all you need to do is produce Kafka records with consistent keys. In the snippet you've sent if you create Record.of
with database ID as your key the default partitioner will assign it to a unique partition every time.
Upvotes: 0