Difference between revisions of "Kafka"
Jump to navigation
Jump to search
(Created page with "# Refs - https://www.confluent.io/blog/secure-kafka-deployment-best-practices/ - https://github.com/dpkp/kafka-python - https://kafka.apache.org/quickstart # Using http to in...") |
|||
| Line 7: | Line 7: | ||
- https://docs.confluent.io/3.0.0/kafka-rest/docs/intro.html#quickstart | - https://docs.confluent.io/3.0.0/kafka-rest/docs/intro.html#quickstart | ||
- front with ngninx | - front with ngninx | ||
| + | |||
| + | |||
| + | Python Kafka | ||
| + | |||
| + | https://python.plainenglish.io/how-to-programmatically-create-topics-in-kafka-using-python-d8a22590ecde | ||
| + | ``` | ||
| + | Using kafka-python | ||
| + | from kafka.admin import KafkaAdminClient, NewTopic | ||
| + | |||
| + | |||
| + | admin_client = KafkaAdminClient( | ||
| + | bootstrap_servers="localhost:9092", | ||
| + | client_id='test' | ||
| + | ) | ||
| + | |||
| + | topic_list = [] | ||
| + | topic_list.append(NewTopic(name="example_topic", num_partitions=1, replication_factor=1)) | ||
| + | admin_client.create_topics(new_topics=topic_list, validate_only=False) | ||
| + | Using confluent_kafka | ||
| + | from confluent_kafka.admin import AdminClient, NewTopic | ||
| + | |||
| + | |||
| + | admin_client = AdminClient({ | ||
| + | "bootstrap.servers": "localhost:9092" | ||
| + | }) | ||
| + | |||
| + | topic_list = [] | ||
| + | topic_list.append(NewTopic("example_topic", 1, 1)) | ||
| + | admin_client.create_topics(topic_list) | ||
| + | ``` | ||
Revision as of 19:04, 27 April 2021
Refs
- https://www.confluent.io/blog/secure-kafka-deployment-best-practices/
- https://github.com/dpkp/kafka-python
- https://kafka.apache.org/quickstart
Using http to interface
- https://docs.confluent.io/3.0.0/kafka-rest/docs/intro.html#quickstart
- front with ngninx
Python Kafka
Using kafka-python
from kafka.admin import KafkaAdminClient, NewTopic
admin_client = KafkaAdminClient(
bootstrap_servers="localhost:9092",
client_id='test'
)
topic_list = []
topic_list.append(NewTopic(name="example_topic", num_partitions=1, replication_factor=1))
admin_client.create_topics(new_topics=topic_list, validate_only=False)
Using confluent_kafka
from confluent_kafka.admin import AdminClient, NewTopic
admin_client = AdminClient({
"bootstrap.servers": "localhost:9092"
})
topic_list = []
topic_list.append(NewTopic("example_topic", 1, 1))
admin_client.create_topics(topic_list)