6

I have an azure function which makes a promise based http post request and gets a response; now I want to send this response to a service bus and to a different event hub (the azure function is being triggered by a different event hub).

function says it has been executed successfully in the case of event hub, but no events are being sent. In the case of service bus I am getting this error NamespaceConnectionString should not contain EntityPath.

module.exports = async function (context, eventHubMessages) {
    context.log(`JavaScript eventhub trigger function called for message array ${eventHubMessages}`);

    var completeData = '';

    eventHubMessages.forEach((message, index) => {
        context.log(`Processed message ${message}`);
        completeData = message;
    });

    var output = '';

    const axios = require('axios');

    try {
        const response =  await axios.post('http://fake-endpoint', 
        {  data-json : completeData
        })
        context.log(`statusCode: ${response.statusCode}`);
        context.log(response.data);
        output += response.data;

        var time = new Date().toString(); 
        context.log('Event Hub message created at: ', time);
        context.bindings.outputEventHubMessage = out;
        context.bindings.outputSbMsg = out;
        context.done()
        return response.data; // or return a custom object using properties from response
    } catch (error) {
        // If the promise rejects, an error will be thrown and caught here
        context.done(error);
    }

};

Expected output: successful execution; data available on service bus and event hub to receive. Actual output: Error: NamespaceConnectionString should not contain EntityPath.

Abe
  • 63
  • 2
  • 5

1 Answers1

10

As the error message says, you need to look at your connection string and remove the EntityPath variable. This is included if you copy the connection string when viewing a specific topic or queue as opposed to copying it from the main Service Bus blade.

Endpoint=sb://{servicebus-name}.servicebus.windows.net/;SharedAccessKeyName=test-queue-sender;SharedAccessKey={SharedAccessKey}=;EntityPath=test-queue;

vs

Endpoint=sb://{servicebus-name}.servicebus.windows.net/;SharedAccessKeyName=test-queue-sender;SharedAccessKey={SharedAccessKey};

PerfectlyPanda
  • 3,271
  • 1
  • 6
  • 17
  • This makes sense, thanks for the info. The problem is this connection string is often generated by an ARM template. How can an ARM template be modified to not provide the EntityPath in the connection string? – SSH This Jan 22 '20 at 16:36
  • Could you share a little about the ARM template you are using and how you are deploying it to get that connection string? There might be something to change in the template or it may be something I need to bring up with the product team. If you don't want to discuss it in the comments as it is off topic to the question, you can send me an email to azcommunity (at) microsoft.com and we can discuss it that way. Make sure to include a link to this thread in the email so it can get routed to me. – PerfectlyPanda Jan 22 '20 at 16:42
  • 1
    Thanks for the response, I actually managed to trim off EntityPath using string operation functions. `"value": "[first(split(listkeys(variables('defaultAuthRuleResourceId'), variables('sbVersion')).primaryConnectionString, ';EntityPath='))]"` This was required by my function app trigger, it didn't like the EntityPath that was being appended. – SSH This Jan 28 '20 at 16:22