@azure/functions-extensions-servicebus

中文文档
0.5.1发布于 2026/05/12MITTypeScriptESM + CJS近 30 天下载 1.4万

Node.js Azure ServiceBus extension implementations for Azure Functions

原始使用文档
文档目录8 节
  1. Azure Functions Node.js Extensions - Service Bus
  2. Features
  3. Prerequisites
  4. Installation
  5. Usage
  6. Contributing
  7. License
  8. Resources

Azure Functions Node.js Extensions - Service Bus

This project provides extensions for working with Azure Service Bus in Azure Functions using Node.js. It simplifies the integration and interaction with Service Bus, enabling developers to build scalable and efficient serverless applications.

Features

  • Service Bus Trigger: Automatically trigger Azure Functions when messages arrive in queues or subscriptions.
  • Service Bus Input Binding: Read Service Bus messages as input to your function.
  • Service Bus Output Binding: Send messages to Service Bus queues and topics.
  • Cached Client Management: Optimized client reuse with intelligent caching
  • Resource Management: Proper disposal patterns for Azure resource clients
  • Performance Optimizations: Reduced overhead for messaging operations

Prerequisites

Installation

To install the required dependencies, run:

npm install @azure/functions-extensions-servicebus

Usage

  1. Set up your Azure Service Bus namespace:
  • Create a Service Bus namespace in the Azure portal.
  • Create queues, topics, and subscriptions as needed.
  1. Configure your function:
  • Update the function.json file to include the appropriate bindings for Service Bus.
  1. Import and initialize the extension:
import '@azure/functions-extensions-servicebus'; // Ensures at the top of the file

Using in Azure Functions

import "@azure/functions-extensions-servicebus";
import { ServiceBusMessageContext } from "@azure/functions-extensions-servicebus"
import { app, InvocationContext } from "@azure/functions";

export async function serviceBusTrigger1(
  serviceBusMessageContext: ServiceBusMessageContext, 
  context: InvocationContext
): Promise<void> {
  try {
    // Log trigger metadata
    context.log("triggerMetadata: ", context.triggerMetadata);
    
    // Process the first message (messages is always an array)
    const message = serviceBusMessageContext.messages[0];
    context.log('Completing the message', message);
    
    // Use serviceBusMessageActions to action on the messages
    await serviceBusMessageContext.actions.complete(message);
    context.log('Completing the body', message.body);
  } catch (error) {
    context.log('Error processing Service Bus message:', error);
  }
}

app.serviceBusQueue("serviceBusTrigger", {
  connection: "AzureWebJobsServiceBus",
  queueName: "testqueue",
  cardinality: "many",
  sdkBinding: true, //Ensure this is set to true
  autoCompleteMessages: false, //Exposing this so that customer can take action on the messages
  handler: serviceBusTrigger1,
});

// https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus?tabs=isolated-process%2Cextensionv5&pivots=programming-language-javascript
// autoCompleteMessages

  1. Run locally:
  • Use the Azure Functions Core Tools to run your function locally:
func start
  1. Deploy to Azure:
  • Deploy your function to Azure using the following command:
func azure functionapp publish <YourFunctionAppName>

Contributing

Contributions are welcome! Please follow the contribution guidelines when submitting issues or pull requests.

License

This project is licensed under the MIT License.

Resources

版本与发布记录

@azure/functions-extensions-servicebus 共发布 13 个版本,首次发布于 2025/07/24;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.5.1latest2026/05/125 个月前
0.5.02026/04/096 个月前
0.4.12026/03/177 个月前
0.4.02026/02/138 个月前
0.3.6-preview2025/12/0311 个月前
0.3.5-preview2025/10/281 年前

关于 @azure/functions-extensions-servicebus 的常见问题

@azure/functions-extensions-servicebus 是什么?

Node.js Azure ServiceBus extension implementations for Azure Functions

如何安装 @azure/functions-extensions-servicebus?

在项目目录运行 npm install @azure/functions-extensions-servicebus,或使用 pnpm add / yarn add / bun add。

@azure/functions-extensions-servicebus 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@azure/functions-extensions-servicebus 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@azure/functions-extensions-servicebus 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@azure/functions-extensions-servicebus 可以商用吗?

@azure/functions-extensions-servicebus 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@azure/functions-extensions-servicebus 的下载量有多少?

根据 npm 官方下载统计,@azure/functions-extensions-servicebus 在 2026/10/08 – 2026/11/06 这 30 天内被下载 14,150 次,日均约 472 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@azure/functions-extensions-servicebus 还在维护吗?

最新版本 0.5.1 发布于 2026/05/12(5 个月前);至今共发布 13 个版本,其中过去 12 个月发布了 5 个;首次发布于 2025/07/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。