haskell-works / hw-kafka-client

Kafka client for Haskell, including auto-rebalancing consumers
MIT License
139 stars 50 forks source link

Has `deliveryCallback` a wrong signature? #167

Closed Gau-thier closed 3 years ago

Gau-thier commented 3 years ago

Hello! We are using this awesome lib for a while now.

Context

I tried today to upgrade from 3.1.0 to 4.0.1 but I faced the following error on my project:

/src/Commons/Kafka/Producer.hs:56:23: error:
    • Couldn't match expected type ‘Callback’
                  with actual type ‘hw-kafka-client-4.0.1:Kafka.Internal.Setup.KafkaConf
                                    -> IO ()’
    • Probable cause: ‘deliveryCallback’ is applied to too few arguments
      In the first argument of ‘setCallback’, namely
        ‘(deliveryCallback (logError logState))’
      In the first argument of ‘(<>)’, namely
        ‘setCallback (deliveryCallback (logError logState))’
      In the second argument of ‘(<>)’, namely
        ‘setCallback (deliveryCallback (logError logState))
           <> setCallback (logCallback (handleLibrdkafkaLogs logState))’
   |
56 |       <> setCallback (deliveryCallback (logError logState))
   |

Research

I did some research on the documentation, but did not find anything interesting, so I took a look on the code.

Without success and the same error, I also tried:

setCallback (deliveryCallback print)

I found out this PR add the

newtype Callback = Callback (KafkaConf -> IO ())

But I also found out the deliveryCallback (that is leading to the previous error) still have the following signature:

deliveryCallback :: (DeliveryReport -> IO ()) -> KafkaConf -> IO ()

Conclusion

First, I really hope I did not miss anything in the documentation to upgrade from 3.1.2 to 4.0.1!

Is the Callback wrapper the real responsible of the error I am currently facing?

Bonus

I thought I would be able to fix this by myself, so in Kafka.Producer.Callbacks I tried:

deliveryCallback :: (DeliveryReport -> IO ()) -> Callback
deliveryCallback callback = Callback $ \kc -> rdKafkaConfSetDrMsgCb (getRdKafkaConf kc) realCb

But then I get stuck on Kafka.Producer (line122) when:

deliveryCallback (const mempty) kc

I am wondering if this is really necessary... Because in Kafka.Producer.ProducerProperties

setCallback :: Callback -> ProducerProperties
setCallback cb = mempty { ppCallbacks = [cb] }

I would be happy and proud if I was able to help this project!

Thanks again!

phile314 commented 3 years ago

Ah, my bad, forgot to update that callback. I think in Kafka.Producer one has to manually unpack the Callback newtype wrapper to make it work. I opened a PR for it: #168

Maybe you could give it a try?

Thanks for the nice bug report!

AlexeyRaga commented 3 years ago

v4.0.2 is on Hackage, thanks @gsebil08 and @phile314 ! :)