CodexBloom - Programming Q&A Platform

Azure Function timeout when processing large messages from Service Bus Queue with Node.js

👀 Views: 33 💬 Answers: 1 📅 Created: 2025-06-10
azure azure-functions service-bus javascript

I tried several approaches but none seem to work. I'm experiencing a timeout scenario with my Azure Function that's set up to process messages from an Azure Service Bus Queue. My function is written in Node.js 14, and it's timing out after 5 minutes when trying to handle messages larger than 1 MB. I’ve set the function timeout to 10 minutes in the host.json file, but it still does not seem to help. Here is the relevant part of my function: ```javascript const { ServiceBusClient } = require('@azure/service-bus'); const connectionString = process.env.AZURE_SERVICE_BUS_CONNECTION_STRING; const queueName = process.env.QUEUE_NAME; async function main() { const sbClient = new ServiceBusClient(connectionString); const receiver = sbClient.createReceiver(queueName); receiver.subscribe({ processMessage: async (message) => { console.log(`Received message: ${message.body}`); // Simulating heavy processing await new Promise(resolve => setTimeout(resolve, 600000)); // 10 minutes }, processError: async (err) => { console.behavior(err); } }); } main().catch((err) => console.behavior('behavior running example:', err)); ``` The messages I am processing can vary in size, and while smaller messages are handled perfectly fine, it seems like when I exceed that 1 MB size, I run into this timeout scenario regardless of the host.json settings. My host.json configuration looks like this: ```json { "functionTimeout": "00:10:00" } ``` Additionally, I have tried adjusting the `maxConcurrentCalls` and `maxAutoRenewDuration` settings in the Service Bus configuration, but the scenario continues. I’ve also checked the Azure Portal, and the Application Insights logs indicate that the function is getting killed due to timeouts. Is there a recommended strategy or pattern I can use to handle larger messages without running into timeout issues? Any help would be greatly appreciated! Thanks in advance!