Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
556 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I cannot receive messages from a topic subscription unless I enable the dead letter queue. Here is a simple example of how I am trying to receive the messages. Thanks for any help.
import "dotenv/config"
import {
ServiceBusClient,
ServiceBusReceiver,
} from "@azure/service-bus";
const topicName = "event-topic";
const topicSub = "event-topic-sub";
let sbClient: ServiceBusClient;
let receiver: ServiceBusReceiver;
async function main() {
const connectionString = process.env.SERVICEBUS_CONNECTION_STRING
if (!connectionString) {
throw new Error("Missing connection string");
}
sbClient = new ServiceBusClient(connectionString);
console.log(`Receiving messages from topic ${topicName} with subscription ${topicSub}`);
receiver = sbClient.createReceiver(topicName, topicSub);
receiver.subscribe({
processMessage: async (msg) => {
console.log(`Received message: Action: ${msg.body.orderAction}, OrderId: ${msg.body.order.id}`);
},
processError: async (err) => {
console.log(err);
}
});
}
main().
catch((err) => console.log(err))
.finally(() => {
receiver?.close();
sbClient?.close()
});