php-pubsub-kafka
php-pubsub-kafka copied to clipboard
Can't connect to anything other than localhost
In summary, I can't connect to a Kafka broker running on a host other than localhost. I can set up a SSH tunnel to tunnel 9092 traffic on the broker to localhost, then everything works fine.
This is not a firewall-related issue either as I can use the Kafka CLI tools to make the connection to that host directly.
I have checked that my configuration settings are getting into laravel-pubsub library but for some reason it always tries to connect to localhost, and then I see some errors like this:
%3|1512781383.226|FAIL|rdkafka#producer-1| [thrd:localhost:9092/0]: localhost:9092/0: Connect to ipv4#127.0.0.1:9092 failed: Connection refused
%3|1512781383.226|ERROR|rdkafka#producer-1| [thrd:localhost:9092/0]: localhost:9092/0: Connect to ipv4#127.0.0.1:9092 failed: Connection refused
%3|1512781383.228|FAIL|rdkafka#consumer-2| [thrd:localhost:9092/0]: localhost:9092/0: Connect to ipv4#127.0.0.1:9092 failed: Connection refused
%3|1512781383.228|ERROR|rdkafka#consumer-2| [thrd:localhost:9092/0]: localhost:9092/0: Connect to ipv4#127.0.0.1:9092 failed: Connection refused
Like I said, I checked and the configs for my custom host are getting where they should be.
This is from this issue which I closed: https://github.com/Superbalist/laravel-pubsub/issues/15
Taking a look.
Is this for producing and consuming messages? Could you share the related config?
For both. My going-forward solution is to have a tunnel kept alive using autossh for now, but my Laravel config looked something like this when I was attempting to connect directly (fake IP there):
<?php
return [
'default' => 'kafka',
'connections' => [
'kafka' => [
'driver' => 'kafka',
'consumer_group_id' => 'php-pubsub',
'brokers' => '1.2.3.4',
],
],
];
So despite sending 1.2.3.4 in, a connection would be attempted (for producing or consuming) to localhost.
Any updates on this?
Unfortunately I no longer work at the company that uses this library, but I don't think they use the Kafka driver at the moment.
@evictor What if you use the following?
$producer = new \RdKafka\Producer($conf);
$producer->addBrokers('127.0.0.1');
I managed to fix this issue. I was using localhost:9092 as, which doesn't work. Now, I'm connecting to PLAINTEXT://host.docker.internal:9092, where host.docker.internal is mapped from within the container to my host machine ip.