Skip to content

Latest commit

 

History

History

http.kafka.proto.oneway

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

http.kafka.proto.oneway

This example allows a protobuf object to be sent to a REST edpoint as JSON that gets validated and converted to the protobuf when it is produced onto Kafka.

Setup

To start the Docker Compose stack defined in the compose.yaml file, use:

docker compose up -d

Watch kafka

Open the Kafka UI or run the kafkacat command:

docker compose -p zilla-http-kafka-proto-oneway exec kafkacat \
    kafkacat -b kafka.examples.dev:29092 -C -f 'Key:Message | %k:%s\n Headers | %h \n\n' -t my-requests

Publish message with correct proto file

echo "message:'hello world',count:10" \
  | protoc  --encode Request ./request.proto \
  | curl -s --request POST http://localhost:7114/requests \
    --header "Content-Type: application/protobuf" \
    --data-binary @-

Block message with incorrect proto file

echo "message:'hello bad type',count:'ten'" \
  | protoc  --encode Request ./request_bad_type.proto \
  | curl -s --request POST http://localhost:7114/requests \
    --header "Content-Type: application/protobuf" \
    --data-binary @-
echo "message:'hello extra field',count:10,extra:'field'" \
  | protoc  --encode Request ./request_extra_field.proto \
  | curl -s --request POST http://localhost:7114/requests \
    --header "Content-Type: application/protobuf" \
    --data-binary @-
echo "message:'hello wrong order',count:10" \
  | protoc  --encode Request ./request_wrong_order.proto \
  | curl -s --request POST http://localhost:7114/requests \
    --header "Content-Type: application/protobuf" \
    --data-binary @-

Teardown

To remove any resources created by the Docker Compose stack, use:

docker compose down