Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a message to azure service bus & event to event hub bus from single azure functions in NodeJS?

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.

like image 572
Abe Avatar asked Apr 29 '19 07:04

Abe


1 Answers

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};

like image 195
PerfectlyPanda Avatar answered Oct 24 '22 19:10

PerfectlyPanda