Samples
Short, runnable examples that demonstrate core Silverback concepts and common integration scenarios. Each sample consists of a producer and a consumer application (plus a common project, where the message contract is shared) and focuses on a single feature.
The source code of all samples is available in the samples folder of the repository, grouped into the Silverback.Samples.slnx solution.
Running the Samples
Prerequisites
- The .NET SDK version pinned in the repository's
global.json. - Docker, to run the message brokers locally.
Starting the Infrastructure
The docker-compose.yaml file in the repository root starts everything the samples need: a two-node Kafka cluster (reachable at localhost:19092 and localhost:29092), the Confluent schema registry (localhost:8081) and an EMQX MQTT cluster behind HAProxy (localhost:1883).
docker compose up -d
Tip
The compose file also starts some web UIs that help to inspect what's going on, like Conduktor for Kafka (http://localhost:8080) and the EMQX dashboard (http://localhost:18083). The credentials are listed in the comments at the top of the compose file.
Running a Sample
Run the producer and the consumer in two separate terminals, from the repository root. For example, for the basic Kafka sample:
dotnet run --project ./samples/Kafka/Basic.Producer/.
dotnet run --project ./samples/Kafka/Basic.Consumer/.
Then observe the console output while the messages are produced and consumed. Each sample page lists the exact commands and any additional step.
Kafka Samples
The simplest possible producer and consumer, with an error policy.
Kafka – Batch ProcessingPublish messages in batch and consume them in batches of up to 100 messages.
Kafka – Batch with TombstonesProduce tombstones within a batch and tell them apart while consuming in batch.
Kafka – File StreamingStream large binary files through Kafka, split into chunks.
Kafka – AvroSerialize the messages as Avro using the Confluent schema registry.
Kafka – JSON with Schema RegistrySerialize the messages as JSON, validated against a schema in the schema registry.
Kafka – Transactional ProducerProduce messages atomically with Kafka transactions, committing or aborting them.