I’m working on an application which utilizes Kafka as a message broker. I want to be able to test the application without having to have a Kafka broker online. How do I inject the Kafka code into my application such that I can replace it with an in-memory solution for my tests?
I have the interface boiled down to:
module type Broker : sig
type client
type message
type ack
val send_message : client -> string -> message -> ack Lwt.t
val listen : client -> string array -> ack Lwt.t
end
You’d want the pieces that interact with the broker to be implemented as functors that are then given a broker module. You can then have an in-memory broker or a kafka broker depending on your needs.