# How to read Kafka message key in Stored Procedure

**URL:** <https://www.singlestore.com/forum/t/how-to-read-kafka-message-key-in-stored-procedure/1872>\
**Category:** Connectors and Pipelines\
**Created:** [April 24, 2020, 3:45pm UTC](https://www.singlestore.com/forum/t/how-to-read-kafka-message-key-in-stored-procedure/1872 "2020-04-24T15:45:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anilee.tech](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@anilee.tech](https://www.singlestore.com/forum/u/anilee.tech)\
**Post date:** [April 24, 2020, 3:45pm UTC](https://www.singlestore.com/forum/t/how-to-read-kafka-message-key-in-stored-procedure/1872/1 "2020-04-24T15:45:00Z")

</div>

Hi,  
I am workin on a CDC solution wherein I am receiving CDC events from my source database into Kafka. I have created pipeline to consume CDC events from Kafka and was able to insert/update records in MemSQL however for delete events, Kafka message is null so I think I have to use Kafka message key to delete the record from MemSQL table.

Is there an example on how can I read message key assuming I need to implement this CDC through Stored Procedure as pipeline into table option doesn’t seem to have an option to indicate on null value delete record based on message key.

---

<div class="post-metadata">

**Author:** ![nikita](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/n/a8b319/32.png) [@nikita](https://www.singlestore.com/forum/u/nikita)\
**Post date:** [April 24, 2020, 3:56pm UTC](https://www.singlestore.com/forum/t/how-to-read-kafka-message-key-in-stored-procedure/1872/2 "2020-04-24T15:56:10Z")

</div>

What CDC tool are you using to push messages into Kafka?

---

<div class="post-metadata">

**Author:** ![anilee.tech](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@anilee.tech](https://www.singlestore.com/forum/u/anilee.tech)\
**Post date:** [April 24, 2020, 3:59pm UTC](https://www.singlestore.com/forum/t/how-to-read-kafka-message-key-in-stored-procedure/1872/3 "2020-04-24T15:59:24Z")

</div>

IBM infosphere CDC Engine

---

<div class="post-metadata">

**Author:** ![sasha](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@sasha](https://www.singlestore.com/forum/u/sasha)\
**Post date:** [April 24, 2020, 11:59pm UTC](https://www.singlestore.com/forum/t/how-to-read-kafka-message-key-in-stored-procedure/1872/4 "2020-04-24T23:59:57Z")

</div>

We currently don’t expose the Kafka key in pipelines logic, though we do in fact plan to support this.

The best workaround for now is to copy the key into the message for deletes. I’m not personally familiar with InfoSphere, but it does look like it’s at least feasible to customize the message format with a “custom operation processor”:

> **[Kafka custom operation processor (KCOP) for the CDC Replication Engine for Kafka](https://www.ibm.com/docs/en/idr/11.4.0?topic=crek-kafka-custom-operation-processor-kcop-cdc-replication-engine-kafka)**
>
> By configuring a Kafka custom operation processor (KCOP), you can control the Kafka producer records that the CDC Replication Engine for Kafka writes.

---

<div class="post-metadata">

**Author:** ![mike.lantink](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/m/dec6dc/32.png) [@mike.lantink](https://www.singlestore.com/forum/u/mike.lantink)\
**Post date:** [May 5, 2020, 7:04pm UTC](https://www.singlestore.com/forum/t/how-to-read-kafka-message-key-in-stored-procedure/1872/5 "2020-05-05T19:04:20Z")

</div>

Yes this seems to be a feature request. It really matters where we have transit costs from third party brokers where we have to additionally embed the key info into the message which causes a large increase in the size of the message.

---

<div class="post-metadata">

**Author:** ![anilee.tech](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@anilee.tech](https://www.singlestore.com/forum/u/anilee.tech)\
**Post date:** [June 23, 2020, 3:32pm UTC](https://www.singlestore.com/forum/t/how-to-read-kafka-message-key-in-stored-procedure/1872/6 "2020-06-23T15:32:20Z")

</div>

Hi Sasha,  
Although, it is possible to code a KCOP and get message key populated within the message. This isn’t feasible.

1. This will impact existing subscribers to Kafka topics
2. I agree with Mike’s comment, embedding message key into the message causes large increase in the size of the message

I think this should be a new feature request for MemSQL pipelines to support Kafka null messages. If this can be supported with load table option that would be even better since I do not need to develop stored procedure for majority of use cases. An option in the pipeline to indicate delete records from table when message is null using message key.
