Search by

adachsoft / mqtt-adapter

Arkadiusz Adach

A PHP adapter that connects the AdachSoft MQTT contract to php-mqtt/client.

Package info

gitlab.com/a.adach/mqtt-adapter

Issues

pkg:composer/adachsoft/mqtt-adapter

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-08 08:35 UTC

This package is not auto-updated.

Last update: 2026-11-09 06:14:07 UTC


README

A PHP adapter that connects the transport-independent AdachSoft MQTT contract to php-mqtt/client.

Features

  • Provides the MqttClientInterface implementation through a public factory.
  • Supports raw and JSON message subscriptions, publishing, quality-of-service levels, and retained messages.
  • Accepts optional broker credentials and a PSR-3 logger.
  • Converts transport-client failures into the contract's MqttException.
  • Supports graceful event-loop interruption through system signals when pcntl is available.

Requirements

  • PHP 8.2 or later.
  • An MQTT broker reachable by the application.

Installation

composer require adachsoft/mqtt-adapter

Quick start

<?php

declare(strict_types=1);

use AdachSoft\Mqtt\Adapter\Factory\PhpMqttClientAdapterFactory;

require __DIR__ . '/vendor/autoload.php';

$client = (new PhpMqttClientAdapterFactory())->create(
    host: 'localhost',
    port: 1883,
    clientId: 'temperature-monitor',
);

$client->connect();
$client->initCntlSignal();
$client->subscribe('sensors/temperature', static function (string $topic, string $payload): void {
    printf("%s: %s\n", $topic, $payload);
}, qualityOfService: 1);

// The event loop runs until it is interrupted, for example by SIGINT.
$client->loop();
$client->close();

The factory also accepts optional username, password, and PSR-3 logger arguments. Use publish() to send a raw payload, or publishMessage() to publish a MessageVo from the contract package.

Examples

License

This package is distributed under the MIT license.