@nestjstools/messaging-azure-service-bus-extension
Version:
Extension to handle messages and dispatch them over Azure service bus
53 lines • 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AzureServiceBusChannel = void 0;
const messaging_1 = require("@nestjstools/messaging");
const azure_service_bus_channel_config_1 = require("./azure-service-bus-channel.config");
const service_bus_1 = require("@azure/service-bus");
class AzureServiceBusChannel extends messaging_1.Channel {
client;
adminClient = undefined;
constructor(config) {
super(config);
this.client = new service_bus_1.ServiceBusClient(config.connectionString);
if (config.autoCreate) {
this.adminClient = new service_bus_1.ServiceBusAdministrationClient(config.connectionString);
}
if (azure_service_bus_channel_config_1.Mode.QUEUE === config.mode && !config.queue) {
throw new Error('For [Mode.QUEUE] property `queue` in config must be defined');
}
if (azure_service_bus_channel_config_1.Mode.TOPIC === config.mode && (!config.topic || !config.subscription)) {
throw new Error('For [Mode.TOPIC] properties `topic` and `subscription` in config must be defined');
}
}
isQueueMode() {
return azure_service_bus_channel_config_1.Mode.QUEUE === this.config.mode;
}
isTopicMode() {
return azure_service_bus_channel_config_1.Mode.TOPIC === this.config.mode;
}
getQueue() {
if (!this.config.queue) {
throw new Error('[queue] in config is not defined');
}
return this.config.queue;
}
getTopic() {
if (!this.config.topic) {
throw new Error('[topic] in config is not defined');
}
return this.config.topic;
}
getSubscription() {
if (!this.config.subscription) {
throw new Error('[subscription] in config is not defined');
}
return this.config.subscription;
}
async onChannelDestroy() {
await this.client.close();
return super.onChannelDestroy();
}
}
exports.AzureServiceBusChannel = AzureServiceBusChannel;
//# sourceMappingURL=azure-service-bus.channel.js.map