当前位置: 首页>>代码示例>>Python>>正文


Python message.Message类代码示例

本文整理汇总了Python中azure.servicebus.common.message.Message的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pqueue_schedule_message

def test_pqueue_schedule_message(live_servicebus_config, partitioned_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)
    import uuid
    queue_client = client.get_queue(partitioned_queue)
    enqueue_time = (datetime.now() + timedelta(minutes=2)).replace(microsecond=0)
    with queue_client.get_receiver() as receiver:
        with queue_client.get_sender() as sender:
            content = str(uuid.uuid4())
            message_id = uuid.uuid4()
            message = Message(content)
            message.properties.message_id = message_id
            message.schedule(enqueue_time)
            sender.send(message)

        messages = receiver.fetch_next(timeout=120)
        if messages:
            try:
                data = str(messages[0])
                assert data == content
                assert messages[0].properties.message_id == message_id
                assert messages[0].scheduled_enqueue_time == enqueue_time
                assert messages[0].scheduled_enqueue_time == messages[0].enqueued_time.replace(microsecond=0)
                assert len(messages) == 1
            finally:
                for m in messages:
                    m.complete()
        else:
            raise Exception("Failed to receive schdeduled message.")
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:32,代码来源:test_partitioned_queues.py

示例2: test_qsession_by_servicebus_client_browse_messages_client

def test_qsession_by_servicebus_client_browse_messages_client(live_servicebus_config, partitioned_session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_session_queue)
    session_id = str(uuid.uuid4())
    with queue_client.get_sender(session=session_id) as sender:
        for i in range(5):
            message = Message("Test message no. {}".format(i))
            message.partition_key = "MyPartitionKey"
            sender.send(message)

    with pytest.raises(ValueError):
        messages = queue_client.peek(5)

    messages = queue_client.peek(5, session=session_id)
    assert len(messages) == 5
    assert all(isinstance(m, PeekMessage) for m in messages)
    for message in messages:
        print_message(message)
        with pytest.raises(TypeError):
            message.complete()
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:25,代码来源:test_partitioned_sessions.py

示例3: test_pqueue_by_servicebus_client_iter_messages_with_defer

def test_pqueue_by_servicebus_client_iter_messages_with_defer(live_servicebus_config, partitioned_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_queue)
    deferred_messages = []
    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(10):
                message = Message("Deferred message no. {}".format(i))
                sender.send(message)

        count = 0
        for message in receiver:
            deferred_messages.append(message.sequence_number)
            print_message(message)
            count += 1
            message.defer()

    assert count == 10
    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            count += 1
    assert count == 0
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:31,代码来源:test_partitioned_queues.py

示例4: test_session_by_queue_client_conn_str_receive_handler_receiveanddelete

def test_session_by_queue_client_conn_str_receive_handler_receiveanddelete(live_servicebus_config, session_queue):
    queue_client = QueueClient.from_connection_string(
        live_servicebus_config['conn_str'],
        name=session_queue,
        debug=True)
    queue_client.get_properties()

    session_id = str(uuid.uuid4())
    with queue_client.get_sender(session=session_id) as sender:
        for i in range(10):
            message = Message("Handler message no. {}".format(i))
            sender.send(message)

    messages = []
    session = queue_client.get_receiver(session=session_id, mode=ReceiveSettleMode.ReceiveAndDelete, idle_timeout=5)
    for message in session:
        messages.append(message)
        assert session_id == session.session_id
        assert session_id == message.session_id
        with pytest.raises(MessageAlreadySettled):
            message.complete()

    assert not session.running
    assert len(messages) == 10
    time.sleep(30)

    messages = []
    session = queue_client.get_receiver(session=session_id, mode=ReceiveSettleMode.ReceiveAndDelete, idle_timeout=5)
    for message in session:
        messages.append(message)
    assert len(messages) == 0
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:31,代码来源:test_sessions.py

示例5: test_pqueue_by_servicebus_client_iter_messages_with_retrieve_deferred_not_found

def test_pqueue_by_servicebus_client_iter_messages_with_retrieve_deferred_not_found(live_servicebus_config, partitioned_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_queue)
    deferred_messages = []
    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(3):
                message = Message("Deferred message no. {}".format(i))
                message.partition_key = "MyPartitionKey"
                sender.send(message)

        count = 0
        for message in receiver:
            deferred_messages.append(message.sequence_number)
            print_message(message)
            count += 1
            message.defer()

    assert count == 3

    with pytest.raises(ServiceBusError):
        deferred = queue_client.receive_deferred_messages([3, 4], mode=ReceiveSettleMode.PeekLock)

    with pytest.raises(ServiceBusError):
        deferred = queue_client.receive_deferred_messages([5, 6, 7], mode=ReceiveSettleMode.PeekLock)
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:31,代码来源:test_partitioned_queues.py

示例6: test_session_by_session_client_conn_str_receive_handler_peeklock

def test_session_by_session_client_conn_str_receive_handler_peeklock(live_servicebus_config, session_queue):
    queue_client = QueueClient.from_connection_string(
        live_servicebus_config['conn_str'],
        name=session_queue,
        debug=True)
    queue_client.get_properties()

    session_id = str(uuid.uuid4())
    with queue_client.get_sender(session=session_id) as sender:
        for i in range(3):
            message = Message("Handler message no. {}".format(i))
            sender.send(message)

    with pytest.raises(ValueError):
        session = queue_client.get_receiver(idle_timeout=5)

    session = queue_client.get_receiver(session=session_id, idle_timeout=5)
    count = 0
    for message in session:
        print_message(message)
        assert message.session_id == session_id
        count += 1
        message.complete()

    assert count == 3
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:25,代码来源:test_sessions.py

示例7: test_session_schedule_message

def test_session_schedule_message(live_servicebus_config, session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)
    import uuid
    session_id = str(uuid.uuid4())
    queue_client = client.get_queue(session_queue)
    enqueue_time = (datetime.now() + timedelta(minutes=2)).replace(microsecond=0)
    with queue_client.get_receiver(session=session_id) as receiver:
        with queue_client.get_sender(session=session_id) as sender:
            content = str(uuid.uuid4())
            message_id = uuid.uuid4()
            message = Message(content)
            message.properties.message_id = message_id
            message.schedule(enqueue_time)
            sender.send(message)

        messages = []
        count = 0
        while not messages and count < 12:
            messages = receiver.fetch_next(timeout=10)
            receiver.renew_lock()
            count += 1

        data = str(messages[0])
        assert data == content
        assert messages[0].properties.message_id == message_id
        assert messages[0].scheduled_enqueue_time == enqueue_time
        assert messages[0].scheduled_enqueue_time == messages[0].enqueued_time.replace(microsecond=0)
        assert len(messages) == 1
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:32,代码来源:test_sessions.py

示例8: test_pqueue_message_time_to_live

def test_pqueue_message_time_to_live(live_servicebus_config, partitioned_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)
    import uuid
    queue_client = client.get_queue(partitioned_queue)
    
    with queue_client.get_sender() as sender:
        content = str(uuid.uuid4())
        message_id = uuid.uuid4()
        message = Message(content)
        message.time_to_live = timedelta(seconds=30)
        sender.send(message)

    time.sleep(30)
    with queue_client.get_receiver() as receiver:
        messages = receiver.fetch_next(timeout=10)
    assert not messages

    with queue_client.get_deadletter_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            count += 1
        assert count == 1
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:28,代码来源:test_partitioned_queues.py

示例9: test_session_message_expiry

def test_session_message_expiry(live_servicebus_config, session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)
    session_id = str(uuid.uuid4())
    queue_client = client.get_queue(session_queue)
    
    with queue_client.get_sender() as sender:
        message = Message("Testing expired messages")
        message.session_id = session_id
        sender.send(message)

    with queue_client.get_receiver(session=session_id) as receiver:
        messages = receiver.fetch_next(timeout=10)
        assert len(messages) == 1
        print_message(messages[0])
        time.sleep(30)
        with pytest.raises(TypeError):
            messages[0].expired
        with pytest.raises(TypeError):
            messages[0].renew_lock()
        assert receiver.expired
        with pytest.raises(SessionLockExpired):
            messages[0].complete()
        with pytest.raises(SessionLockExpired):
            receiver.renew_lock()

    with queue_client.get_receiver(session=session_id) as receiver:
        messages = receiver.fetch_next(timeout=30)
        assert len(messages) == 1
        print_message(messages[0])
        #assert messages[0].header.delivery_count  # TODO confirm this with service
        messages[0].complete()
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:35,代码来源:test_sessions.py

示例10: test_pqueue_by_servicebus_client_receive_batch_with_deadletter

def test_pqueue_by_servicebus_client_receive_batch_with_deadletter(live_servicebus_config, partitioned_queue):

    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_queue)
    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock, prefetch=10) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(10):
                message = Message("Dead lettered message no. {}".format(i))
                sender.send(message)

        count = 0
        messages = receiver.fetch_next()
        while messages:
            for message in messages:
                print_message(message)
                count += 1
                message.dead_letter(description="Testing")
            messages = receiver.fetch_next()

    assert count == 10

    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            count += 1
    assert count == 0
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:34,代码来源:test_partitioned_queues.py

示例11: test_session_by_servicebus_client_iter_messages_with_retrieve_deferred_client

def test_session_by_servicebus_client_iter_messages_with_retrieve_deferred_client(live_servicebus_config, session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(session_queue)
    deferred_messages = []
    session_id = str(uuid.uuid4())
    with queue_client.get_sender(session=session_id) as sender:
        for i in range(10):
            message = Message("Deferred message no. {}".format(i))
            sender.send(message)

    session = queue_client.get_receiver(session=session_id, idle_timeout=5)
    count = 0
    for message in session:
        deferred_messages.append(message.sequence_number)
        print_message(message)
        count += 1
        message.defer()

    assert count == 10

    with pytest.raises(ValueError):
        deferred = queue_client.receive_deferred_messages(deferred_messages, session=session_id)

    with pytest.raises(ValueError):
        queue_client.settle_deferred_messages('completed', [message], session=session_id)
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:30,代码来源:test_sessions.py

示例12: test_pqueue_by_queue_client_conn_str_receive_handler_receiveanddelete

def test_pqueue_by_queue_client_conn_str_receive_handler_receiveanddelete(live_servicebus_config, partitioned_queue):
    queue_client = QueueClient.from_connection_string(
        live_servicebus_config['conn_str'],
        name=partitioned_queue,
        debug=True)

    with queue_client.get_sender() as sender:
        for i in range(10):
            message = Message("Handler message no. {}".format(i))
            message.enqueue_sequence_number = i
            sender.send(message)

    messages = []
    receiver = queue_client.get_receiver(mode=ReceiveSettleMode.ReceiveAndDelete, idle_timeout=5)
    for message in receiver:
        messages.append(message)
        with pytest.raises(MessageAlreadySettled):
            message.complete()

    assert not receiver.running
    assert len(messages) == 10
    time.sleep(30)

    messages = []
    receiver = queue_client.get_receiver(mode=ReceiveSettleMode.ReceiveAndDelete, idle_timeout=5)
    for message in receiver:
        messages.append(message)
    assert len(messages) == 0
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:28,代码来源:test_partitioned_queues.py

示例13: test_pqueue_by_queue_client_conn_str_receive_handler_with_stop

def test_pqueue_by_queue_client_conn_str_receive_handler_with_stop(live_servicebus_config, partitioned_queue):
    queue_client = QueueClient.from_connection_string(
        live_servicebus_config['conn_str'],
        name=partitioned_queue,
        debug=True)

    with queue_client.get_sender() as sender:
        for i in range(10):
            message = Message("Stop message no. {}".format(i))
            sender.send(message)

    messages = []
    receiver = queue_client.get_receiver(idle_timeout=5)
    for message in receiver:
        messages.append(message)
        message.complete()
        if len(messages) >= 5:
            break

    assert receiver.running
    assert len(messages) == 5

    with receiver:
        for message in receiver:
            messages.append(message)
            message.complete()
            if len(messages) >= 5:
                break

    assert not receiver.running
    assert len(messages) == 6
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:31,代码来源:test_partitioned_queues.py

示例14: test_pqueue_by_servicebus_client_iter_messages_simple

def test_pqueue_by_servicebus_client_iter_messages_simple(live_servicebus_config, partitioned_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_queue)
    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(10):
                message = Message("Iter message no. {}".format(i))
                sender.send(message)

        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            with pytest.raises(MessageAlreadySettled):
                message.complete()
            with pytest.raises(MessageAlreadySettled):
                message.renew_lock()
            count += 1

        with pytest.raises(InvalidHandlerState):
            next(receiver)
    assert count == 10
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:28,代码来源:test_partitioned_queues.py

示例15: test_pqueue_by_servicebus_conn_str_client_iter_messages_with_abandon

def test_pqueue_by_servicebus_conn_str_client_iter_messages_with_abandon(live_servicebus_config, partitioned_queue):
    client = ServiceBusClient.from_connection_string(live_servicebus_config['conn_str'], debug=True)
    queue_client = client.get_queue(partitioned_queue)
    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(10):
                message = Message("Abandoned message no. {}".format(i))
                sender.send(message)

        count = 0
        for message in receiver:
            print_message(message)
            if not message.header.delivery_count:
                count += 1
                message.abandon()
            else:
                assert message.header.delivery_count == 1
                message.complete()

    assert count == 10

    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            count += 1
    assert count == 0
开发者ID:Azure,项目名称:azure-sdk-for-python,代码行数:29,代码来源:test_partitioned_queues.py


注:本文中的azure.servicebus.common.message.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。