0

I am trying to produce messages in Avro format using AvroProducer class of confluent_kafka. Kafka and Schema-Registry run as cluster of 3 nodes in the same network.

I am reading the schema from string and initializing AvroProducer as below:

value_schema = loads("""{"doc": "Messages to be written.",
        "namespace": "schemas.avro",
        "type": "record",
        "name": "kafkagwo",
        "fields": [
            {"name": "timestamp", "type": "string"},
            {"name": "message", "type": "string"}
        ]}""")
key_schema = loads('{"type": "string"}')
p = AvroProducer({'bootstrap.servers': 'broker1,broker2,broker3',
                 'schema.registry.url': 'http://broker1:8081'})

Listener of schema-registry is set to http://localhost:8081 on side of schema registry server, that is broker1.

Then try to send messages using the code below

value = {'timestamp': timestamp, 'message': message}
p.produce(topic = 'topic-1', partition=0,
          key=str('key_0'),
          value=value, callback=delivery_report, 
          value_schema = value_schema, key_schema = key_schema)

What I get is

ConnectionError: HTTPConnectionPool(host='broker1', port=8081): Max retries exceeded with url: /subjects/topic-1-value/versions (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000165C1522D88>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))

I am not using Docker container. Clusters consist of 3 separate VMs where Kafka and Registry Schema are installed and run, so it's not standalone either. Python code is executed from a 4th VM that has Network access and firewall exception to it. In fact I am able to produce and consume messages without avro and registry schema, so I don't expect the issue to be related to networking but I am open to ideas. When I try to use Avro with Registry Schema, I get the above error. Also, error points out to Registry Schema port 8081 so the issue should be related to it, but I don't know what to look for furthermore.

meliksahturker
  • 922
  • 2
  • 11
  • 20
  • Can you edit your question to include details of where your Schema Registry is running relative to the python code? It looks like a networking issue. For example, do you have your Schema Registry running on the same machine as the broker? Are you using Docker? – Robin Moffatt Mar 17 '21 at 09:39
  • I edited the post with the details you asked. – meliksahturker Mar 17 '21 at 11:05

1 Answers1

0

Problem was due to schema-registry.properties file configuration. I had set listeners=http://localhost:8081 but this corresponds to 127.0.0.1 and is not open to access from another machine.

I changed it to listeners=http://0.0.0.0:8081 and it worked.

meliksahturker
  • 922
  • 2
  • 11
  • 20