消息投递(从集群内)
从集群内使用生产者、消费者与 kafka 进行消息投递。
前提条件
-
已获取内部路由名称(
{Kafka 实例名称}-kafka-bootstrap
)。说明:平台为 Kafka 实例创建的内部路由中,带有
-bootstrap
标识的内部路由可用于消息投递,对应的9093
端口可用于集群内认证通信。 -
已获取实例下待使用的 Topic 名称。
操作步骤
listeners.tls | authentification.type | authorization.type |
---|---|---|
留空 | tls | simple |
-
使用 root 用户进入 Kafka 所在 Pod。
$ kubectl -n {命名空间名称} exec -ti {Pod 名称} bash
-
切换到相关目录。
$ cd /home/kafka/
-
运行客户端。
说明:创建 KafkaTopic 实例时若未设置 Topic Name,下述 Topic 名称 即 KafkaTopic 实例名称。
- 生产消息
$ /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server {Kafka 实例名称}-kafka-bootstrap:9093 --topic {Topic 名称} --producer.config ./client-ssl.properties OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N >hello1 >hello2 >hello3 >
-
消息消息
$ /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server {Kafka 实例名称}-kafka-bootstrap:9093 --topic {Topic 名称} --consumer.config ./client-ssl.properties --from-beginning --group my-group OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N hello1 hello2 hello3