0

I have requirement of : - I have azure function service bus topic trigger by using python code, So the service bus topic having one topic and multiple subscription with in it.

I have to add a sqlfilter to the subscription so that the message which I sent right it should only go to that subscription if the filter condition satisfies and triggers the function app

How to add the filter option in python code. I found multiple of reference in c# but I need for python.

public async Task SendMessage(MyPayload payload)
        {
            string messagePayload = JsonSerializer.Serialize(payload);
            ServiceBusMessage message = new ServiceBusMessage(messagePayload);
 
            message.ApplicationProperties.Add("goals", payload.Goals);
 
            try

for sample I have add the code for c# where there are adding application properties in function app code , so which ever subscription satisfy the condition which is goals = payload.Goals the mgs will go to that subscription.

I want to know how can we add the application properties in python azure function app code for service bus topic trigger

1 Answers1

0

Using the python client sdk for Azure Service bus, you can apply SqlFilter and SqlRuleAction before you start processing your messages.

Pseudocode will be like,

servicebus_mgmt_client.create_rule(topicname,sub_name,filtername, filter, action)

send_mesgs_to_topic()  #set filter in your message

receive_mesgs() #received mesg will have properties

See the detailed examples here in github.

Anand Sowmithiran
  • 2,591
  • 2
  • 10
  • 22
  • I have tried it but its not working. what I am doing is creating a service bus topic trigger function app. I have one topic for in-message and out-mgs and 3 subscriptions. we are trigger the databricks job with function app when we sent mgs from service bus so generally when we sent mgs in topic that mgs will be sent all the subscriptions if there is no filter . we are trying stop that behavior by keeping filter to subscription .now what ever the mgs that we sent to service bus have to go to that particular topic which we add the filter and function app has to trigger the databricks job – Syamala Kumar Rama Koti Reddy Sep 07 '22 at 12:14
  • I have edit the question and kept some reference for requirement of mine – Syamala Kumar Rama Koti Reddy Sep 07 '22 at 12:27