kafkaex/kafka_ex

Typespec for KafkaEx.Protocol.Produce.Message with optional :timestamp

esambo opened this issue · 0 comments

I am getting some typespec errors because Dialyzer doesn't like Message{timestamp: nil}. This timestamp was added as a required key. Shouldn't it be optional, so that it can be skipped as in the compression example, and not produce any dialyzer errors?

alias KafkaEx.Protocol.Produce.{Message, Request}
@type kafka_response ::
        nil
        | :ok
        | {:ok, integer()}
        | {:error, :closed}
        | {:error, :inet.posix()}
        | {:error, any()}
        | iodata()
        | :leader_not_available

@spec test :: kafka_response()
def test do
  %Message{
    key: "ID 1", value: "payload" #, timestamp: 666 # <== required to fix dialyzer error
  }
  |> produce_on_kafka()
end

@spec produce_on_kafka(Message.t()) :: kafka_response()
def produce_on_kafka(%Message{} = message) do
  %Request{
    topic: "test_topic",
    messages: [message]
  }
  |> KafkaEx.produce()
end