# Can I horizontally scale MQTT Kafka Source Connector?

**URL:** <https://forum.confluent.io/t/can-i-horizontally-scale-mqtt-kafka-source-connector/9928>\
**Category:** Kafka Connect\
**Created:** [26 January 2024 01:25 UTC](https://forum.confluent.io/t/can-i-horizontally-scale-mqtt-kafka-source-connector/9928 "2024-01-26T01:25:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![k2sebeom](https://avatars.discourse-cdn.com/v4/letter/k/d26b3c/32.png) [@k2sebeom](https://forum.confluent.io/u/k2sebeom)\
**Post date:** [26 January 2024 01:25 UTC](https://forum.confluent.io/t/can-i-horizontally-scale-mqtt-kafka-source-connector/9928/1 "2024-01-26T01:25:19Z")

</div>

I have my IoT devices to send messages to a MQTT broker cluster. I am planning to streamline packets from mqtt brokers to kafka brokers and thinking of utilizing Kafka Connect MQTT source connector. Yet, almost all references I found on the usage of mqtt connector use single connector with max.Tasks=1, meaning that there is only one task subscribing to the topic. Yet, when message throughput is high on a single topic, I think scaling out connector tasks is a nice approach, but simply spawning more tasks will result in redundant messages since tasks subscribing to the same topic will all get the messages from the broker cluster.

Now I am curious what the best practice for ingesting mqtt messages to kafka brokers in a scalable fashion.

---

<div class="post-metadata">

**Author:** ![dtroiano](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/dtroiano/32/1961_2.png) [@dtroiano](https://forum.confluent.io/u/dtroiano)\
**Post date:** [26 January 2024 19:07 UTC](https://forum.confluent.io/t/can-i-horizontally-scale-mqtt-kafka-source-connector/9928/2 "2024-01-26T19:07:00Z")

</div>

Can you take advantage of hierarchy to have multiple `mqtt.topics` values? The connector supports single and multiple level wildcards (`+` and `#` respectively). If you’re able to use wildcards to cover the space of the one topic with multiple `mqtt.topics` values, then you can scale up to as many _active_ tasks as there are comma-separated values.

> [@k2sebeom](#):
>
> simply spawning more tasks will result in redundant messages since tasks subscribing to the same topic will all get the messages from the broker cluster.

This isn’t correct – the connector assigns tasks by mapping the comma-separated values in `mqtt.topics` to tasks, and there’s no overlap of assignments. Each value only goes to one task as described [here](https://docs.confluent.io/kafka-connectors/mqtt/current/mqtt-source-connector/overview.html#at-least-once-delivery). As those docs say, though, the connector _may_ output duplicates since it offers at least once delivery; just keep in mind that those dupes aren’t because the same topic gets subscribed by multiple tasks.

---

<div class="post-metadata">

**Author:** ![k2sebeom](https://avatars.discourse-cdn.com/v4/letter/k/d26b3c/32.png) [@k2sebeom](https://forum.confluent.io/u/k2sebeom)\
**Post date:** [29 January 2024 02:13 UTC](https://forum.confluent.io/t/can-i-horizontally-scale-mqtt-kafka-source-connector/9928/3 "2024-01-29T02:13:16Z")

</div>

Thanks for the information. This is very useful.  
So can I just assume that one topic (either wildcard or single) is assigned per task by default? What would be the best approach to increase throughput on one topic then?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/confluentcommunity/original/1X/c49438c90c9df282e9996fdf6971be890c71b65a.svg) [@system](https://forum.confluent.io/u/system)\
**Post date:** [28 February 2024 02:13 UTC](https://forum.confluent.io/t/can-i-horizontally-scale-mqtt-kafka-source-connector/9928/4 "2024-02-28T02:13:20Z")

</div>

Closed on 28 February 2024 02:13 UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
