0

I am using Service Bus Explorer as a quick way of testing a rule that does not work when deployed via ARM.

In JavaScript in the Azure Function I am setting the Topic message to:

context.bindings.outputSbMsg = { Indicator: 'Itinerary'};

In Service Bus Explorer I am setting a Rule on a Subscription with this string:

Indicator = 'Itinerary'

But messages sent to the Topic do not go to this Subscription ( they go to another with the rule 1 = 1)

Question: What am I missing here?

Supplementary info:

  1. I do not seem to have access to the Indicator property. As a test I created an action on the 1=1 rule that appended to the Indicator property and the result was empty.

  2. I am able to access the Indicator property in JavaScript if I have a Function that is triggered by the 1 = 1 rule, so the property is there.

Jerry Liu
  • 17,282
  • 4
  • 40
  • 61
Trevor Cousins
  • 233
  • 2
  • 7

1 Answers1

1

The rule doesn't work because

  1. The rule works against system or user-defined properties rather than message body.
  2. What js function outputs is merely message body, i.e. context.bindings.outputSbMsg = { Indicator: 'Itinerary'}; sends a message { Indicator: 'Itinerary'} and no property is set by us.

And the default rule with 1=1 true filter enables all messages to be selected into the subscription, so you see messages went there all the time. Check doc of topic filters for more details.

For now, it's by design that js function output can't populate message properties. To make the filter work, we have to send messages with property using SDK instead. Install azure-sb package then try sample code below.

const azuresb = require("azure-sb");
const connStr = "ServiceBusConnectionString";
const mytopic = "mytopic";

var serviceBus = azuresb.createServiceBusService(connStr);
const msg =
{
  body: "Testing",
  customProperties: {
    Indicator: 'Itinerary'
  }
};
serviceBus.sendTopicMessage(mytopic, msg, function(error) {
    if (error) {
        context.log(error);
    }
    else{
        context.log("Message Sent");
    }
});
Jerry Liu
  • 17,282
  • 4
  • 40
  • 61