Schema Validation with Pyflink and Kafka’s Schema Registry

I was able register my expected schema for the Kafka topic for the records arriving using the below command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json"
--data '{"schema": "{"type":"record","name":"UserData","namespace":"io.confluent.examples.clients.basicavro","fields":[{"name":"user_id","type":"int"},{"name":"transaction_timestamp_millis","type":"double"},{"name":"amount","type":"double"},{"name":"currency","type":"string"},{"name":"counterpart_id","type":"int"}]}"}'
http://localhost:8081/subjects/user-data/versions
</code>
<code>curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "{"type":"record","name":"UserData","namespace":"io.confluent.examples.clients.basicavro","fields":[{"name":"user_id","type":"int"},{"name":"transaction_timestamp_millis","type":"double"},{"name":"amount","type":"double"},{"name":"currency","type":"string"},{"name":"counterpart_id","type":"int"}]}"}' http://localhost:8081/subjects/user-data/versions </code>
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" 
  --data '{"schema": "{"type":"record","name":"UserData","namespace":"io.confluent.examples.clients.basicavro","fields":[{"name":"user_id","type":"int"},{"name":"transaction_timestamp_millis","type":"double"},{"name":"amount","type":"double"},{"name":"currency","type":"string"},{"name":"counterpart_id","type":"int"}]}"}' 
  http://localhost:8081/subjects/user-data/versions  

Now, I am trying to validate the incoming record values with the already registered schema. So, I tried this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json"
--data '{"schema": "{"type":"record","name":"UserData","namespace":"io.confluent.examples.clients.basicavro","fields":[{"name":"user_id","type":"float"},{"name":"transaction_timestamp_millis","type":"double"},{"name":"amount","type":"double"},{"name":"currency","type":"string"},{"name":"counterpart_id","type":"int"}]}"}'
http://localhost:8081/compatibility/subjects/user-data/versions/latest
</code>
<code>curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "{"type":"record","name":"UserData","namespace":"io.confluent.examples.clients.basicavro","fields":[{"name":"user_id","type":"float"},{"name":"transaction_timestamp_millis","type":"double"},{"name":"amount","type":"double"},{"name":"currency","type":"string"},{"name":"counterpart_id","type":"int"}]}"}' http://localhost:8081/compatibility/subjects/user-data/versions/latest </code>
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" 
  --data '{"schema": "{"type":"record","name":"UserData","namespace":"io.confluent.examples.clients.basicavro","fields":[{"name":"user_id","type":"float"},{"name":"transaction_timestamp_millis","type":"double"},{"name":"amount","type":"double"},{"name":"currency","type":"string"},{"name":"counterpart_id","type":"int"}]}"}' 
  http://localhost:8081/compatibility/subjects/user-data/versions/latest

But it gives me the below response:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{"is_compatible":true}
</code>
<code>{"is_compatible":true} </code>
{"is_compatible":true}  

I was expecting it as false since the data type for the user_id field passed in the new request is float but I was expecting it to be int.

But since I want to validate my incoming record for the expected schema so I tried second approach and referred to this link

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>docker exec -it 5a7990c6f769 kafka-topics --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic lets-tests --config confluent.value.schema.validation=true --config confluent.value.subject.name.strategy=io.confluent.kafka.serializers.subject.user-data
</code>
<code>docker exec -it 5a7990c6f769 kafka-topics --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic lets-tests --config confluent.value.schema.validation=true --config confluent.value.subject.name.strategy=io.confluent.kafka.serializers.subject.user-data </code>
docker exec -it 5a7990c6f769 kafka-topics --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic lets-tests --config confluent.value.schema.validation=true --config confluent.value.subject.name.strategy=io.confluent.kafka.serializers.subject.user-data

But it gives me the below error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Error while executing topic command : The server experienced an unexpected error when processing the request.
[2024-04-27 06:51:34,766] ERROR org.apache.kafka.common.errors.UnknownServerException: The server experienced an unexpected error when processing the request.
(kafka.admin.TopicCommand$)
</code>
<code>Error while executing topic command : The server experienced an unexpected error when processing the request. [2024-04-27 06:51:34,766] ERROR org.apache.kafka.common.errors.UnknownServerException: The server experienced an unexpected error when processing the request. (kafka.admin.TopicCommand$) </code>
Error while executing topic command : The server experienced an unexpected error when processing the request.
[2024-04-27 06:51:34,766] ERROR org.apache.kafka.common.errors.UnknownServerException: The server experienced an unexpected error when processing the request.
 (kafka.admin.TopicCommand$)

I have ensured that all the services are up and running except ksql and relevant services.

Also, my expectation is I don’t want to terminate my producer session if the incoming record is not as per the expectation. Since I am using PyFlink, I was planning to park such records aside and send them to another topic that can be evaluated later.

So where am I going wrong? What could be the best way here? Any help is much appreciated. TIA

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật