Fix failed AsyncioTest.test_send_failure and clean up tests (#231) After https://github.com/apache/pulsar/pull/23291, which is included in Pulsar 4.0.0, when the tenant does not exist, the broker will respond with `BrokerMetadataError`, which is retryable. Before that, the error code is `AuthorizationError`, which is not retryable so that `create_producer` will fail immediately. This patch fixes the `test_send_failure` to assert the error is `Timeout`. Additional, separate some tests from `pulsar_test.py`: 1. debug logger tests will affect other tests so that all tests will print debug logs 2. running `schema_test` in `pulsar_test` might have unexpected failures like ``` Failed to create ConsumerImpl for persistent://public/default/my-python-pattern-consumer-3-partition-0: Failed to create steady_timer: kqueue: Too many open files [system:24] Failed when subscribed to topic persistent://public/default/my-python-pattern-consumer-3 in TopicsConsumer. Error - ConnectError Unable to create Consumer - [Muti Topics Consumer: TopicName - persistent://public/default/my-python-pattern-consumer.* - Subscription - my-pattern-consumer-sub] Error - ConnectError Failed to retry lookup for get-partition-metadata-persistent://public/default/my-v2-topic-producer-consumer: Failed to create steady_timer: kqueue: Too many open files [system:24] Error Checking/Getting Partition Metadata while Subscribing on persistent://public/default/my-v2-topic-producer-consumer -- ConnectError Failed to retry lookup for get-partition-metadata-persistent://public/default/my-v2-topic-producer-consumer: Failed to create steady_timer: kqueue: Too many open files [system:24] Error Checking/Getting Partition Metadata while Subscribing on persistent://public/default/my-v2-topic-producer-consumer -- ConnectError Failed to retry lookup for get-partition-metadata-persistent://public/default/test_has_message_available_after_seek-1730263910.78957: Failed to create steady_timer: kqueue: Too many open files [system:24] Error Checking/Getting Partition Metadata while creating producer on persistent://public/default/test_has_message_available_after_seek-1730263910.78957 -- ConnectError Failed to retry lookup for get-partition-metadata-persistent://public/default/test_seek_latest_message_id-1730263910.789991: Failed to create steady_timer: kqueue: Too many open files [system:24] ```
Pulsar Python clients support a variety of Pulsar features to enable building applications connecting to your Pulsar cluster. For the supported Pulsar features, see Client Feature Matrix.
PyBind11 is a header-only library and a submodule, so you can simply download the submodule so that CMake can find this dependency.
git submodule update --init
You can also download the pybind11 directly like:
pip3 install pyyaml export PYBIND11_VERSION=$(./build-support/dep-version.py pybind11) curl -L -O https://github.com/pybind/pybind11/archive/refs/tags/v${PYBIND11_VERSION}.tar.gz tar zxf v${PYBIND11_VERSION}.tar.gz mv pybind11-${PYBIND11_VERSION} pybind11
After that, you only need to install the Pulsar C++ client dependency into the system path. You can install the pre-built binaries or build from source.
Make sure the PyBind11 submodule has been downloaded and the Pulsar C++ client has been installed. Then run the following commands:
cmake -B build cmake --build build cmake --install build python3 ./setup.py bdist_wheel python3 -m pip install dist/pulsar_client-*.whl --force-reinstall
NOTE
- The separate
builddirectory is created to store all CMake temporary files. However, thesetup.pyrequires the_pulsar.soto be under the project directory.- Add the
--force-reinstalloption to overwrite the existing Python wheel in case your system has already installed a wheel before.- On Windows, the Python command is
pyinstead ofpython3.
You can run python3 -c 'import pulsar' to see whether the wheel has been installed successfully. If it fails, check whether dependencies (e.g., libpulsar.so) are in the system path. If not, make sure the dependencies are in LD_LIBRARY_PATH (on Linux) or DYLD_LIBRARY_PATH (on macOS).
Then you can run examples as a simple end-to-end test.
# In terminal 1 python3 ./examples/consumer.py
# In terminal 2 python3 ./examples/producer.py
Before executing the commands above, you must ensure the Pulsar service is running. See here for quick start.
Before running the unit tests, you must run a Pulsar service with all things set up:
./build-support/pulsar-test-service-start.sh
The command above runs a Pulsar standalone in a Docker container. You can run ./build-support/pulsar-test-service-stop.sh to stop it.
Run all unit tests:
./tests/run-unit-tests.sh
Run a single unit test (e.g., PulsarTest.test_tls_auth):
python3 ./tests/pulsar_test.py 'PulsarTest.test_tls_auth'
Pulsar Python Client uses pydoctor to generate API docs. To generate by yourself, you need to install the Python library first. Then run the following command in the root path of this repository:
sudo python3 -m pip install pydoctor cp $(python3 -c 'import _pulsar, os; print(_pulsar.__file__)') ./_pulsar.so pydoctor --make-html \ --docformat=numpy --theme=readthedocs \ --intersphinx=https://docs.python.org/3/objects.inv \ --html-output=<path-to-apidocs> \ --introspect-c-modules \ ./_pulsar.so \ pulsar
Then the index page will be generated in <path-to-apidocs>/index.html.
We welcome contributions from the open source community!
If your contribution adds Pulsar features for Python clients, you need to update both the Pulsar docs and the Client Feature Matrix. See Contribution Guide for more details.