當前位置: 首頁>>代碼示例>>Python>>正文


Python Message.complete方法代碼示例

本文整理匯總了Python中azure.servicebus.common.message.Message.complete方法的典型用法代碼示例。如果您正苦於以下問題:Python Message.complete方法的具體用法?Python Message.complete怎麽用?Python Message.complete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在azure.servicebus.common.message.Message的用法示例。


在下文中一共展示了Message.complete方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_pqueue_by_servicebus_client_iter_messages_simple

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:30,代碼來源:test_partitioned_queues.py

示例2: test_pqueue_by_queue_client_conn_str_receive_handler_receiveanddelete

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:30,代碼來源:test_partitioned_queues.py

示例3: test_pqueue_by_servicebus_conn_str_client_iter_messages_with_abandon

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:31,代碼來源:test_partitioned_queues.py

示例4: test_qsession_by_servicebus_client_browse_messages_client

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:27,代碼來源:test_partitioned_sessions.py

示例5: test_pqueue_by_queue_client_conn_str_receive_handler_with_stop

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:33,代碼來源:test_partitioned_queues.py

示例6: test_pqueue_message_time_to_live

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:30,代碼來源:test_partitioned_queues.py

示例7: test_pqueue_by_servicebus_client_receive_batch_with_deadletter

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:36,代碼來源:test_partitioned_queues.py

示例8: test_pqueue_by_servicebus_client_iter_messages_with_defer

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:33,代碼來源:test_partitioned_queues.py

示例9: test_session_by_queue_client_conn_str_receive_handler_receiveanddelete

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:33,代碼來源:test_sessions.py

示例10: test_session_by_session_client_conn_str_receive_handler_peeklock

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
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,代碼行數:27,代碼來源:test_sessions.py

示例11: test_session_by_conn_str_receive_handler_with_autolockrenew

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
def test_session_by_conn_str_receive_handler_with_autolockrenew(live_servicebus_config, session_queue):
    session_id = str(uuid.uuid4())
    queue_client = QueueClient.from_connection_string(
        live_servicebus_config['conn_str'],
        name=session_queue,
        debug=True)

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

    renewer = AutoLockRenew()
    messages = []
    with queue_client.get_receiver(session=session_id, idle_timeout=5, mode=ReceiveSettleMode.PeekLock, prefetch=10) as session:
        renewer.register(session, timeout=60)
        print("Registered lock renew thread", session.locked_until, datetime.now())
        with pytest.raises(SessionLockExpired):
            for message in session:
                if not messages:
                    print("Starting first sleep")
                    time.sleep(40)
                    print("First sleep {}".format(session.locked_until - datetime.now()))
                    assert not session.expired
                    with pytest.raises(TypeError):
                        message.expired
                    assert message.locked_until is None
                    with pytest.raises(TypeError):
                        message.renew_lock()
                    assert message.lock_token is None
                    message.complete()
                    messages.append(message)

                elif len(messages) == 1:
                    print("Starting second sleep")
                    time.sleep(40)
                    print("Second sleep {}".format(session.locked_until - datetime.now()))
                    assert session.expired
                    assert isinstance(session.auto_renew_error, AutoLockRenewTimeout)
                    try:
                        message.complete()
                        raise AssertionError("Didn't raise SessionLockExpired")
                    except SessionLockExpired as e:
                        assert isinstance(e.inner_exception, AutoLockRenewTimeout)
                    messages.append(message)

    renewer.shutdown()
    assert len(messages) == 2
開發者ID:Azure,項目名稱:azure-sdk-for-python,代碼行數:50,代碼來源:test_sessions.py

示例12: test_pqueue_by_queue_client_conn_str_receive_handler_peeklock

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
def test_pqueue_by_queue_client_conn_str_receive_handler_peeklock(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)

    receiver = queue_client.get_receiver(idle_timeout=5)
    count = 0
    for message in receiver:
        print_message(message)
        count += 1
        message.complete()

    assert count == 10
開發者ID:Azure,項目名稱:azure-sdk-for-python,代碼行數:22,代碼來源:test_partitioned_queues.py

示例13: test_pqueue_by_servicebus_client_iter_messages_with_retrieve_deferred_client

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
def test_pqueue_by_servicebus_client_iter_messages_with_retrieve_deferred_client(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))
                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 == 10

    deferred = queue_client.receive_deferred_messages(deferred_messages, mode=ReceiveSettleMode.PeekLock)
    assert len(deferred) == 10

    for message in deferred:
        assert isinstance(message, DeferredMessage)
        with pytest.raises(ValueError):
            message.complete()

    with pytest.raises(ValueError):
        queue_client.settle_deferred_messages('foo', message)
    queue_client.settle_deferred_messages('completed', message)

    with pytest.raises(ServiceBusError):
        queue_client.receive_deferred_messages(deferred_messages)
開發者ID:Azure,項目名稱:azure-sdk-for-python,代碼行數:43,代碼來源:test_partitioned_queues.py

示例14: test_queue_by_servicebus_client_browse_messages_client

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
def test_queue_by_servicebus_client_browse_messages_client(live_servicebus_config, standard_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(standard_queue)
    with queue_client.get_sender() as sender:
        for i in range(5):
            message = Message("Test message no. {}".format(i))
            sender.send(message)

    messages = queue_client.peek(5)
    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,代碼行數:23,代碼來源:test_queues.py

示例15: test_pqueue_by_servicebus_client_browse_messages_with_receiver

# 需要導入模塊: from azure.servicebus.common.message import Message [as 別名]
# 或者: from azure.servicebus.common.message.Message import complete [as 別名]
def test_pqueue_by_servicebus_client_browse_messages_with_receiver(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(5):
                message = Message("Test message no. {}".format(i))
                message.partition_key = "MyPartitionKey"
                sender.send(message)

        messages = receiver.peek(5)
        assert len(messages) > 0
        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_queues.py


注:本文中的azure.servicebus.common.message.Message.complete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。