How to use the uamqp.AMQPClient function in uamqp

To help you get started, we’ve selected a few uamqp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-python / sdk / eventhub / azure-eventhub / azure / eventhub / _client_base.py View on Github external
def _management_request(self, mgmt_msg, op_type):
        # type: (Message, bytes) -> Any
        retried_times = 0
        last_exception = None
        while retried_times <= self._config.max_retries:
            mgmt_auth = self._create_auth()
            mgmt_client = AMQPClient(self._mgmt_target)
            try:
                conn = self._conn_manager.get_connection(
                    self._address.hostname, mgmt_auth
                )  # pylint:disable=assignment-from-none
                mgmt_client.open(connection=conn)
                response = mgmt_client.mgmt_request(
                    mgmt_msg,
                    constants.READ_OPERATION,
                    op_type=op_type,
                    status_code_field=b"status-code",
                    description_fields=b"status-description",
                )
                status_code = response.application_properties[b"status-code"]
                if status_code < 400:
                    return response
                raise errors.AuthenticationException(
github Azure / azure-sdk-for-python / sdk / eventhub / azure-eventhubs / azure / eventhub / client.py View on Github external
def _management_request(self, mgmt_msg, op_type):
        alt_creds = {
            "username": self._auth_config.get("iot_username"),
            "password": self._auth_config.get("iot_password")}
        connect_count = 0
        while True:
            connect_count += 1
            mgmt_auth = self._create_auth(**alt_creds)
            mgmt_client = uamqp.AMQPClient(self.mgmt_target, auth=mgmt_auth, debug=self.config.network_tracing)
            try:
                mgmt_client.open()
                response = mgmt_client.mgmt_request(
                    mgmt_msg,
                    constants.READ_OPERATION,
                    op_type=op_type,
                    status_code_field=b'status-code',
                    description_fields=b'status-description')
                return response
            except (errors.AMQPConnectionError, errors.TokenAuthFailure, compat.TimeoutException) as failure:
                if connect_count >= self.config.max_retries:
                    err = ConnectError(
                        "Can not connect to EventHubs or get management info from the service. "
                        "Please make sure the connection string or token is correct and retry. "
                        "Besides, this method doesn't work if you use an IoT connection string.",
                        failure
github Azure / azure-event-hubs-python / azure / eventhub / client.py View on Github external
Get details on the specified EventHub.
        Keys in the details dictionary include:
            -'name'
            -'type'
            -'created_at'
            -'partition_count'
            -'partition_ids'

        :rtype: dict
        """
        alt_creds = {
            "username": self._auth_config.get("iot_username"),
            "password":self._auth_config.get("iot_password")}
        try:
            mgmt_auth = self._create_auth(**alt_creds)
            mgmt_client = uamqp.AMQPClient(self.mgmt_target, auth=mgmt_auth, debug=self.debug)
            mgmt_client.open()
            mgmt_msg = Message(application_properties={'name': self.eh_name})
            response = mgmt_client.mgmt_request(
                mgmt_msg,
                constants.READ_OPERATION,
                op_type=b'com.microsoft:eventhub',
                status_code_field=b'status-code',
                description_fields=b'status-description')
            eh_info = response.get_data()
            output = {}
            if eh_info:
                output['name'] = eh_info[b'name'].decode('utf-8')
                output['type'] = eh_info[b'type'].decode('utf-8')
                output['created_at'] = datetime.datetime.fromtimestamp(float(eh_info[b'created_at'])/1000)
                output['partition_count'] = eh_info[b'partition_count']
                output['partition_ids'] = [p.decode('utf-8') for p in eh_info[b'partition_ids']]
github Azure / azure-sdk-for-python / sdk / servicebus / azure-servicebus / azure / servicebus / base_handler.py View on Github external
def _build_handler(self):
        auth = None if self.connection else authentication.SASTokenAuth.from_shared_access_key(**self.auth_config)
        self._handler = AMQPClient(
            self.endpoint,
            auth=auth,
            debug=self.debug,
            properties=self.properties,
            error_policy=self.error_policy,
            encoding=self.encoding,
            **self.handler_kwargs)