Skip to content

Commit

Permalink
use simple http server when no auth
Browse files Browse the repository at this point in the history
  • Loading branch information
vdesabou committed Sep 7, 2023
1 parent 7b8c670 commit 6dd39f7
Show file tree
Hide file tree
Showing 18 changed files with 223 additions and 351 deletions.
116 changes: 5 additions & 111 deletions connect/connect-http-sink/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# HTTP Sink connector



## Objective

Quickly test [HTTP Sink](https://docs.confluent.io/current/connect/kafka-connect-http/index.html#kconnect-long-http-sink-connector) connector.

This is based on [Kafka Connect HTTP Connector Quick Start](https://docs.confluent.io/current/connect/kafka-connect-http/index.html#kconnect-long-http-connector-quick-start)

The HTTP service is using [vdesabou/kafka-connect-http-demo](https://github.com/vdesabou/kafka-connect-http-demo).
The HTTP service is using [vdesabou/kafka-connect-http-demo](https://github.com/vdesabou/kafka-connect-http-demo) when authentication is used, otherwise it use a simple http server where error code returned can be changed simply using:

Note: A great resource to test different HTTP status code is [http://httpstat.us](http://httpstat.us).
```bash
log "Set webserver to reply with 503"
curl -X PUT -H "Content-Type: application/json" --data '{"errorCode": 503}' http://localhost:9006
```

## How to run

Expand Down Expand Up @@ -43,111 +45,3 @@ $ playground run -f http_ssl_basic_auth<tab>
```bash
$ playground run -f http_mtls_auth<tab>
```

### JSON Converter Example

```bash
$ playground run -f http_json_basic_auth<tab>
```

Sending using:

```
docker exec -i broker kafka-console-producer --broker-list broker:9092 --topic json-topic << EOF
{"customer_name":"Ed", "complaint_type":"Dirty car", "trip_cost": 29.10, "new_customer": false, "number_of_rides": 22}
EOF
```

Json data:

```json
{
"customer_name": "Ed",
"complaint_type": "Dirty car",
"trip_cost": 29.1,
"new_customer": false,
"number_of_rides": 22
}
```

Getting:

```bash
curl admin:password@localhost:9083/api/messages | jq .
[
{
"id": 1,
"message": "[{\"complaint_type\":\"Dirty car\",\"new_customer\":false,\"trip_cost\":29.1,\"customer_name\":\"Ed\",\"number_of_rides\":22}]"
}
]
```
### AVRO Converter Example

```
$ playground run -f http_avro_basic_auth<tab>
```

Sending using:

```bash
playground topic produce -t avro-topic --nb-messages 10 --forced-value '{"f1":"value%g"}' << 'EOF'
{
"type": "record",
"name": "myrecord",
"fields": [
{
"name": "f1",
"type": "string"
}
]
}
EOF
```

Getting:

```
curl admin:password@localhost:9083/api/messages | jq .
[
{
"id": 1,
"message": "[{\"f1\":\"value1\"}]"
},
{
"id": 2,
"message": "[{\"f1\":\"value2\"}]"
},
{
"id": 3,
"message": "[{\"f1\":\"value3\"}]"
},
{
"id": 4,
"message": "[{\"f1\":\"value4\"}]"
},
{
"id": 5,
"message": "[{\"f1\":\"value5\"}]"
},
{
"id": 6,
"message": "[{\"f1\":\"value6\"}]"
},
{
"id": 7,
"message": "[{\"f1\":\"value7\"}]"
},
{
"id": 8,
"message": "[{\"f1\":\"value8\"}]"
},
{
"id": 9,
"message": "[{\"f1\":\"value9\"}]"
},
{
"id": 10,
"message": "[{\"f1\":\"value10\"}]"
}
]
```
75 changes: 75 additions & 0 deletions connect/connect-http-sink/docker-compose.plaintext copy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
version: '3.5'
services:

connect:
volumes:
- ../../connect/connect-http-sink/security:/tmp
- ../../connect/connect-http-sink/jcl-over-slf4j-2.0.7.jar:/usr/share/confluent-hub-components/confluentinc-kafka-connect-http/lib/jcl-over-slf4j-2.0.7.jar
environment:
CONNECT_PLUGIN_PATH: /usr/share/confluent-hub-components/confluentinc-kafka-connect-http

http-service-no-auth:
image: vdesabou/http-sink-demo # created from https://github.com/vdesabou/kafka-connect-http-demo with mvn clean install -DskipTests && docker build -t vdesabou/http-sink-demo:latest . && docker push vdesabou/http-sink-demo:latest
hostname: http-service-no-auth
container_name: http-service-no-auth
ports:
- "8080:8080"
environment:
SPRING_PROFILES_ACTIVE: 'simple-auth'

http-service-basic-auth:
image: vdesabou/http-sink-demo
hostname: http-service-basic-auth
container_name: http-service-basic-auth
ports:
- "9083:8080"
environment:
SPRING_PROFILES_ACTIVE: 'basic-auth'

# for testing error 500
http-service-no-auth-500:
image: vdesabou/http-service-no-auth-500
hostname: http-service-no-auth-500
container_name: http-service-no-auth-500
ports:
- "9082:8080"
environment:
SPRING_PROFILES_ACTIVE: 'simple-auth'

# for testing error 204
http-service-basic-auth-204:
image: vdesabou/http-sink-demo-error-204
hostname: http-service-basic-auth-204
container_name: http-service-basic-auth-204
ports:
- "9081:8080"
environment:
SPRING_PROFILES_ACTIVE: 'basic-auth'

http-service-oauth2-auth:
image: vdesabou/http-sink-demo
hostname: http-service-oauth2-auth
container_name: http-service-oauth2-auth
ports:
- "10080:8080"
environment:
SPRING_PROFILES_ACTIVE: 'oauth2'

http-service-ssl-basic-auth:
image: vdesabou/http-sink-demo
hostname: http-service-ssl-basic-auth
container_name: http-service-ssl-basic-auth
ports:
- "8443:8443"
environment:
SPRING_PROFILES_ACTIVE: 'ssl-basic-auth'

http-service-mtls-auth:
image: vdesabou/http-sink-demo
hostname: http-service-mtls-auth
container_name: http-service-mtls-auth
ports:
- "8643:8443"
environment:
SPRING_PROFILES_ACTIVE: 'ssl-auth'
19 changes: 19 additions & 0 deletions connect/connect-http-sink/docker-compose.plaintext.basic.auth.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: '3.5'
services:

connect:
volumes:
- ../../connect/connect-http-sink/security:/tmp
- ../../connect/connect-http-sink/jcl-over-slf4j-2.0.7.jar:/usr/share/confluent-hub-components/confluentinc-kafka-connect-http/lib/jcl-over-slf4j-2.0.7.jar
environment:
CONNECT_PLUGIN_PATH: /usr/share/confluent-hub-components/confluentinc-kafka-connect-http

http-service-basic-auth:
image: vdesabou/http-sink-demo
hostname: http-service-basic-auth
container_name: http-service-basic-auth
ports:
- "9083:8080"
environment:
SPRING_PROFILES_ACTIVE: 'basic-auth'
19 changes: 19 additions & 0 deletions connect/connect-http-sink/docker-compose.plaintext.mtls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: '3.5'
services:

connect:
volumes:
- ../../connect/connect-http-sink/security:/tmp
- ../../connect/connect-http-sink/jcl-over-slf4j-2.0.7.jar:/usr/share/confluent-hub-components/confluentinc-kafka-connect-http/lib/jcl-over-slf4j-2.0.7.jar
environment:
CONNECT_PLUGIN_PATH: /usr/share/confluent-hub-components/confluentinc-kafka-connect-http

http-service-mtls-auth:
image: vdesabou/http-sink-demo
hostname: http-service-mtls-auth
container_name: http-service-mtls-auth
ports:
- "8643:8443"
environment:
SPRING_PROFILES_ACTIVE: 'ssl-auth'
19 changes: 19 additions & 0 deletions connect/connect-http-sink/docker-compose.plaintext.oauth2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: '3.5'
services:

connect:
volumes:
- ../../connect/connect-http-sink/security:/tmp
- ../../connect/connect-http-sink/jcl-over-slf4j-2.0.7.jar:/usr/share/confluent-hub-components/confluentinc-kafka-connect-http/lib/jcl-over-slf4j-2.0.7.jar
environment:
CONNECT_PLUGIN_PATH: /usr/share/confluent-hub-components/confluentinc-kafka-connect-http

http-service-oauth2-auth:
image: vdesabou/http-sink-demo
hostname: http-service-oauth2-auth
container_name: http-service-oauth2-auth
ports:
- "10080:8080"
environment:
SPRING_PROFILES_ACTIVE: 'oauth2'
56 changes: 0 additions & 56 deletions connect/connect-http-sink/docker-compose.plaintext.proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ services:
CONNECT_PLUGIN_PATH: /usr/share/confluent-hub-components/confluentinc-kafka-connect-http
dns: 0.0.0.0

http-service-no-auth:
image: vdesabou/http-sink-demo # created from https://github.com/vdesabou/kafka-connect-http-demo with mvn clean install -DskipTests && docker build -t vdesabou/http-sink-demo:latest . && docker push vdesabou/http-sink-demo:latest
hostname: http-service-no-auth
container_name: http-service-no-auth
ports:
- "8080:8080"
environment:
SPRING_PROFILES_ACTIVE: 'simple-auth'

http-service-basic-auth:
image: vdesabou/http-sink-demo
hostname: http-service-basic-auth
Expand All @@ -36,50 +27,3 @@ services:
- "9083:8080"
environment:
SPRING_PROFILES_ACTIVE: 'basic-auth'

# for testing error 500
http-service-no-auth-500:
image: vdesabou/http-service-no-auth-500
hostname: http-service-no-auth-500
container_name: http-service-no-auth-500
ports:
- "9082:8080"
environment:
SPRING_PROFILES_ACTIVE: 'simple-auth'

# for testing error 204
http-service-basic-auth-204:
image: vdesabou/http-sink-demo-error-204
hostname: http-service-basic-auth-204
container_name: http-service-basic-auth-204
ports:
- "9081:8080"
environment:
SPRING_PROFILES_ACTIVE: 'basic-auth'

http-service-oauth2-auth:
image: vdesabou/http-sink-demo
hostname: http-service-oauth2-auth
container_name: http-service-oauth2-auth
ports:
- "10080:8080"
environment:
SPRING_PROFILES_ACTIVE: 'oauth2'

http-service-ssl-basic-auth:
image: vdesabou/http-sink-demo
hostname: http-service-ssl-basic-auth
container_name: http-service-ssl-basic-auth
ports:
- "8443:8443"
environment:
SPRING_PROFILES_ACTIVE: 'ssl-basic-auth'

http-service-mtls-auth:
image: vdesabou/http-sink-demo
hostname: http-service-mtls-auth
container_name: http-service-mtls-auth
ports:
- "8643:8443"
environment:
SPRING_PROFILES_ACTIVE: 'ssl-auth'
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: '3.5'
services:

connect:
volumes:
- ../../connect/connect-http-sink/security:/tmp
- ../../connect/connect-http-sink/jcl-over-slf4j-2.0.7.jar:/usr/share/confluent-hub-components/confluentinc-kafka-connect-http/lib/jcl-over-slf4j-2.0.7.jar
environment:
CONNECT_PLUGIN_PATH: /usr/share/confluent-hub-components/confluentinc-kafka-connect-http

http-service-ssl-basic-auth:
image: vdesabou/http-sink-demo
hostname: http-service-ssl-basic-auth
container_name: http-service-ssl-basic-auth
ports:
- "8443:8443"
environment:
SPRING_PROFILES_ACTIVE: 'ssl-basic-auth'
Loading

0 comments on commit 6dd39f7

Please sign in to comment.