0

In azure servicebus I have a topic with a subscription. When this topic recieved a message, the subscription must forward the message to a logging-queue. How can I specify that the forwarded message is from this topic? I need the name of topic in the forwarded message.

I tried this but does not work. I dont know if Im doing wrong.

az servicebus topic subscription rule create --resource-group myresourcegroup --namespace-name mynamespace --topic-name mytopic --subscription-name mysubscription --name myrule --sql-action-expression myproperty=myvalue
milan-W
  • 65
  • 1
  • 9
  • Can you not add topic name as one of the custom properties in the message itself while sending? – Gaurav Mantri May 16 '19 at 08:18
  • No I dont think so. I did not find any option which do that in topic rules or subscription rules. Is that possible to do? if so how? – milan-W May 16 '19 at 09:18
  • Not through the rules but when you send a message you can define zero or more custom properties. For example, if you're using Azure Service Bus SDK for .Net, `Message` class has a property called. `UserProperties`. You can add topic name there and send the message to the topic. More on UserProperties can be found here: https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.servicebus.message.userproperties?view=azure-dotnet#Microsoft_Azure_ServiceBus_Message_UserProperties. – Gaurav Mantri May 16 '19 at 09:22
  • Yeah, Ofc I do that. In the message property I added TopicName. But since I have several Topics, so I want that the name of the Topic which forwards a message to be set while forwarding. The message has a TopicName property which is empty when a user send the message to the topic, and it is OK. But when the topic got the message, the subscription in the topic must forward the message to a queue. In this forwarding I need the name of topic in the message. I want something like Set TopicName=%topicname% just befor forwarding. – milan-W May 16 '19 at 09:44
  • 1
    I think you're confusing between a `Topic` and a `Subscription`. If I am not mistaken, you need the name of the `Subscription` from where the message is forwarded to as a message sent to a topic can be received by 0 or more subscriptions based on the filtering rules. – Gaurav Mantri May 16 '19 at 10:26
  • To get the name of subscription can solve the problem as well. Then how can I set the name of subscription while forwarding? – milan-W May 16 '19 at 10:37
  • AFAIK, I don’t think you can. Messages are forwarded automatically and you can’t inject anything into the messages. – Gaurav Mantri May 16 '19 at 10:52

1 Answers1

0

Messages that have specific characteristics must be processed in different ways. To enable this processing, you can configure subscriptions to find messages that have desired properties and then perform certain modifications to those properties. While Service Bus subscriptions see all messages sent to the topic, you can only copy a subset of those messages to the virtual subscription queue.

This filtering is accomplished using subscription filters. Such modifications are called filter actions. When a subscription is created, you can supply a filter expression that operates on the properties of the message, both the system properties (for example, Label) and custom application properties (for example, StoreName.)

For a full working example, see the TopicSubscriptionWithRuleOperationsSample sample on GitHub.

DixitArora-MSFT
  • 1,768
  • 1
  • 5
  • 8
  • But according to https://learn.microsoft.com/en-us/cli/azure/servicebus/topic/subscription?view=azure-cli-latest#az-servicebus-topic-subscription-create there is no option to set custom application properties (for example, StoreName). – milan-W May 16 '19 at 10:16
  • In subscription rules, https://learn.microsoft.com/en-us/cli/azure/servicebus/topic/subscription/rule?view=azure-cli-latest#az-servicebus-topic-subscription-rule-create there are some options but they belong to system properties (for example, Label) – milan-W May 16 '19 at 10:18