def __init__( self, service_url, authentication=None, operation_timeout_seconds=30, io_threads=1, message_listener_threads=1, concurrent_lookup_requests=50000, log_conf_file_path=None, logger=None, use_tls=False, tls_trust_certs_file_path=None, tls_allow_insecure_connection=False, tls_validate_hostname=False, ): """ Create a new Pulsar client instance. **Args** * `service_url`: The Pulsar service url eg: pulsar://my-broker.com:6650/ **Options** * `authentication`: Set the authentication provider to be used with the broker. For example: `AuthenticationTls` or `AuthenticationAthenz` * `operation_timeout_seconds`: Set timeout on client operations (subscribe, create producer, close, unsubscribe). * `io_threads`: Set the number of IO threads to be used by the Pulsar client. * `message_listener_threads`: Set the number of threads to be used by the Pulsar client when delivering messages through message listener. The default is 1 thread per Pulsar client. If using more than 1 thread, messages for distinct `message_listener`s will be delivered in different threads, however a single `MessageListener` will always be assigned to the same thread. * `concurrent_lookup_requests`: Number of concurrent lookup-requests allowed on each broker connection to prevent overload on the broker. * `log_conf_file_path`: Initialize log4cxx from a configuration file. * `logger`: Set a Python logger for this Pulsar client. * `use_tls`: Configure whether to use TLS encryption on the connection. This setting is deprecated. TLS will be automatically enabled if the `serviceUrl` is set to `pulsar+ssl://` or `https://` * `tls_trust_certs_file_path`: Set the path to the trusted TLS certificate file. If empty defaults to certifi. * `tls_allow_insecure_connection`: Configure whether the Pulsar client accepts untrusted TLS certificates from the broker. * `tls_validate_hostname`: Configure whether the Pulsar client validates that the hostname of the endpoint, matches the common name on the TLS certificate presented by the endpoint. """ _check_type(str, service_url, 'service_url') _check_type_or_none(Authentication, authentication, 'authentication') _check_type(int, operation_timeout_seconds, 'operation_timeout_seconds') _check_type(int, io_threads, 'io_threads') _check_type(int, message_listener_threads, 'message_listener_threads') _check_type(int, concurrent_lookup_requests, 'concurrent_lookup_requests') _check_type_or_none(str, log_conf_file_path, 'log_conf_file_path') _check_type_or_none(logging.Logger, logger, 'logger') _check_type(bool, use_tls, 'use_tls') _check_type_or_none(str, tls_trust_certs_file_path, 'tls_trust_certs_file_path') _check_type(bool, tls_allow_insecure_connection, 'tls_allow_insecure_connection') _check_type(bool, tls_validate_hostname, 'tls_validate_hostname') conf = _pulsar.ClientConfiguration() if authentication: conf.authentication(authentication.auth) conf.operation_timeout_seconds(operation_timeout_seconds) conf.io_threads(io_threads) conf.message_listener_threads(message_listener_threads) conf.concurrent_lookup_requests(concurrent_lookup_requests) if log_conf_file_path: conf.log_conf_file_path(log_conf_file_path) if logger: conf.set_logger(logger) if use_tls or service_url.startswith( 'pulsar+ssl://') or service_url.startswith('https://'): conf.use_tls(True) if tls_trust_certs_file_path: conf.tls_trust_certs_file_path(tls_trust_certs_file_path) else: conf.tls_trust_certs_file_path(certifi.where()) conf.tls_allow_insecure_connection(tls_allow_insecure_connection) conf.tls_validate_hostname(tls_validate_hostname) self._client = _pulsar.Client(service_url, conf) self._consumers = []
def __init__(self, service_url, authentication=None, operation_timeout_seconds=30, io_threads=1, message_listener_threads=1, concurrent_lookup_requests=50000, log_conf_file_path=None, use_tls=False, tls_trust_certs_file_path=None, tls_allow_insecure_connection=False): """ Create a new Pulsar client instance. **Args** * `service_url`: The Pulsar service url eg: pulsar://my-broker.com:6650/ **Options** * `authentication`: Set the authentication provider to be used with the broker. * `operation_timeout_seconds`: Set timeout on client operations (subscribe, create producer, close, unsubscribe). * `io_threads`: Set the number of IO threads to be used by the Pulsar client. * `message_listener_threads`: Set the number of threads to be used by the Pulsar client when delivering messages through message listener. The default is 1 thread per Pulsar client. If using more than 1 thread, messages for distinct `message_listener`s will be delivered in different threads, however a single `MessageListener` will always be assigned to the same thread. * `concurrent_lookup_requests`: Number of concurrent lookup-requests allowed on each broker connection to prevent overload on the broker. * `log_conf_file_path`: Initialize log4cxx from a configuration file. * `use_tls`: Configure whether to use TLS encryption on the connection. * `tls_trust_certs_file_path`: Set the path to the trusted TLS certificate file. * `tls_allow_insecure_connection`: Configure whether the Pulsar client accepts untrusted TLS certificates from the broker. """ conf = _pulsar.ClientConfiguration() if authentication: conf.authentication(authentication.auth) conf.operation_timeout_seconds(operation_timeout_seconds) conf.io_threads(io_threads) conf.message_listener_threads(message_listener_threads) conf.concurrent_lookup_requests(concurrent_lookup_requests) if log_conf_file_path: conf.log_conf_file_path(log_conf_file_path) conf.use_tls(use_tls) if tls_trust_certs_file_path: conf.tls_trust_certs_file_path(tls_trust_certs_file_path) conf.tls_allow_insecure_connection(tls_allow_insecure_connection) self._client = _pulsar.Client(service_url, conf) self._consumers = []