apache / camel-kafka-connector-examples

Apache Camel Kafka Connector Examples
https://camel.apache.org
64 stars 43 forks source link

Add HTTP Connector Example #323

Closed kferrone closed 2 years ago

kferrone commented 2 years ago

I'm having a lot of trouble trying to figure out how to use the HTTP connector with an endpoint which needs a bearer token in the Authorization header. Please add some http examples using auth tokens

oscerd commented 2 years ago

You just need to send an header together with the payload to the sink connector. This header should be named "CamelHeader.Authorization" with the bearer token as value.

kferrone commented 2 years ago

Ok, so I am using the unofficial strimzi-cli here for local testing and Strimzi is running in kubernetes.

I made a file called producer.properties with the following on my local machine:

CamelHeader.Authorization=Bearer 123token456

Then I run this command to create a producer from the cli

kfk console-producer --topic my-topic -c my-cluster -n default --producer.config producer.properties

Then I paste the following:

{"message": "foo"}

I see my consumers do get the message including the connector. However I am still getting 403 back from the endpoint from within the sink connector. Did I even do what you are saying?

How to debug the actual request getting made to the endpoint? I want to see the headers, body and all.

I also get this warning when I open the producer terminal:

WARN The configuration 'CamelHeader.Authorization' was supplied but isn't a known config. (org.apache.kafka.clients.producer.ProducerConfig)
oscerd commented 2 years ago

I would use Kafkacat and add a

-H CamelHeader.Authorization="Bearer 123token456"

kferrone commented 2 years ago

Oh my hero! Kafkacat worked well for me. It looks like there is a bug in the Strimzi CLI. I was pulling my hair out. I'll let them know something isn't working right. Thanks.