def _create_uamqp_connection(self): auth = create_authentication(self) self._connection = uamqp.Connection( hostname=self.fully_qualified_namespace, sasl=auth, debug=self._config.logging_enable )
def test_event_hubs_shared_connection(live_eventhub_config): uri = "sb://{}/{}".format(live_eventhub_config['hostname'], live_eventhub_config['event_hub']) sas_auth = authentication.SASTokenAuth.from_shared_access_key( uri, live_eventhub_config['key_name'], live_eventhub_config['access_key']) source = "amqps://{}/{}/ConsumerGroups/{}/Partitions/".format( live_eventhub_config['hostname'], live_eventhub_config['event_hub'], live_eventhub_config['consumer_group']) send_single_message(live_eventhub_config, "0", "Message") send_single_message(live_eventhub_config, "1", "Message") with uamqp.Connection(live_eventhub_config['hostname'], sas_auth, debug=False) as conn: partition_0 = uamqp.ReceiveClient(source + "0", debug=False, auth=sas_auth, timeout=3000, prefetch=10) partition_1 = uamqp.ReceiveClient(source + "1", debug=False, auth=sas_auth, timeout=3000, prefetch=10) partition_0.open(connection=conn) partition_1.open(connection=conn) try: messages_0 = partition_0.receive_message_batch(1) messages_1 = partition_1.receive_message_batch(1) assert len(messages_0) == 1 and len(messages_1) == 1 except: raise finally: partition_0.close() partition_1.close()
def test_iothub_client_receive_sync(live_iothub_config): operation = '/messages/events/ConsumerGroups/{}/Partitions/{}'.format( live_iothub_config['consumer_group'], live_iothub_config['partition']) auth = authentication.SASLPlain( live_iothub_config['hostname'], *_build_iothub_amqp_endpoint_from_target(live_iothub_config)) source = 'amqps://' + live_iothub_config['hostname'] + operation log.info("Source: {}".format(source)) with uamqp.Connection(live_iothub_config['hostname'], auth, debug=True) as conn: result = _receive_message(conn, source, auth) new_auth = authentication.SASLPlain(result.hostname, live_iothub_config['key_name'], live_iothub_config['access_key']) conn.redirect(result, new_auth) result = _receive_message(conn, result.address, new_auth) log.info("Finished receiving")