Set up Redpanda with the Aspire integration

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

⭐ Community Toolkit

Use the Redpanda hosting integration to model a Kafka-compatible broker in an Aspire AppHost. For an introduction, see Get started with Redpanda integration.

Aspire CLI — CommunityToolkit.Aspire.Hosting.RedPanda Paket hinzufügen
aspire add communitytoolkit-redpanda

Die Aspire CLI ist interaktiv; das passende Suchergebnis wählen, wenn gefragt:

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

The resource exposes the kafka endpoint for host connections and an internal endpoint for container-to-container traffic. It also exposes the Schema Registry and Admin API. Aspire assigns a host port for the Kafka endpoint unless you pin one with the port argument.

Redpanda defaults to one CPU and 1G of memory. Use the C# options callback to change these values:

AppHost.cs
var redpanda = builder.AddRedPanda("redpanda", options =>
{
options.CpuCount = 2;
options.Memory = "2G";
});

Set the broker’s host port in TypeScript with addRedPanda('redpanda', { port: 9092 }). The TypeScript API does not expose the resource sizing callback.

Use a data volume or bind mount to persist broker state across container restarts:

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

Use either Redpanda Console or Kafka UI. The integration connects each UI to the broker and its Schema Registry.

apphost.mts
const redpanda = await builder.addRedPanda('redpanda');
await redpanda.withConsole({
configureContainer: async (console) => {
await console.withHostPort({ port: 8080 });
},
});
// Or use Kafka UI:
const redpandaWithKafkaUi = await builder.addRedPanda('redpanda-ui');
await redpandaWithKafkaUi.withKafkaUI();

The TypeScript withHostPort export targets Redpanda Console. C# also supports a Kafka UI-specific WithHostPort overload; the TypeScript API can start Kafka UI but cannot pin its host port.

MethodPurpose
AddRedPanda / addRedPandaAdd a broker, optionally specifying its Kafka host port.
WithDataVolume / withDataVolumePersist broker state in a volume.
WithDataBindMount / withDataBindMountPersist broker state in a host directory.
WithConsole / withConsoleAdd Redpanda Console.
WithKafkaUI / withKafkaUIAdd the Kafka UI container.
WithHostPort / withHostPortSet Redpanda Console’s host port. C# also supports setting the Kafka UI host port.