Not able to send message from Azure function app to service bus queue.

srikanth t 0 Reputation points
2025-04-18T03:49:16.7833333+00:00

I am trying to crate a azure function which use service bus trigger binding to get message from queue(input queue) and place it in to other service bus queue by using azure service bus binding. Azure function invoking message from service bus but not putting message to second service bus queue(output queue). I am using azure portal to build this integration. Below is the code base azure portal generated.

funcation.js

{

"bindings": [

{

  "name": "mySbMsg",

  "type": "serviceBusTrigger",

  "direction": "in",

  "queueName": "poctestqueue",

  "connection": "cis-sandbox_RootManageSharedAccessKey_SERVICEBUS"

},

{

  "name": "outputSbMsg",

  "direction": "out",

  "type": "serviceBus",

  "queueName": "poctestqueue",

  "methods": [],

  "connection": "servicebus_td00"

}

]

}

Index.js

module.exports = async function(context, mySbMsg, outputSbMsg) {

context.log('JavaScript ServiceBus queue trigger function processed message', mySbMsg);

var outputSbMsg = mySbMsg;

context.log('Output message', outputSbMsg); 

return outputSbMsg;

};

host.json

{

"version": "2.0",

"isDefaultHostConfig": true,

"extensionBundle": {

"id": "Microsoft.Azure.Functions.ExtensionBundle",

"version": "[4.*, 5.0.0]"

}

}

Can you please help to understand what I am doing incorrect and what fixes are required to resolve this issue. Any help would be appreciated.

Thanks.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,771 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Shireesha Eeraboina 2,855 Reputation points Microsoft External Staff Moderator
    2025-04-18T05:20:47.9633333+00:00

    Hi srikanth t,

    It looks like your Azure Function is set up to read from one Service Bus queue and write to another, but the output message isn't being sent correctly.

    Here's what to check:

    Output Binding Configuration:

    Make sure the queueName in your output binding is correctly set to the name of the second Service Bus queue (the target queue where you want to send the message). It seems you are using the same queue name (poctestqueue) for both input and output. Change the output queue name to the correct target queue name.

    Setting the Output Message:

    In your index.js, you should not declare a new outputSbMsg variable. Instead, directly assign the message to the context’s bindings object like this:

    context.bindings.outputSbMsg = mySbMsg;
    
    

    This will ensure the message is sent to the output queue.

    After making these changes, test your function again to ensure everything works.

    For your reference, please review the following documentation for further clarification:

    Service Bus Trigger Binding in Azure Functions

    Also, please refer to these thread for more clarity on the issue.

    I hope this addresses your query. Please let me know if you need any further assistance or clarification.

     

    1 person found this answer helpful.
    0 comments No comments

  2. Shireesha Eeraboina 2,855 Reputation points Microsoft External Staff Moderator
    2025-04-21T04:15:09.3233333+00:00

    Hi srikanth t,

    Thank you for your patience and for sharing your feedback on the Q&A community platform. I’m glad to hear that you were able to resolve your issue, and I appreciate you sharing your solution! Your contribution is valuable and can help others in the community facing similar challenges.

    As per the Microsoft Q&A community policy, "The question author cannot accept their own answer. They can only accept answers by others"

    I’m reposting your solution here so you can mark it as accepted if it resolves your query:

    "The issue was resolved after adding the output context binding. I used the same queue name, but since the queues are on different Service Bus namespaces, no changes to the names were needed".

    Thank you again for your time and patience throughout this issue.  

    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.