Service bus queue message - ReceiveByCorrelationId equivalent in ServiceBus Message Python SDK

ShilpaGopal 100 Reputation points
2023-03-27T20:07:31.0766667+00:00

I am using Azure Service Bus message queue. I want to retrieve first queue's message based on the correlation id when the 2nd message arrives. (both message have same correlation id)

I would like to know the equivalent of .Net API's MessageQueue.ReceiveByCorrelationId in Python API. Below is the .net API but I could not find ReceiveByCorrelationId in Python SDK.

https://learn.microsoft.com/en-us/dotnet/api/system.messaging.messagequeue.receivebycorrelationid?view=netframework-4.8.1

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
614 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,141 Reputation points
    2023-03-31T11:04:03.3966667+00:00

    @ShilpaGopal Thanks for reaching out. Unfortunately, there is no equivalent method in python as per the reference document here as we have in C# for MessageQueue.ReceiveByCorrelationId.

    The workaround in Python would be you can use the ServiceBusReceiver class to receive messages from a Service Bus queue. You can use the receive_messages() method to receive messages from the queue.

    To receive the first message based on the correlation id when the second message arrives, you can use the peek_messages() method to peek at the messages in the queue and then filter the messages based on the correlation id. Once you have the message that matches the correlation id, you can use the complete_message() method to remove the message from the queue.

    Feel free to provide the feedback/feature request in the Azure SDK for python repo here.

    Please accept as "Yes" if the answer is helpful so that it can help others in the community. If you need any help/clarification/concerns/follow up questions, then please click on "Add Comment" on my answer and provide more details.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.