Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example HTTP clients with HTTP Bridge sidecar
###############
# Topic
###############
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaTopic
metadata:
name: my-topic
labels:
strimzi.io/cluster: my-cluster
spec:
partitions: 1
replicas: 1
---
###############
# Producer
###############
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaUser
metadata:
name: example-producer
labels:
strimzi.io/cluster: my-cluster
spec:
authentication:
type: tls
authorization:
type: simple
acls:
# Producer messages to topic my-topic
- resource:
type: topic
name: my-topic
patternType: literal
operation: Write
host: "*"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: producer-configuration
data:
bridge.properties: |
bridge.id=producer-sidecar
# HTTP related settings
http.enabled=true
http.host=127.0.0.1
http.port=8080
# Configuration Providers
kafka.config.providers=env
kafka.config.providers.env.class=io.strimzi.kafka.EnvVarConfigProvider
# General Kafka settings
kafka.bootstrap.servers=${env:BOOTSTRAP_SERVERS}
kafka.security.protocol=SSL
kafka.ssl.keystore.type=PEM
kafka.ssl.keystore.certificate.chain=${env:USER_CRT}
kafka.ssl.keystore.key=${env:USER_KEY}
kafka.ssl.truststore.type=PEM
kafka.ssl.truststore.certificates=${env:CA_CRT}
kafka.ssl.endpoint.identification.algorithm=HTTPS
# Kafka Producer options
kafka.producer.acks=1
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: example-producer
name: example-producer
spec:
replicas: 1
selector:
matchLabels:
app: example-producer
template:
metadata:
labels:
app: example-producer
spec:
containers:
- name: producer
image: quay.io/strimzi-examples/java-http-vertx-producer:latest
env:
- name: HOSTNAME
value: localhost
- name: PORT
value: "8080"
- name: TOPIC
value: my-topic
- name: SEND_INTERVAL
value: "1000"
- name: bridge
image: quay.io/strimzi/kafka-bridge:0.20.2
command: ["/opt/strimzi/bin/kafka_bridge_run.sh", "--config-file", "/etc/strimzi-bridge/bridge.properties"]
env:
- name: BOOTSTRAP_SERVERS
value: my-cluster-kafka-bootstrap:9093
- name: USER_CRT
valueFrom:
secretKeyRef:
name: example-producer
key: user.crt
- name: USER_KEY
valueFrom:
secretKeyRef:
name: example-producer
key: user.key
- name: CA_CRT
valueFrom:
secretKeyRef:
name: my-cluster-cluster-ca-cert
key: ca.crt
volumeMounts:
- name: producer-configuration
mountPath: /etc/strimzi-bridge
volumes:
- name: producer-configuration
configMap:
name: producer-configuration
---
###############
# Consumer
###############
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaUser
metadata:
name: example-consumer
labels:
strimzi.io/cluster: my-cluster
spec:
authentication:
type: tls
authorization:
type: simple
acls:
# Consume from topic my-topic using consumer group my-group
- resource:
type: topic
name: my-topic
patternType: literal
operation: Read
host: "*"
- resource:
type: group
name: example-group
patternType: literal
operation: Read
host: "*"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: consumer-configuration
data:
bridge.properties: |
bridge.id=consumer-sidecar
# HTTP related settings
http.enabled=true
http.host=127.0.0.1
http.port=8080
# Configuration Providers
kafka.config.providers=env
kafka.config.providers.env.class=io.strimzi.kafka.EnvVarConfigProvider
# General Kafka settings
kafka.bootstrap.servers=${env:BOOTSTRAP_SERVERS}
kafka.security.protocol=SSL
kafka.ssl.keystore.type=PEM
kafka.ssl.keystore.certificate.chain=${env:USER_CRT}
kafka.ssl.keystore.key=${env:USER_KEY}
kafka.ssl.truststore.type=PEM
kafka.ssl.truststore.certificates=${env:CA_CRT}
kafka.ssl.endpoint.identification.algorithm=HTTPS
# Kafka Consumer options
kafka.consumer.auto.offset.reset=earliest
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: example-consumer
name: example-consumer
spec:
replicas: 1
selector:
matchLabels:
app: example-consumer
template:
metadata:
labels:
app: example-consumer
spec:
containers:
- name: consumer
image: quay.io/strimzi-examples/java-http-vertx-consumer:latest
env:
- name: HOSTNAME
value: localhost
- name: PORT
value: "8080"
- name: TOPIC
value: my-topic
- name: CLIENTID
value: "example-consumer"
- name: GROUPID
value: "example-group"
- name: POLL_INTERVAL
value: "1000"
- name: bridge
image: quay.io/strimzi/kafka-bridge:0.20.2
command: ["/opt/strimzi/bin/kafka_bridge_run.sh", "--config-file", "/etc/strimzi-bridge/bridge.properties"]
env:
- name: BOOTSTRAP_SERVERS
value: my-cluster-kafka-bootstrap:9093
- name: USER_CRT
valueFrom:
secretKeyRef:
name: example-consumer
key: user.crt
- name: USER_KEY
valueFrom:
secretKeyRef:
name: example-consumer
key: user.key
- name: CA_CRT
valueFrom:
secretKeyRef:
name: my-cluster-cluster-ca-cert
key: ca.crt
volumeMounts:
- name: consumer-configuration
mountPath: /etc/strimzi-bridge
volumes:
- name: consumer-configuration
configMap:
name: consumer-configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment