Topic subscriptions are not receiving any messages unless the DLQ is enabled

Rafael Wolf 0 Reputation points
2024-04-30T17:45:26.5166667+00:00

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()
    });
Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
556 questions
0 comments No comments
{count} votes