728x90
반응형
Kafka SASL에 관한 정보는 구글링해도 잘 나온다.
하지만 세팅하는 부분은 생각보다 별로 없어서 여기 적어놔야겠다.
1. Kafka Broker Docker Compose
kafka:
image: bitnami/kafka:3.4
hostname: kafka
ports:
- 9092:9092
environment:
KAFKA_CLIENT_USERS: user
KAFKA_CLIENT_PASSWORDS: pass
ALLOW_PLAINTEXT_LISTENER: yes
KAFKA_BROKER_ID: 1
KAFKA_CFG_PROCESS_ROLES: broker,controller
KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_CFG_INTER_BROKER_LISTENER_NAME: CLIENT
KAFKA_CFG_LISTENERS: CONTROLLER://:9093,CLIENT://:9092
KAFKA_CFG_ADVERTISED_LISTENERS: CLIENT://host.docker.internal:9092
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,CLIENT:SASL_PLAINTEXT
KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL: PLAIN
KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093
KAFKA_CFG_DELETE_TOPIC_ENABLE: true
KAFKA_CFG_BROKER_ID: 1
KAFKA_CFG_NODE_ID: 1
KRAFT_MODE: true
KAFKA_ENABLE_KRAFT: yes
KAFKA_MESSAGE_MAX_BYTES: 2000000000
TZ: Asia/Seoul
volumes:
- ${KAFKA_DATA_DIR}:/bitnami/kafka/data
위와 같이 Users, Passwords를 추가해주고 ( 여러개여도 상관 없음. )
SASL에 관한 필드를 추가해준다.
2. Producer
kafka:
producer:
bootstrap-servers: host.docker.internal:9092
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
properties:
security.protocol: SASL_PLAINTEXT
sasl.mechanism: PLAIN
sasl.jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="user" password="pass!";
3. Consumer
kafka:
consumer:
bootstrap-servers: kafka:9092
auto-offset-reset: earliest
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
properties:
security.protocol: SASL_PLAINTEXT
sasl.mechanism: PLAIN
sasl.jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="user" password="pass!";
728x90
반응형
'Kafka' 카테고리의 다른 글
Kafka | Verify Server Connection (0) | 2024.02.22 |
---|