PHPackages                             vs-point/messenger-transport-mqtt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. vs-point/messenger-transport-mqtt

ActiveLibrary[HTTP &amp; Networking](/categories/http)

vs-point/messenger-transport-mqtt
=================================

Symfony Messenger transport for the MQTT.

1.0.1(1mo ago)81283MITPHPPHP &gt;=8.2CI passing

Since Jul 2Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/vs-point/messenger-transport-mqtt)[ Packagist](https://packagist.org/packages/vs-point/messenger-transport-mqtt)[ Docs](https://github.com/vs-point/messenger-transport-mqtt)[ RSS](/packages/vs-point-messenger-transport-mqtt/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

MQTT Transport for Symfony Messenger
====================================

[](#mqtt-transport-for-symfony-messenger)

[![Latest Stable Version](https://camo.githubusercontent.com/1efce9c6157c3b2a2c1aa6d200d9b892111d4d6bd411de6bf1f214dc9372c6bc/68747470733a2f2f706f7365722e707567782e6f72672f76732d706f696e742f6d657373656e6765722d7472616e73706f72742d6d7174742f76657273696f6e)](https://packagist.org/packages/vs-point/messenger-transport-mqtt)[![Total Downloads](https://camo.githubusercontent.com/250506257682215d37d23669797bbe8708f63fc12b8085517db484df19c95e42/68747470733a2f2f706f7365722e707567782e6f72672f76732d706f696e742f6d657373656e6765722d7472616e73706f72742d6d7174742f646f776e6c6f616473)](https://packagist.org/packages/vs-point/messenger-transport-mqtt)[![License](https://camo.githubusercontent.com/44ac027fd38ff53f6132881bd03de9894faecc6a81d6fabae4b80a98f4cf6374/68747470733a2f2f706f7365722e707567782e6f72672f76732d706f696e742f6d657373656e6765722d7472616e73706f72742d6d7174742f6c6963656e7365)](https://packagist.org/packages/vs-point/messenger-transport-mqtt)

Symfony Messenger transport for MQTT, built on top of [php-mqtt/client](https://github.com/php-mqtt/client).

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Symfony Messenger ^7.0 | ^8.0
- A running MQTT broker (e.g. [Eclipse Mosquitto](https://mosquitto.org))

Installation
------------

[](#installation)

```
composer require vs-point/messenger-transport-mqtt
```

How it works
------------

[](#how-it-works)

**Sending:** any message class implementing `MqttMessageInterface` dispatched to the bus is published to the MQTT broker on the topic and with the QoS level returned by the message. Messages with QoS &gt; 0 wait up to 300 ms for the broker acknowledgment before returning.

**Receiving:** the Messenger worker calls `get()` in a loop. Each call opens a 100 ms non-blocking poll against the broker and returns all messages that arrived during that window as `MqttMessage` envelopes. Subscribed topics are configured on the transport factory and established on the first `get()` call. All subscriptions use QoS 0.

`ack()` and `reject()` are no-ops — delivery guarantees are handled at the MQTT protocol level via QoS.

Configuration
-------------

[](#configuration)

### 1. Register the transport factory

[](#1-register-the-transport-factory)

```
# config/services.yaml
VSPoint\Messenger\Transport\Mqtt\MqttTransportFactory:
    arguments:
        $topics: ['/sensors/#', '/commands/+']
        $clientId: '%env(MQTT_CLIENT_ID)%'
    tags: ['messenger.transport_factory']
```

`$topics` — list of MQTT topic filters the worker subscribes to. Wildcards (`#`, `+`) are supported.
`$clientId` — optional; defaults to the current process ID.

### 2. Configure the transport

[](#2-configure-the-transport)

```
# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            mqtt: '%env(MESSENGER_MQTT_TRANSPORT_DSN)%'

        routing:
            App\Message\SensorReading: mqtt
```

### 3. Environment variables

[](#3-environment-variables)

```
# .env
MESSENGER_MQTT_TRANSPORT_DSN=mqtt://user:pass@broker.example.com:1883
MQTT_CLIENT_ID=my-app-worker
```

Omit credentials for brokers that allow anonymous connections:

```
MESSENGER_MQTT_TRANSPORT_DSN=mqtt://broker.example.com:1883
```

Usage
-----

[](#usage)

### Sending a message

[](#sending-a-message)

Implement `MqttMessageInterface` in your message class to control the topic, QoS level, and payload:

```
