Search code examples
pythonazureazure-servicebus-queues

How to close connection with the azure service bus queue?


I am able to receive the message from azure queues using their official SDK. It works fine. Here is the snippet that I am using to receive a message from the queue.

   from azure.servicebus import QueueClient

   client = QueueClient.from_connection_string(
           q_string,
           q_name)

    msg = None

    with client.get_receiver() as queue_receiver:
        messages = queue_receiver.fetch_next(max_batch_size=1, timeout=3)
        if len(messages) > 0:
            msg = messages[0]
            print(f"Received {msg.message}")

    return msg

How do I close the connection with the queue? How can I do that? Is there any function available with azure sdk?


Solution

  • How do I close the connection with the queue? How can I do that? Is there any function available with azure sdk?

    You can call close method on the service bus client. That will close down the Service Bus client and the underlying connection.