def configure_client_certificate_authentication_customized_settings( props, key_file, key_store_password, key_store_url): """ For a client to use a client certificate authentication scheme, the host event broker must be properly configured for TLS/SSL connections, and Client Certificate Verification must be enabled for the particular Message VPN that the client is connecting to. On client side client certificate needs to be present in a keystore file. Args: props: key_store_password: password for the key store key_store_url: url to the key store file key_file: key file Returns: configured and connected instance of MessagingService ready to be used for messaging tasks """ try: transport_security = TLS.create() \ .with_certificate_validation(True, validate_server_name=False, trust_store_file_path=SamplerUtil.get_trusted_store_dir()) messaging_service = MessagingService.builder() \ .from_properties(props) \ .with_transport_security_strategy(transport_security) \ .with_authentication_strategy(ClientCertificateAuthentication.of(certificate_file=key_store_url, key_file=key_file, key_password=key_store_password)) \ .build(SamplerUtil.get_new_application_id()) return messaging_service.connect() except Exception as exception: print(exception) finally: messaging_service.disconnect()
def connect_parametrized_retry(retries, retry_interval): """ creates a new instance of message service, that is used to configure direct message instances from config Returns: new connection for Direct messaging Raises: PubSubPlusClientError """ try: message_service = MessagingService.builder() \ .from_properties(boot.broker_properties()) \ .with_reconnection_retry_strategy(RetryStrategy.parametrized_retry(retries, retry_interval)) \ .build(SamplerUtil.get_new_application_id()) return message_service.connect() except PubSubPlusClientError as exception: print(f'Exception: {exception}') raise exception finally: message_service.disconnect()
def run(): """this method is used to run the connect messaging service sampler""" broker_props = boot.broker_properties() result = HowToConnectMessagingService().create_from_properties( broker_props) SamplerUtil.print_sampler_result( Template("Message Service[SYNC] connect $status").substitute( status="SUCCESS" if result == 0 else "FAILED")) result = HowToConnectMessagingService().create_from_properties_async( broker_props) SamplerUtil.print_sampler_result( Template("Message Service[ASYNC] connect $status").substitute( status="SUCCESS" if result == 0 else "FAILED")) result = HowToConnectMessagingService() \ .create_from_properties_async_application_id(broker_props, SamplerUtil.get_new_application_id()) SamplerUtil.print_sampler_result( Template( "Message Service[ASYNC] connect with applicationId $status"). substitute(status="SUCCESS" if result == 0 else "FAILED"))