Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mookid8000/topos
:cyclone: .NET Event Processing library
https://github.com/mookid8000/topos
azure-event-hubs azure-eventhub event-driven kafka kafka-consumer kafka-producer log-broker
Last synced: 2 months ago
JSON representation
:cyclone: .NET Event Processing library
- Host: GitHub
- URL: https://github.com/mookid8000/topos
- Owner: mookid8000
- License: mit
- Created: 2017-12-02T08:55:33.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T08:09:20.000Z (3 months ago)
- Last Synced: 2024-10-25T03:14:32.473Z (3 months ago)
- Topics: azure-event-hubs, azure-eventhub, event-driven, kafka, kafka-consumer, kafka-producer, log-broker
- Language: C#
- Homepage:
- Size: 5.17 MB
- Stars: 23
- Watchers: 6
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Topos
It's something with topics.
## Producing messages
Could e.g. be Apache Kafka, where we send a JSON-serialized message:
```csharp
var producer = Configure
.Producer(c => c.UseKafka("localhost:9092"))
.Serialization(s => s.UseNewtonsoftJson())
.Create();// keep producer instance for the entire life of your app,
// remembering to dispose it when we shut down
Using(producer);// send events like this:;
await producer.Send("someevents", new ToposMessage(new SomeEvent("This is just a message")), partitionKey: "customer-004");
```Let's go through the different configuration parts:
```csharp
// Topos configurations start with 'Configure.', no matter what you want to configure
var producer = Configure// we configure a producer that uses Kafka, seeding it with a couple of brokers
.Producer(c => c.UseKafka("kafkahost01:9092", "kafkahost02:9092"))// tell Topos to JSON-serialize messages
.Serialization(s => s.UseNewtonsoftJson())// creates the producer
.Create();
```## Consuming messages
Let's also use Kafka to consume messages... the configuration is probably not that surprising to you, it's
just `Configure.` and then let the fluent API guide you.Check this out - here we set up a corresponding consumer that just prints out the contents from the received messages:
```csharp
var consumer = Configure
.Consumer("default-group", c => c.UseKafka("kafkahost01:9092", "kafkahost02:9092"))
.Serialization(s => s.UseNewtonsoftJson())
.Topics(t => t.Subscribe("someevents"))
.Positions(p => p.StoreInMongoDb("mongodb://mongohost01/some_database", "Positions"))
.Handle(async (messages, context, token) =>
{
foreach (var message in messages)
{
switch (message.Body)
{
case SomeEvent someEvent:
Console.WriteLine($"Got some event: {someEvent}");
break;
}
}
})
.Start();// dispose consumer when you want to stop consuming messages
Using(consumer);
```Let's go through the configuration again:
```csharp
// start with 'Configure.'...
var consumer = Configure// configure a consumer instance as part of the group 'default-group', and use Kafka
.Consumer("default-group", c => c.UseKafka("kafkahost01:9092", "kafkahost02:9092"))// use JSON
.Serialization(s => s.UseNewtonsoftJson())// subscribe to 'someevents'
.Topics(t => t.Subscribe("someevents"))// store positions in MongoDB
.Positions(p => p.StoreInMongoDb("mongodb://mongohost01/some_database", "Positions"))// handle messages
.Handle(async (messages, context, token) =>
{
foreach (var message in messages)
{
switch (message.Body)
{
case SomeEvent someEvent:
Console.WriteLine($"Got some event: {someEvent}");
break;
}
}
})
.Start();
```