confluent-kafka-python | Confluent 's Kafka Python Client | Pub Sub library
kandi X-RAY | confluent-kafka-python Summary
kandi X-RAY | confluent-kafka-python Summary
confluent-kafka-python provides a high-level Producer, Consumer and AdminClient compatible with all [Apache KafkaTM] brokers >= v0.8, [Confluent Cloud] and the [Confluent Platform] The client is:. See the [API documentation] for more info.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Temporarily alter configs
- Create futures for each key in futmap_keys
- Create a future
- Alters configured configs
- Register a new Avro schema
- Store a schema
- Create an ACL
- Create an ACL binding
- Delete ACL
- Parse a string or None
- Update compatibility level
- Make a Kafka result from a f
- Make resource result from futures
- Get the compatibility level
- Returns the compatibility level
- Delete a subject
- Collect artifacts matching the git ref
- Gets a registered schema
- Tests whether a subject is compatible with the given schema
- Retrieve a message from the server
- List topics
- Check the schema for a subject
- Describe ACLs
- Test whether a subject is compatible
- Get a schema by its ID
- Get the version of a subject
confluent-kafka-python Key Features
confluent-kafka-python Examples and Code Snippets
topicparts = [TopicPartition(topic_name, i) for i in range(0, 8)]
whents = datetime.fromisoformat("2022-01-01T12:34:56.000")
whenms = int(whents) * 1000 # to get milliseconds
topicparts = [TopicPartition(topic_n
from confluent_kafka import Consumer, TopicPartition
# create the Consumer with a connection to your brokers
topic_name = "my.topic"
topicparts = [TopicPartition(topic_name, i) for i in range(0, 8)]
offsets = consumer.get_watermark_of
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 3.2.0
/_/
Using Scala version 2.12.15 (OpenJDK 64-Bit Server VM, Java 1.8.0_292)
<
from queue import Queue
import threading
import time
import json
from kafka_message_consumer import KafkaMessageConsumer
from kafka_discovery_executor import KafkaDiscoveryExecutor
def main():
with open('kafka_properties.json') as f:
from confluent_kafka.admin import AdminClient
broker = '1.1.1.1:9092' # replace appropriately
a = AdminClient({'bootstrap.servers': broker})
groups = a.list_groups(timeout=10)
print(" {} consumer groups".format(len(groups)))
for g in group
from struct import unpack
magic, schema_id = unpack('>bI', header_bytes)
Topic1 (Priority Low): 1 partitions
Topic2 (Priority medium): 5 partitions
Topic3 (Priority High): 20 partitions
topic = %MY_TOPIC_NAME_INJECTED_BY_ENV_VAR%
consumer.subscribe(topic)
while True:
messages
from confluent_kafka.avro import AvroConsumer
from confluent_kafka.avro.serializer import SerializerError
c = AvroConsumer({
'bootstrap.servers': 'mybroker,mybroker2',
'group.id': 'groupid',
'schema.registry.url': 'http://127
from kafka.admin import KafkaAdminClient, ConfigResource
admin_client = KafkaAdminClient(
bootstrap_servers="localhost:9092",
client_id='test'
)
topic_list = []
topic_list.append(ConfigResource(restype='TOPIC','your_topic_name',
Community Discussions
Trending Discussions on confluent-kafka-python
QUESTION
I have some trouble installing confluent-kafka by using "pip install confluent-kafka". But I got this error: "The filename or extension is too long." Details are below.
...ANSWER
Answered 2022-Mar-30 at 05:53Windows versions lower than 1607 have limitations in place for maximum length for a path (set by MAX_PATH), which restricts file paths' lengths to be capped at 260 characters.
Fortunately, if you are running Windows 10 version 1607, you can enable support for long paths:
- Click
Win
+R
- Type
regedit
and pressEnter
- Go to
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
- Edit or create a key named
LongPathsEnabled
(type:REG_DWORD
) - Enter
1
as its value and pressOK
. - Restart your system and try again. It should work now.
Read more: Maximum Path Length Limitation in Windows
QUESTION
This question is similar to Python KafkaConsumer start consuming messages from a timestamp except I want to know how to do it in the official Python Kafka client by Confluent.
I looked into the Consumer.offsets_for_times function but I'm confused by that it accepts timestamps in the TopicPartition.offset
field.
How is a offset
equivalent to a timestamp?
ANSWER
Answered 2022-Feb-19 at 14:14That method doesn't accept timestamps; only partitions that you want to find timestamps for.
Perhaps you mean the timeout parameter?
QUESTION
I need to retrive last N messages of a topic using confluent-kafka-python
.
I've been reading https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html# for a day, but no finding any appropriate method for getting the offset of the last message, thus I cannot calculate the offset for consumer to start with.
Please help. Thanks!
...ANSWER
Answered 2022-Feb-19 at 23:51You need the get_watermark_offsets()
function of the Consumer. You call it with a list of TopicPartition
and it returns a tuple (int, int)
(low, high) for each partition.
Something like this:
QUESTION
I've installed latest (7.0.1) version of Confluent platform in standalone mode on Ubuntu virtual machine.
Python producer for Avro formatUsing this sample Avro producer to generate stream from data to Kafka topic (pmu214).
Producer seems to work ok. I'll give full code on request. Producer output:
...ANSWER
Answered 2022-Feb-11 at 14:42If you literally ran the Python sample code, then the key is not Avro, so a failure on the key.converter
would be expected, as shown
Error converting message key
QUESTION
have encountered this error "Unrecognized field: schemaType (HTTP status code 422, SR code 422)"
when i execute a json_producer.py example in Confluent Github repository
this is my docker-compose:
...ANSWER
Answered 2022-Jan-08 at 15:08Jsonschema support was not added to the Confluent Schema Registry until version 6.0, and this is why the error reports issues about a schemaType
field, because any lower versions of the Registry response/request payload do not know about that field.
Upgrading to at least that version, or using the latest version of the image will solve that error
If you just want to produce JSON, then you don't need the Registry. More details at https://www.confluent.io/blog/kafka-connect-deep-dive-converters-serialization-explained/ .
You can use the regular producer.py
example and provide JSON objects as strings on the CLI
QUESTION
I am trying to read and print Protobuf message from Kafka using Apache Flink.
I followed the official docs with no success: https://nightlies.apache.org/flink/flink-docs-master/docs/dev/datastream/fault-tolerance/serialization/third_party_serializers/
The Flink consumer code is:
...ANSWER
Answered 2022-Jan-03 at 20:50The confluent protobuf serializer doesn't produce content that can be directly deserialized by other deserializers. The format is described in confluent's documentation: it starts with a magic byte (that is always zero), followed by a four byte schema ID. The protobuf payload follows, starting with byte 5.
The getProducedType
method should return appropriate TypeInformation
, in this case TypeInformation.of(User.class)
. Without this you may run into problems at runtime.
Deserializers used with KafkaSource
don't need to implement isEndOfStream
, but it won't hurt anything.
QUESTION
I'm currently investigating a very large Python codebase with lots of side effects and unexpected behavior, and I'd like to get a grasp on what it's doing by seeing all of the outbound HTTP requests that it makes throughout its execution, at any point in the call stack. Are there any utilities or integration paths that allow me to automatically profile the complete set of network calls made by code written in Python?
Specifically, as opposed to a solely external tool, I would like to be able to interact with the captured HTTP requests and responses programmatically from within the profiled module or an adjacent module; for example to:
- Log the requests/responses using existing logging handlers within that codebase
- Publish the request to an event broker like Kafka
- Parse into a pandas dataframe for analysis
- Integrate into existing unittest or pytest suites
I've looked at the offerings of different observability tools. For instance, Sentry appears to automatically integrate with Python's httplib
to create a "breadcrumb" for each request; however Sentry only records this information when an exception is being thrown, and its default behavior is only to publish to its Web UI. New Relic also offers the ability to view "external service" calls as part of its application performance monitoring offerings, again through its own dashboard. In both cases, however, they each lack an officially-supported Python handler that would permit the tasks described above to occur within the process that generates the outbound network requests.
ANSWER
Answered 2021-Oct-14 at 20:23I looked at Sentry's Python SDK source code, to see how they integrated with http.client
, and adapted their approach in a way that generalizes to meet my needs.
Here is the code that I wrote to decorate the http.client.HTTPConnection
object to tap into requests, request bodies, and response objects. This particular example appends the data I'd like to collect to global lists that live under the profiling module, as well as logging that same data to standard out. You can easily substitute whatever bespoke functionality you'd like in place of those calls to list.append
and logger.info
:
QUESTION
So, I want to read a topic from kafka (Confluent) where data lies in Avro format.
For certain unavoidable reasons , I would like to disable certificate validation.
I am using security.protocol= SASL_SSL and sasl.mechanisms= OAUTHBEARER
I can connect to Kafka by disabling the ssl certificate validation
...ANSWER
Answered 2021-Sep-10 at 21:54I have found an answer to this.
Basically this S.O post here. Especially the answer after the accepted answer , if you are using Confluent kafka
and avro documentation here , because my schema wasn't coming from a file , but as a http response, so I had to parse it using avro.schema.parse
Final skeleton code
QUESTION
I use the confluent kafka docker image and have enabled authentication and authorization with the following config. KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://:9092,SASL_SSL://:9093
=> 9093 SASL_SSL
=> 9092 PLAINTEXT
Here is a part of my config:
Container environment variables
ANSWER
Answered 2021-Aug-03 at 09:58You did not enable authentication on port 9092,
with combination of KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND
, you are getting authorization failure,
to fix it you should change to SASL_PLAINTEXT to allow SASL authentication without TLS encryption
PLAINTEXT://:9092 -> SASL_PLAINTEXT://:9092
QUESTION
As a beginner, I'm exploring Apache Kafka and confluent-kafka-python clients. When I tried to send simple messages from the producer, the consumer was able to consume messages successfully. Thought that I would give it a try for sending the image as payload. So going forward with a 1MB(png) image, my producer was unable to produce messages. The error which I encountered was
...ANSWER
Answered 2021-Apr-10 at 14:30It doesn't look like you changed the broker defaults very much; it's still around 1MB.
For your client errors, you need to add message.max.bytes
to the Producer config
If you need any other client properties, such as the consumer max fetch bytes, those are documented here
https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
Overall, the recommendation would be to upload your images to a centralized filestore, then send their URI location via Kafka as plain strings. This will increase throughput and reduce storage needs for your brokers, especially if you're sending/copying the same image data over multiple topics
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install confluent-kafka-python
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page