1

I have a Kafka topic containing messages with an Avro-serialized key and Avro-serialized value.

I am trying to setup a sink connector to land these values into a table in a postgres database (AWS RDS in this case).

I have tried a number of variations on the topic, messages and sink config themselves, but looking at the following example, if someone could provide guidance on where I am going wrong, that would be great! :)

My topic has the following schema (in a schema registry)...

Key Schema

{
    "type": "record",
    "name": "TestTopicKey",
    "namespace": "test.messaging.avro",
    "doc": "Test key schema.",
    "fields": [
        {
            "name": "unitId",
            "type": "int"
        }
    ]
}

Value Schema

{
    "type": "record",
    "name": "TestTopicValues",
    "namespace": "test.messaging.avro",
    "doc": "Test value schema.",
    "fields": [
        {
            "name": "unitPrice",
            "type": "int",
            "doc": "Price in AUD excluding GST."
        },
        {
            "name": "unitDescription",
            "type": "string"
        }
    ]
}

I am manually producing records to the topic using the "kafka-avro-console-producer" as follows:

/bin/kafka-avro-console-producer --broker-list kafka-box-one:9092 --topic test.units --property parse.key=true --property "key.separator=|" --property "schema.registry.url=http://kafka-box-one:8081" --property key.schema='{"type":"record","name":"TestTopicKey","namespace":"test.messaging.avro","doc":"Test key schema.","fields":[{"name":"unitId","type":"int"}]}' --property value.schema='{"type":"record","name":"TestTopicValues","namespace":"test.messaging.avro","doc":"Test value schema.","fields":[{"name":"unitPrice","type":"int","doc":"Price in AUD excluding GST."},{"name":"unitDescription","type":"string"}]}'

Once that Producer starts I can then successfully add records to the topic as follows:

{"unitId":111}|{"unitPrice":15600,"unitDescription":"A large widget thingy."}

NB: I can also successfully consume with kafka-avro-console-consumer as expected.

The postgres table I am trying to Sink into looks like this:

CREATE TABLE test_area.unit_prices (
    unitId int4 NOT NULL,
    unitPrice int4 NULL,
    unitDescription text NULL,
    CONSTRAINT unit_prices_unitid_pk PRIMARY KEY (unitId)
);

My sink connector looks like this:

{
  "name": "test.area.unit.prices.v01",
  "config": {
      "connector.class": "JdbcSinkConnector",
      "topics": "test.units",
      "group.id": "test.area.unit.prices.v01",
      "key.converter": "io.confluent.connect.avro.AvroConverter",
      "key.converter.schema.registry.url": "http://kafka-box-one:8081",
      "value.converter": "io.confluent.connect.avro.AvroConverter",
      "value.converter.schema.registry.url": "http://kafka-box-one:8081",
      "connection.user": "KafkaSinkUser",
      "connection.password": "KafkaSinkPassword",
      "connection.url": "jdbc:postgresql://unit-catalogue.abcdefghij.my-region-1.rds.amazonaws.com:5432/unit_sales?currentSchema=test_area",
      "table.name.format": "unit_prices",
      "auto.create": false,
      "auto.evole": "false"
  }
}

My expectation is that records would appear in the postgres table shortly after the Sink is shown as running. However nothing is sinking.

Additional notes:

  • I can connect and write to the postgres RDS instance from the Kafka Connect box on which this Sink connector is being published with credentials as per the Sink connector using usql.
  • The sink connector status is "running" which suggests to me that there are no errors in the Sink syntax.
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Check your Kafka Connect worker log. Are there any errors there or warnings there? – Robin Moffatt Mar 27 '19 at 11:08
  • Thanks Robin, apologies for the belated reply. I have been having issues getting my logging to work so have been working blind. But through some Googling am finding that I think they need to be configured in my log4j properties. As soon as I get some logs working I will respond again. Stay tuned :) In the meantime, if yourself or someone can see anything wrong with my setup above, happy to try suggestions in parallel. – Stan Bridge Mar 28 '19 at 23:50
  • How are you running your Kafka Connect worker? If just from the command line then the logs are sent straight to the console (`stdout`) – Robin Moffatt Mar 29 '19 at 20:15
  • On the host that runs my Kafka Connectors, I am submitting my Kafka Connect job with a cURL command., eg: curl -X POST -H "Content-Type: application/json" --data @${mySinkJsonFile} http://localhost:8083/connectors (the Kafka topics themselves are on another host) The only feedback I get is the cURL comms timing etc stats. – Stan Bridge Apr 01 '19 at 03:04
  • That's _configuring_ Kafka Connect - when you _run_ Kafka Connect itself you launch the worker from the command line (or maybe run it from `confluent start`? or a systemd service?) – Robin Moffatt Apr 01 '19 at 04:42
  • By default, Connect starts from the latest offsets of your topic... It's not clear if data is actively produced after your first `console-producer` usage while Connect is running – OneCricketeer Apr 02 '19 at 21:45
  • This connect host was setup before my time, but it must start when the host (an AWS EC2) boots up. @RobinMoffatt I found your doco here on getting some logs happening: https://rmoff.net/2017/06/12/configuring-kafka-connect-to-log-rest-http-messages-to-a-separate-file/ Currently working through this to get a log happening. FYI... at present this connect box only has a generic log4j.properties in /mnt/kafka/etc/. Does not have a "connect-log4j.properties" as found with "ps -ef". Stay tuned for useful info. – Stan Bridge Apr 03 '19 at 00:10
  • @Cricket_007 Thanks... yes will try creating a whole new topic after fixing logging – Stan Bridge Apr 03 '19 at 00:10
  • You don't need a new topic... You can use `kafka-consumer-groups` to describe/reset the consumer group, if needed – OneCricketeer Apr 03 '19 at 19:02

1 Answers1

1

Apologies for the very belated reply on this one folks. After finally getting logs working, this was a proxy issue. Thankyou everyone for you assistance.