https://github.com/vs-point/messenger-transport-mqtt
Symfony Messenger transport for the MQTT.
https://github.com/vs-point/messenger-transport-mqtt
composer-package mqtt mqtt-client php symfony symfony-messenger
Last synced: 5 months ago
JSON representation
Symfony Messenger transport for the MQTT.
- Host: GitHub
- URL: https://github.com/vs-point/messenger-transport-mqtt
- Owner: vs-point
- License: mit
- Created: 2019-05-01T08:24:11.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-04T10:32:15.000Z (over 6 years ago)
- Last Synced: 2025-05-31T03:47:53.815Z (6 months ago)
- Topics: composer-package, mqtt, mqtt-client, php, symfony, symfony-messenger
- Language: PHP
- Homepage:
- Size: 18.6 KB
- Stars: 8
- Watchers: 2
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MQTT Transport for Symfony Messenger
[](https://packagist.org/packages/vs-point/messenger-transport-mqtt)
[](https://packagist.org/packages/vs-point/messenger-transport-mqtt)
[](https://packagist.org/packages/vs-point/messenger-transport-mqtt)
[](//packagist.org/packages/vs-point/messenger-transport-mqtt)
Extends the [Symfony Messenger](https://symfony.com/doc/master/components/messenger.html) component to
handle the MQTT transport.
## Install
```bash
composer require vs-point/messenger-transport-mqtt
```
### Install without the Symfony Bundle:
1. Register the transport factory:
```yaml
# config/services.yaml
VSPoint\Messenger\Transport\Mqtt\MqttTransportFactory:
arguments:
$topics: ['/topic1','/topic2']
$clientId: '%env(MQTT_CLIENT_ID)%'
tags: ['messenger.transport_factory']
```
2. Configure the MQTT transport:
```yaml
# config/packages/messenger.yaml
framework:
messenger:
transports:
mqtt: '%env(MESSENGER_MQTT_TRANSPORT_DSN)%'
routing:
# Route your messages to the transports
'*': mqtt
```
## Configuration
Example:
```bash
# .env
MESSENGER_MQTT_TRANSPORT_DSN=mqtt://user:pass@server:1883
MQTT_CLIENT_ID=symfonyclient
```
## Usage
```php
bus = $bus;
}
public function __invoke(string $section = 'ALL')
{
$this->bus->dispatch(new StateMessage($section, 'newState'));
}
}
```
```php
bus = $bus;
$this->router = $router;
$this->stateScenario = $stateScenario;
}
/**
* @Route("/state/{section}",
* name="change.state",
* requirements={"
* section"="all|a|b|c|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))"
* },
* defaults={"section": "all"})
*/
public function __invoke($section)
{
$stateScenario = $this->stateScenario;
$stateScenario($section);
return new RedirectResponse($this->router->generate('homepage'), 302);
}
}
```
```php
topic = '/state/'.$section;
$this->message = $state;
}
private $topic;
private $message;
public function getTopic(): string
{
return $this->topic;
}
public function getQos(): int
{
return 1;
}
public function getBody(): string
{
return $this->message;
}
}
```