Skip to main content

MQTT Client Configuration

As we have seen earlier, MqttClient requires an instance of MqttV3Configuration. MqttV3Configuration allows you to configure the following properties of MqttClient:

Required Configs

  • MqttPingSender : It is an implementation of MqttPingSender interface, which defines the logic of sending ping requests over the MQTT connection. Read more ping sender here.

  • Authenticator : MqttClient uses Authenticator to refresh the connect options when username or password are incorrect. Read more Authenticator here.

Optional Configs

  • Retry Policies : There are multiple retry policies used in Courier library - connect retry policy, connect timeout policy, subscription policy. You can either use the in-built policies or provide your own custom policies.

  • Logger : An instance of ILogger can be passed to get the internal logs.

  • Event Handler : EventHandler allows you to listen to all the library events like connect attempt/success/failure, message send/receive, subscribe/unsubscribe.

  • Mqtt Interceptors : By passing mqtt interceptors, you can intercept all the MQTT packets sent over the courier connection. This is also used for enabling MQTT Chuck.

  • Persistence Options : It allows you to configure message persistence and the offline buffer present inside Paho.

    • shouldUseMemoryPersistence : When enabled, it will use in-memory persistence to store inflight messages instead of the default disk-based persistence.
    • memoryPersistenceCapacity : Maximum number of entries Bounded Memory Persistence holds when the value > 0, otherwise fallbacks to the unbounded in-memory persistence. Once the limit is reached, new messages are either dropped or used to evict the oldest entry, depending on isDeleteOldestMessages.
    • bufferCapacity : Maximum number of messages the offline buffer can hold while the client is disconnected.
    • isPersistBuffer : When enabled, offline-buffered messages are also written through the active MqttClientPersistence (memory or disk). Disable this to store the messages only in offline buffer when the client is disconnected.
    • isDeleteOldestMessages : When the offline buffer or Bounded Memory Persistence is full, enabling this evicts the oldest entry to make room for the new one. When disabled, the offline buffer rejects the new message with an exception, while Bounded Memory Persistence silently drops it instead of throwing.
  • Experimentation Configs : These are the experiment configs used inside Courier library which are explained in detail here.

  • WakeLock Timeout : When positive value of this timeout is passed, a wakelock is acquired while creating the MQTT connection. By default, it is 0.