# Message key is null

**URL:** <https://forum.confluent.io/t/message-key-is-null/1476>\
**Category:** Kafka Connect\
**Created:** [13 April 2021 15:27 UTC](https://forum.confluent.io/t/message-key-is-null/1476 "2021-04-13T15:27:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gpietro](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/gpietro/32/685_2.png) [@gpietro](https://forum.confluent.io/u/gpietro)\
**Post date:** [13 April 2021 15:27 UTC](https://forum.confluent.io/t/message-key-is-null/1476/1 "2021-04-13T15:27:27Z")

</div>

Hi,  
I created the following jdbc source connector for a mysql database:

```
{
  "name": "mysql-source-patients",
  "config": {
    "connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector",
    "connection.url": "jdbc:mysql://mysql:3306/admindb?characterEncoding=UTF-8&serverTimezone=UTC",
    "connection.user": "root",
    "connection.password": "rootpw",
    "table.whitelist": "patients",
    "mode": "timestamp+incrementing",
    "timestamp.column.name": "updated_at",
    "incrementing.column.name": "id",
    "topic.prefix": "mysql.admindb.",
    "tasks.max": "1",

    "_comment": "--- Add key to the message based on the entity id field ---",
    "transform": "createKey,extractId",
    "transforms.createKey.type": "org.apache.kafka.connect.transforms.ValueToKey",
    "transforms.createKey.fields": "id",
    "transforms.extractId.type": "org.apache.kafka.connect.transforms.ExtractField$Key",
    "transforms.extractId.field": "id"
  }
}

```

The connector seems to work fine since I see the db records into the ‘mysql.admindb.patients’ topic. The problem is that the key is always set to **null**.

By reading the [documentation](https://docs.confluent.io/kafka-connect-jdbc/current/source-connector/index.html), the properties needed to set the message key are “transforms.\*”.

Avro schema:

> {  
> “type”: “record”,  
> “name”: “Patient”,  
> “namespace”: “ch.demo.gpietro.schema”,  
> “fields”: [  
> {  
> “name”: “id”,  
> “type”: “long”  
> },  
> {  
> “name”: “created\_at”,  
> “type”: {  
> “type”: “long”,  
> “connect.version”: 1,  
> “connect.name”: “org.apache.kafka.connect.data.Timestamp”,  
> “logicalType”: “timestamp-millis”  
> }  
> },  
> {  
> “name”: “updated\_at”,  
> “type”: {  
> “type”: “long”,  
> “connect.version”: 1,  
> “connect.name”: “org.apache.kafka.connect.data.Timestamp”,  
> “logicalType”: “timestamp-millis”  
> }  
> },  
> {  
> “name”: “first\_name”,  
> “type”: “string”  
> },  
> {  
> “name”: “last\_name”,  
> “type”: “string”  
> },  
> {  
> “name”: “birth\_date”,  
> “type”: {  
> “type”: “long”,  
> “connect.version”: 1,  
> “connect.name”: “org.apache.kafka.connect.data.Timestamp”,  
> “logicalType”: “timestamp-millis”  
> }  
> }  
> ]  
> }

Topic output:

> ```
> ksql> print 'mysql.admindb.patients' from BEGINNING;
> Key format: ¯\_(ツ)_/¯ - no data processed
> Value format: AVRO
> rowtime: 2021/04/13 15:16:57.367 Z, key: <null>, value: {"id": 1, "birth_date": null, "created_at": 1618327013631, "first_name": "Pietro", "last_name": "Ghezzi", "updated_at": 1618327013631}
> 
> ```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![rmoff](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/rmoff/32/3_2.png) [@rmoff](https://forum.confluent.io/u/rmoff)\
**Post date:** [13 April 2021 15:57 UTC](https://forum.confluent.io/t/message-key-is-null/1476/2 "2021-04-13T15:57:11Z")

</div>

> [@gpietro](#):
>
> ```auto
> "transform": "createKey,extractId",
> 
> ```

You’re missing an `s` on `transform`. Try

```
"transforms": "createKey,extractId",

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/confluentcommunity/original/1X/c49438c90c9df282e9996fdf6971be890c71b65a.svg) [@system](https://forum.confluent.io/u/system)\
**Post date:** [20 April 2021 15:57 UTC](https://forum.confluent.io/t/message-key-is-null/1476/3 "2021-04-20T15:57:33Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
