As time passes, the Azure Service Bus Consumer experiences a decline in performance

My issue involves managing different topics with subscriptions, each tied to a consumer. Over time, I've noticed a decline in the number of messages received. Despite trying to utilize maxconcurrentcalls, it seems to only be effective at the start. My implementation involves using the azure/service-bus npm package and referencing an Azure bus code sample for message consumption. Although I've made tweaks to enable concurrent calls and manage message completion.

In the past, I maintained a single connection for all consumers. I experimented with establishing individual connections for each consumer, but unfortunately, this did not resolve the issue.

Here is a snippet of the code:

// Code block

Answer №1

Here are some tips to boost the process speed:

  • autoCompleteMessages should be switched off to prevent building up unfinished messages, which can slow down the consumer. Make sure to swiftly complete messages after processing.
  • Utilize the receiver's prefetchCount attribute. This determines the maximum number of messages the receiver can request in one go.
  • The lockDuration setting specifies how long a message is locked for processing by a consumer.
receiveMode:  "peekLock",
maxConcurrentCalls:  30,
autoCompleteMessages:  false,

CODE:

const  {  ServiceBusClient  } = require("@azure/service-bus");
async  function  startConsumer(connectionString,  topic,  subscriptionName)  {
let  receiver;
let  sbClient;
try  {
sbClient = new  ServiceBusClient(connectionString);
console.log("Azure connection established successfully for topic:",  topic);
}  catch (err) {
console.error("Error in connecting to Azure Service Bus:",  err);
return;
}
try  {
receiver = sbClient.createReceiver(topic,  subscriptionName,  {
receiveMode:  "peekLock",
maxConcurrentCalls:  30,
autoCompleteMessages:  false,
});
console.log(`Receiver for ${topic} connected successfully.`);
}  catch (err) {
sbClient.close();
console.error(`Error in creating receiver for ${topic}:`,  err);
return  null;
}
const  processMessage = async  (brokeredMessage)  =>  {
const  input = brokeredMessage.body.toString();
const  result = await  processData(input);
if (result) {
await  receiver.completeMessage(brokeredMessage);
}  else  {
await  receiver.abandonMessage(brokeredMessage);
}
};
const  processError = async  (args)  =>  {

console.error(`Error from source ${args.errorSource} occurred:`,  args.error);

if (args.error.code === "MessagingEntityDisabled" ||
args.error.code === "MessagingEntityNotFound" ||
args.error.code === "UnauthorizedAccess") {

console.error("An unrecoverable error occurred. Stopping processing.",  args.error);

await  receiver.close();

}  else  if (args.error.code === "MessageLockLost") {

console.error("Message lock lost for message",  args.error);

}  else  if (args.error.code === "ServiceBusy") {

await  customDelay(1000); 

}  else  {

console.error("Error in processing message",  args);

}

};

const  subscription = receiver.subscribe({

processMessage,

processError,

});
return  receiver;

}
async  function  processData(input)  {
console.log("Processing message:",  input);
return  true;

}
function  customDelay(ms)  {
return  new  Promise((resolve)  =>  setTimeout(resolve,  ms));

}
const  connectionString = "Endpoint=sb:";
const  topic = "sam";
const  subscriptionName = "sampath";
startConsumer(connectionString,  topic,  subscriptionName)
.then((receiver)  =>  {
if (receiver) {
console.log("Consumer started successfully.");
}  else  {
console.log("Failed to start the consumer.");
}
})
.catch((err)  =>  {
console.error("An error occurred while starting the consumer:",  err);
});

Output:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing a series of functions in succession using jQuery

I am trying to iterate through an object that contains functions which need to execute consecutively. Ideally, I would like these functions to be chained together in a way where one function waits for the previous one to finish before executing (e.g., func ...

Error in identifying child element using class name

I need help accessing the element with the class "hs-input" within this structure: <div class = "hbspt-form".......> <form ....class="hs-form stacked"> <div class = "hs_firstname field hs-form-field"...> <div class = ...

React's input onChange event does not trigger for the second time. It only works the first time

Recently, I developed a React JS application to import images from external sources and process them. To handle the user's onChange event, I utilized the onChange attribute to execute my handleChange function. However, I encountered an issue where it ...

Set the value obtained from a resolved promise to a mutable reference object in a React component

I am in the process of developing a random movie generator. I am utilizing an external API to retrieve a list of movies and then selecting one randomly from the returned data. The current implementation is as follows: export default function Page() { con ...

Having trouble with clearInterval in my Angular code

After all files have finished running, the array this.currentlyRunning is emptied and its length becomes zero. if(numberOfFiles === 0) { clearInterval(this.repeat); } I conducted a test using console.log and found that even though ...

Tips for creating an array that aligns with the keys of a type in TypeScript

Currently, I am utilizing the Kysely SQL builder for JS based on Vercel's recommendation, despite the limited documentation and community support. This SQL builder is fully typed, allowing you to create a db object with a schema that recognizes table ...

Instructions on utilizing module.exports to export an async function

I am facing an issue with returning the result of an async function to the route I am calling. How can I resolve this successfully? My goal is to export a token from file token_generator.js and display it on route ('/') using Express. The functi ...

Looking to update a specific element in an array on an hourly basis?

var temperature = [-18 , -18.1 , -18.2, -18.3, -18.4, -18.5, -18.6, -18.7,-18.8, -18.9, -19 , -19.1 , -19.2, -19.3, -19.4, -19.5, -19.6, -19.7,-19.8, -19.9, -20]; $(".warlotemp").html(temperature[0]); $(".warlotemp").append(" C"); I am intere ...

Guide to setting up npm pug-php-filter in conjunction with gulp

I'm having trouble setting up pug-php-filter (https://www.npmjs.com/package/pug-php-filter) with gulp in order to enable PHP usage in my Pug files. Any assistance would be greatly appreciated. ...

Removing border of the top and bottom of jspdf pages

In my project, I am utilizing a combination of html2canvas, canvg, and jspdf to convert HTML content (which includes SVG graphs) into canvases for the purpose of creating a PDF file. To address some page-break issues, I have resorted to creating multiple c ...

What causes functions operating on mapped objects with computed keys to not correctly infer types?

If you are seeking a way to convert the keys of one object, represented as string literals, into slightly modified keys for another expected object in Typescript using template string literals, then I can help. In my version 4.9.5 implementation, I also ma ...

Encountering issues with browser tabs and Socket.IO

I'm currently working on a real-time chat using Socket.IO, but I've encountered a major issue. The aim is to allow users to log in, select another connected user, and start chatting... var http = require('http'), fs = require(&ap ...

The middleware is causing disruptions in the configuration of redis and express

I've recently started using Redis and I'm facing an issue with my middleware 'cache' function that seems to be causing problems in my code. Everything works fine without it, the data displays correctly in the browser, and when I check f ...

Is it possible to showcase D3 charts on an .epub file?

For my research project, I am exploring the possibilities of .epub files and experimenting with embedding JavaScript code to display data visualizations. I am currently using calibre to convert an HTML file containing D3 scatterplots into an .epub. The s ...

TypeScript - creating a dynamic instance of a new class with a custom

Looking to dynamically create new class objects in a loop with customizable names? For example, having classes like "tree": export default class ParentClass { // ... } export default class Thomas extends ParentClass { // ... } export default cla ...

Simple methods for ensuring a minimum time interval between observable emittance

My RxJS observable is set to emit values at random intervals ranging from 0 to 1000ms. Is there a way to confirm that there is always a minimum gap of 200ms between each emission without skipping or dropping any values, while ensuring they are emitted in ...

Creating dynamic fields for an ExtJS chart

Can chart axes be customized using setFields? I looked through the documentation for a method called setFields, but couldn't find one. While I was able to use setTitle on an axes, setting the field proved to be more challenging. I have a variable ca ...

Infinite scrolling made effortless with jQuery and Ajax

I am attempting to create a basic infinite scroll feature that monitors when the user scrolls to the bottom in an HTML file. Once the bottom is reached, it should then load additional content from another HTML file which contains more text. The second HTM ...

The People and Groups selection dialog is displaying incorrectly in IE 10

I've been working on a Sharepoint web application and have created a site column of type “People or Group”. This should be automatically associated with a user selection dialog as shown below: However, as you can see in the image above, the users ...

What are the steps for incorporating the AAD B2C functionality into an Angular2 application with TypeScript?

I recently built a web application using Angular2 and TypeScript, but now one of my clients wants to integrate Azure B2C for customer login instead of OAuth. I followed a simple example on how to implement Azure B2C in a .NET Web app through the link provi ...