KonstantinCodes / messenger-kafka

Simple Kafka transport for Symfony Messenger.
MIT License
84 stars 35 forks source link

Signal critical errors back to the application. #33

Open jbouzekri opened 3 years ago

jbouzekri commented 3 years ago

I made an error in my hostname but the process keep going without exiting so I was not aware I made this error. Librdkafka just logs messages without raising an error :

%3|1622636859.368|FAIL|rdkafka#consumer-1| [thrd:kafka:19092/bootstrap]: kafka:19092/bootstrap: Failed to resolve 'kafka:19092': Name does not resolve (after 2ms in state CONNECT)
%3|1622636859.368|ERROR|rdkafka#consumer-1| [thrd:kafka:19092/bootstrap]: kafka:19092/bootstrap: Failed to resolve 'kafka:19092': Name does not resolve (after 2ms in state CONNECT)
%3|1622636859.368|ERROR|rdkafka#consumer-1| [thrd:kafka:19092/bootstrap]: 1/1 brokers are down

The KafkaConf object should implements the setErrorCb method to raise Exception on blocking ones.

https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/rdkafka-conf.seterrorcb.html

Example :

// In KafkaTransportFactory method createTransport        
$conf->setErrorCb(function ($kafka, $err, $reason) {
    dump(rd_kafka_err2str($err));
    dump($err);
    dump($reason);
});

Outputs for the same error previously :

^ "Local: Host resolution failure"
^ -193
^ "kafka:19092/bootstrap: Failed to resolve 'kafka:19092': Name does not resolve (after 3ms in state CONNECT)"

^ "Local: All broker connections are down"
^ -187
^ "1/1 brokers are down"

I think a simple switch case on blocking error code and a raised Exception should do the trick like you did for the rebalanceCb