Watch Aspire live streamsDocumentaciónPrueba Aspire

Set up Mosquitto with the Aspire integration

Esta página aún no está disponible en tu idioma.

⭐ Community Toolkit

Use the Mosquitto hosting integration to run Eclipse Mosquitto as an Aspire container resource. For a short introduction, see Get started with the Mosquitto integration.

Aspire CLI — Añadir paquete CommunityToolkit.Aspire.Hosting.Mosquitto
aspire add communitytoolkit-mosquitto

La CLI de Aspire es interactiva; asegúrate de seleccionar el resultado adecuado cuando se te pida:

Aspire CLI — Ejemplo de salida
Select an integration to add:
> communitytoolkit-mosquitto (CommunityToolkit.Aspire.Hosting.Mosquitto)
> Other results listed as selectable options...
apphost.mts
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const mqtt = await builder.addMosquitto('mqtt');
const api = await builder.addProject('api', '../Api/Api.csproj');
await api.withReference(mqtt);
await api.waitFor(mqtt);
await builder.build().run();

The resource exposes the MQTT protocol endpoint on container port 1883. Aspire assigns a host port unless you specify port. The generated connection string uses mqtt://host:port. The integration’s health check attempts an MQTT connection and reports healthy only after the broker accepts it.

The container stores state under /mosquitto/data. A volume preserves it independently of the container. A bind mount makes the files accessible from the host.

apphost.mts
const mqtt = await builder.addMosquitto('mqtt');
await mqtt.withDataVolume();
// Or use a host directory:
// await mqtt.withDataBindMount('./mosquitto-data');

The default mosquitto.conf listens on port 1883, permits anonymous connections, and persists state under /mosquitto/data. Replace it with a configuration appropriate to your environment by copying a local configuration directory into the container:

AppHost.cs
var mqtt = builder.AddMosquitto("mqtt")
.WithContainerFiles("/mosquitto/config", "./mosquitto-config");

Keep authentication and listener settings aligned with the applications that connect to the broker. The default anonymous configuration is intended for local development, not an exposed production broker.

MethodPurpose
AddMosquitto / addMosquittoAdd an MQTT broker, optionally pinning the host port.
WithDataVolume / withDataVolumePersist Mosquitto data in a named volume.
WithDataBindMount / withDataBindMountPersist Mosquitto data in a host directory.