MQTT library for Cumulocity IoT Custom Agents - Use case

Introduction to MQTT IoT Library

Cumulocity IoT Supports MQTT protocol. To connect the devices with Cumulocity usually, a device/gateway agent would be used. Internally these agent uses the MQTT library to connect with the Cumulocity platform and device management.

Available MQTT libraries

To connect with the Cumulocity Platform multiple MQTT libraries are available. These come with pros & cons. Based on the use cases & customer experience will analyze the best-fit library.

Opening many MQTT connections depends on the below variables

  • Maximum number of open-file supported in the host Machine / VM
  • Optimum CPU and RAM configuration of the host machine
  • Number of Concurrent MQTT connections allowed on the Cumulocity IoT Platform (Depends on the cumulocity deployment configurations)

Use case 1 - Less number of connection required (< 5K)

Library - Paho Java Library
If the requirement is to open a small number of MQTT connections with the Cumulocity platform than Paho Java client library could be used & works perfectly fine. Below find the pros & cons of this library.

Pros

  • Good with less number of connection management
  • Works well with the Cumulocity Platform
  • Provides other standard MQTT features (lightweight, high availability, reliability, persistence & Security TLS)
  • Supports both MQTT V3 & V5

Cons

  • If your requirement is to open more than 5K connection then it’s not a good choice
  • For every one TCP connection you open 3 more child threads will get created
  • There is a performance problem with the Paho Java library

Use case 2 - More connection required (> 5K)

If the requirement is to open more than 5K connections (like 40K / 50K) using the device/gateway agent then the below libraries could be your choice. Since the implementation was java bases so we selected hive java library and it worked well with our implementation. I was able to achieve 45K concurrent MQTT connection with my implementation.

Library - Hive Java Library (Community version)

Pros

  • Works well with a high number of concurrent MQTT connection
  • Better thread management & performance
  • Provides other standard MQTT features (lightweight, high availability, reliability, persistence & Security TLS)
  • Supports both MQTT V3 & V5

Note- Other library that could provide a better throughput (Library - C/C++ Paho library - not tested)

Available useful links - Eclipse Community Forums: Paho » Paho java client - cannot create more than 5000 connections

1 Like