Kafka Transport?
I've noticed the absence of kafka as transport method. While this issue is also a request to perhaps support it, first I wanted to ask: Is kafka technically a viable transport for wolverine? My understanding is that I'd be ideal as not only it can forward messages to appropriate recipients, but also serve as database given how it's client's choice at which offset to start fetching messages from topic. But perhaps I'm missing a point on how a transport is supposed to work?
A Kafka transport is definitely planned, occasionally asked for, probably immediately valuable for Marten subscription support right after Wolverine 1.0, but mostly this:
Wanna volunteer? There actually was a Jasper (Wolverine's ancestor) transport for Kafka, and I think it would closely resemble the Pulsar transport in Wolverine today.
Kafka is definitely the missing piece for a lot of my work. A basic implementation based on the Pulsar stuff, like you suggested, would be a good start, and I even got a version of it somewhat working once, but the big requirement for me would be support for SchemaRegistry. The Confluent packages are ok for this, and I even wrote a quick abstraction around it a couple of years ago (it's in a private repo, but if it would be helpful, I could open it up, and even update it.). It supports Avro and Protobuf, because that's what we use, but would probably need to add the serdes for JsonSchema as well. As I recall, the Avro/Protobuf is super straight forward, but the JsonSchema stuff was a whole other world. Happy to share some code/what I've learned if the project gets this deep into it.
Edit: Looking at some old code, it's coming back to me. ;) The protobuf/avro serdes are from Confluent, and so have a ton of symmetry, but the JsonSchema stuff was very different. Here's a bit of a thing for doing Avro/Protobuf:
namespace KafkaProducers;
using Confluent.Kafka.SyncOverAsync;
using Confluent.SchemaRegistry;
using Confluent.SchemaRegistry.Serdes;
public class KafkaTypedProducer<TKey, TValue, TKeySerializer, TValueSerializer>
where TValue : IMessage<TValue>,new()
where TKey : IMessage<TKey>, new()
where TKeySerializer : IAsyncSerializer<TKey>
where TValueSerializer : IAsyncSerializer<TValue>
{
private readonly IProducer<TKey, TValue> _kafkaHandle;
private delegate ISerializer<TValue> SerializerValueFactory(CachedSchemaRegistryClient schemaRegistry);
private delegate ISerializer<TKey> SerializeKeyFactory
(CachedSchemaRegistryClient schemaRegistry);
private readonly Dictionary<Type, SerializerValueFactory> _valueConstructors = new()
{
{ typeof(ProtobufSerializer<TValue>), (s) => new ProtobufSerializer<TValue>(s).AsSyncOverAsync() },
{ typeof(AvroSerializer<TValue>), (s) => new AvroSerializer<TValue>(s).AsSyncOverAsync() },
};
private readonly Dictionary<Type, SerializeKeyFactory> _keyConstructors = new()
{
{ typeof(ProtobufSerializer<TKey>), (s) => new ProtobufSerializer<TKey>(s).AsSyncOverAsync() },
{ typeof(AvroSerializer<TKey>), (s) => new AvroSerializer<TKey>(s).AsSyncOverAsync() }
};
public KafkaTypedProducer(KafkaClientHandle handler, string registryUrl)
{
var schemaRegistryConfig = new SchemaRegistryConfig { Url = registryUrl };
var schemaRegistry = new CachedSchemaRegistryClient(schemaRegistryConfig);
var handleBuilder = new DependentProducerBuilder<TKey, TValue>(handler.Handle);
var keySerializer = _keyConstructors[typeof(TKeySerializer)](schemaRegistry);
var valueSerializer = _valueConstructors[typeof(TValueSerializer)](schemaRegistry);
handleBuilder.SetValueSerializer(valueSerializer);
handleBuilder.SetKeySerializer(keySerializer);
_kafkaHandle = handleBuilder.Build();
}
public Task ProduceAsync(string topic, Message<TKey, TValue> message) => _kafkaHandle.ProduceAsync(topic, message);
public void Produce(string topic, Message<TKey, TValue> message, Action<DeliveryReport<TKey, TValue>>? deliveryHandler = null) => _kafkaHandle.Produce(topic, message, deliveryHandler);
public void Flush(TimeSpan timeout)
=> _kafkaHandle.Flush(timeout);
}
@jeremydmiller adding it here as I didn't manage to get here after you've asked for input, but before you merged initial support (your work is just amazing).
Schema support - one of great benefits of Kafka is schema support - either JSON Schema or Avro (more standard). It would be really nice if Wolverine would support it.