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

Is there a more efficient method for translating arrays between JavaScript and PHP?

Currently, I am in the process of developing a web page that has the capability to read, write, and modify data stored in a MySQL database. My approach involves utilizing PHP with CodeIgniter for handling queries while using JavaScript to dynamically updat ...

Text in Angular vanishes upon reopening

I have a code snippet where I am trying to allow the user to edit and save a paragraph displayed on a side panel of the main page. Although the code works fine, allowing users to update the text and see it reflected in the network upon saving, there seems ...

Strange activities observed during the management of state in react hooks, where the splice() function ends up eliminating the

My current setup involves maintaining a state to handle the addition of new JSX elements: const [display, setDisplay] = useState<IDisplay>({ BookingFormDropDown: [], } ); I have a function in onClick() which adds an elem ...

What's causing jQuery to make the entire page malfunction?

I am experiencing an issue where a function is not recognized as being in scope when I have a reference to jQuery defined. Oddly enough, if I comment out that reference, the function call works just fine. I have other pages set up the same way with jQuer ...

Learn how to render a single element with multiple child elements within separate `<td>` tags in a table row using React

I'm just starting out with React and I have a code snippet that I'm using to render an HTML table in a component. Is there a more optimized way to achieve this? bodyItems = sorted.map((data) => [ data.employerName, data.sectors.map((sector ...

Angular is unable to eliminate the focus outline from a custom checkbox created with Boostrap

Have you noticed that Angular doesn't blur out the clicked element for some strange reason? Well, I came up with a little 'fix' for it: *:focus { outline: none !important; } It's not a perfect solution because ideally every element sh ...

What is preventing me from using javascript setInterval with a function in a separate external file?

Everything is running smoothly with this code snippet...an alert pops up every 10 seconds <script type='text/javascript'> function letsTest(){ alert("it works"); } var uptimeId = window.setInterval(letsTest, 10000); < ...

Is it possible to swap out the content within a <div> element with an external piece of HTML code using JQuery or JavaScript whenever the viewport dimensions are adjusted?

<html> <head> </head> function () { var viewportWidth = $(window).width(); if (viewportWidth < 700) { $('#wrapper').load('A.html'); }; <body> &l ...

TypeScript encountered an error with code TS2554, indicating that it was expecting 0 arguments but instead received 1 in an Ionic application

Hello everyone! I'm encountering an issue in my project involving a Type Script error TS2554: Expected 0 arguments, but got 1. This error is preventing me from being able to select other options for custom input pop up. In this forum post, I have shar ...

The attribute interface overload in Typescript is an important concept to

Consider a scenario where there are multiple payload options available: interface IOne { type: 'One', payload: { name: string, age: number } } interface ITwo { type: 'Two', payload: string } declare type TBoth = IOne ...

Utilize the reducer from another slice in Redux Toolkit

I am working with an authSlice const authSlice = createSlice({ name: 'authStore', initialState, reducers: { logout(state = initialState) { return { ...state, isAuthenticated: false }; }, }, extraReducers: (builder) => { ...

The functionality of sending form data via Express.js router is restricted

In my current project, I am developing a basic CRUD functionality in express. My goal is to utilize the express.Router() to transmit form data via the HTTP POST method. The form structure on the browser appears as follows: form.png The process was flawle ...

Populate HTML form with return values using jQuery AJAX

I am struggling with retrieving values from jQuery/AJAX and displaying them in an HTML form within the index.php file. This is what my index.php looks like: <script type="text/javascript"> $(document).ready(function () { $('#display'). ...

Error: Unable to convert null or undefined to an object | NextAuth

Recently, I've been attempting to implement a SignIn feature with Nextauth using the following code: import { getProviders, signIn as SignIntoProvider} from "next-auth/react"; function signIn({ providers }) { return ( <> ...

The plugin "react" encountered a conflict while trying to sync with both the "package.json" and the "BaseConfig" files

Whenever I open Terminal in my react folder and try to start the react app using npm start, I always end up encountering an error on the browser. The error message states that the "react" plugin is conflicting between two paths: "package.json » eslint ...

The issue arises when the logout component fails to render even after the user has been authenticated. This problem resembles the one discussed in the React Router

While attempting to run the react-router docs example on the browser, I encountered an issue with the AuthButton component. The problem arises when the isAuthenticated value changes to true but the signOut button fails to display. import React from ' ...

What is the best way to conceal a dropdown menu when the page first loads?

I have a dropdown menu that is displaying like this: <ul> <li class="dropdown open"> <a aria-expanded="true" href="#" class="dropdown-toggle waves-effect waves-button waves-classic" data-toggle="dropdown"> <spa ...

"Learn how to transfer a selected value from a parent ASP.NET dropdownlist to a textbox in a popup window using JavaScript

I'm struggling to pass the value from a dropdown list in the parent ASPX form to a textbox in the child ASPX form. Parent JavaScript: The first script is used to open the popup window <script type="text/javascript"> var popup; ...

Retrieving the data from a Material UI Slider control

I'm encountering an issue with retrieving the value property I assigned to a component. event.target.value is returning undefined. How can I successfully access the value of the component? My goal is for handlePlayersChange() to be able to handle dyn ...

A guide to finding the mean in Angular by utilizing JSON information

import { Component, OnInit } from "@angular/core"; import { MarkService } from "../app/services/marks.service"; @Component({ selector: "app-root", templateUrl: "./app.component.html", styleUrls: ["./app.component.scss"] }) export class AppComp ...