Ejemplo n.º 1
0
def test_basic_consume_cat_headers():
    def on_receive(ch, method, properties, msg):
        headers = properties.headers
        assert headers
        assert "NewRelicID" not in headers
        assert "NewRelicTransaction" not in headers
        assert msg == b"Testing CAT 123"
        txn = current_transaction()
        assert txn.client_cross_process_id == "1#1"
        assert txn.client_account_id == 1
        assert txn.client_application_id == 1
        ch.stop_consuming()

    with pika.BlockingConnection(pika.ConnectionParameters(
            DB_SETTINGS["host"])) as connection:
        channel = connection.channel()
        queue_name = "TESTCAT-%s" % os.getpid()
        channel.queue_declare(queue_name, durable=False)

        properties = pika.BasicProperties()
        properties.headers = {"Hello": "World"}

        try:
            basic_consume(channel, queue_name, on_receive, auto_ack=False)
            do_basic_publish(channel, queue_name, properties=properties)
            do_basic_consume(channel)

        finally:
            channel.queue_delete(queue_name)
Ejemplo n.º 2
0
def test_blocking_connection_basic_consume_inside_txn(producer, as_partial):
    def on_message(channel, method_frame, header_frame, body):
        assert hasattr(method_frame, '_nr_start_time')
        assert body == BODY
        channel.stop_consuming()

    if as_partial:
        on_message = functools.partial(on_message)

    with pika.BlockingConnection(
            pika.ConnectionParameters(DB_SETTINGS['host'])) as connection:
        channel = connection.channel()
        basic_consume(channel, QUEUE, on_message)
        try:
            channel.start_consuming()
        except:
            channel.stop_consuming()
            raise
Ejemplo n.º 3
0
def test_basic_consume_distributed_tracing_headers():
    def on_receive(ch, method, properties, msg):
        headers = properties.headers
        assert headers
        assert 'NewRelicID' not in headers
        assert 'NewRelicTransaction' not in headers
        assert msg == b'Testing distributed_tracing 123'
        txn = current_transaction()

        assert txn
        assert txn._distributed_trace_state
        assert txn.parent_type == 'App'
        assert txn._trace_id.startswith(txn.parent_tx)
        assert txn.parent_span is not None
        assert txn.parent_account == txn.settings.account_id
        assert txn.parent_transport_type == 'AMQP'
        assert txn._priority is not None
        assert txn._sampled is not None

        ch.stop_consuming()

    with pika.BlockingConnection(pika.ConnectionParameters(
            DB_SETTINGS['host'])) as connection:
        channel = connection.channel()
        queue_name = 'TESTDT-%s' % os.getpid()
        channel.queue_declare(queue_name, durable=False)

        properties = pika.BasicProperties()
        properties.headers = {'Hello': 'World'}

        try:
            basic_consume(channel, queue_name, on_receive, auto_ack=False)
            do_basic_publish(channel, queue_name, properties=properties)
            do_basic_consume(channel)

        finally:
            channel.queue_delete(queue_name)
Ejemplo n.º 4
0
 def on_open_channel(channel):
     basic_consume(channel, QUEUE, on_message)