php-pubsub-kafka icon indicating copy to clipboard operation
php-pubsub-kafka copied to clipboard

Can't connect to anything other than localhost

Open evictor opened this issue 7 years ago • 7 comments

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.

evictor avatar Dec 09 '17 01:12 evictor

This is from this issue which I closed: https://github.com/Superbalist/laravel-pubsub/issues/15

evictor avatar Dec 09 '17 01:12 evictor

Taking a look.

zoidyzoidzoid avatar Dec 21 '17 13:12 zoidyzoidzoid

Is this for producing and consuming messages? Could you share the related config?

zoidyzoidzoid avatar Dec 21 '17 13:12 zoidyzoidzoid

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.

evictor avatar Dec 21 '17 22:12 evictor

Any updates on this?

drgomesp avatar Jul 10 '18 15:07 drgomesp

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');

zoidyzoidzoid avatar Jul 10 '18 15:07 zoidyzoidzoid

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.

drgomesp avatar Jul 12 '18 07:07 drgomesp