Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,47 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

dist
out
pkg
*.tgz

**/*-test-results.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ModelBindingData {
version?: string | null;
}

export type ResourceFactory = (modelBindingData: ModelBindingData) => unknown;
export type ResourceFactory = (modelBindingData: ModelBindingData | ModelBindingData[]) => unknown;

export class ResourceFactoryResolver {
private constructor();
Expand Down
49 changes: 49 additions & 0 deletions azure-functions-nodejs-extensions-servicebus/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "header", "deprecation", "simple-import-sort", "import"],
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended"
],
"rules": {
"header/header": [
2,
"line",
[" Copyright (c) .NET Foundation. All rights reserved.", " Licensed under the MIT License."],
2
],
"deprecation/deprecation": "error",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "ignoreRestSiblings": true }],
"prefer-const": ["error", { "destructuring": "all" }],
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "no-public"
}
],
"no-return-await": "off",
"@typescript-eslint/return-await": "error",
"eqeqeq": "error",
"@typescript-eslint/no-empty-function": "off",
"simple-import-sort/imports": [
"error",
{
"groups": [["^\\u0000", "^node:", "^@?\\w", "^", "^\\."]]
}
],
"simple-import-sort/exports": "error",
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error"
},
"ignorePatterns": ["**/*.js", "**/*.mjs", "**/*.cjs", "out", "dist"]
}
6 changes: 6 additions & 0 deletions azure-functions-nodejs-extensions-servicebus/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
out
dist
node_modules

# Exclude markdown until this bug is fixed: https://github.com/prettier/prettier/issues/5019
*.md
6 changes: 6 additions & 0 deletions azure-functions-nodejs-extensions-servicebus/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 4,
"singleQuote": true,
"printWidth": 120,
"endOfLine": "auto"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
19 changes: 19 additions & 0 deletions azure-functions-nodejs-extensions-servicebus/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
},
{
"name": "Launch Unit Tests",
"runtimeExecutable": "npm",
"runtimeArgs": ["test"],
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"type": "node"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"azureFunctions.showProjectWarning": false,
"editor.codeActionsOnSave": ["source.fixAll"],
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.preferences.importModuleSpecifier": "relative"
}
25 changes: 25 additions & 0 deletions azure-functions-nodejs-extensions-servicebus/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "npm: watch",
"type": "npm",
"script": "watch",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$ts-checker-webpack-watch"],
"isBackground": true,
"presentation": {
"reveal": "never"
}
},
{
"type": "npm",
"script": "lint",
"problemMatcher": "$eslint-stylish",
"label": "npm: lint"
}
]
}
25 changes: 25 additions & 0 deletions azure-functions-nodejs-extensions-servicebus/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributing

- Clone the repository locally and open in VS Code
- Run "Extensions: Show Recommended Extensions" from the [command palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) and install all extensions listed under "Workspace Recommendations"
- Run `npm install`
- Run `npm run build`
- Run `npm link`
- Create or open a local function app to test with
- In the local function app:
- Follow the steps in the "Usage" section of the README for this repo
- Run `npm link @azure/functions-extensions-servicebus`. This will point your app to the local repository for the `@azure/functions-extensions-servicebus` package
- Add the following settings to your "local.settings.json" file or configure them directly as environment variables
- `languageWorkers__node__arguments`: `--inspect`
> 💡 Tip: Set `logging__logLevel__Worker` to `debug` if you want to view worker-specific logs in the output of `func start`
- Start the app (i.e. run `func start` or press <kbd>F5</kbd>)
- Back in this repository, press <kbd>F5</kbd> and select the process for your running function app
- Before you submit a PR, run `npm test` and fix any issues. If you want to debug the tests, switch your [launch profile](https://code.visualstudio.com/docs/editor/debugging) in VS Code to "Launch Unit Tests" and press <kbd>F5</kbd>.

## Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

## Contributing to type definitions

The type definitions are located in the `types` folder. Please make sure to update the tests in `./test/types/index.test.ts` as well.
21 changes: 21 additions & 0 deletions azure-functions-nodejs-extensions-servicebus/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) .NET Foundation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
105 changes: 105 additions & 0 deletions azure-functions-nodejs-extensions-servicebus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
## 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

- [Node.js](https://nodejs.org/) (LTS version recommended)
- [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local)
- An active [Azure subscription](https://azure.microsoft.com/free/)

### Installation

To install the required dependencies, run:

```bash
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.

2. **Configure your function**:

- Update the `function.json` file to include the appropriate bindings for Service Bus.

3. **Import and initialize the extension:**

```javascript
import '@azure/functions-extensions-servicebus'; // Ensures at the top of the file
```

Using in Azure Functions

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

export async function serviceBusTrigger1(
serviceBusClient: ServiceBusClient,
message: unknown,
context: InvocationContext
): Promise<void> {
context.log(
`Service Bus function processed message: ${JSON.stringify(message)}`
);
try {
//Actual Message
context.log("triggerMetadata: ", context.triggerMetadata);
context.log('Completing the message', serviceBusMessageManager.messages[0]);
//Use serviceBusMessageActions to action on the messages
await serviceBusMessageManager.serviceBusMessageActions.complete(serviceBusMessageManager.messages[0]);
context.log('Completing the body', serviceBusMessageManager.messages[0].body);
}
}

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

4. **Run locally**:

- Use the Azure Functions Core Tools to run your function locally:
```bash
func start
```

5. **Deploy to Azure**:

- Deploy your function to Azure using the following command:
```bash
func azure functionapp publish <YourFunctionAppName>
```

### Contributing

Contributions are welcome! Please follow the [contribution guidelines](CONTRIBUTING.md) when submitting issues or pull requests.

### License

This project is licensed under the [MIT License](LICENSE).

### Resources

- [Azure Functions Documentation](https://learn.microsoft.com/azure/azure-functions/)
- [Azure Service Bus Documentation](https://learn.microsoft.com/azure/service-bus-messaging/)
- [Azure SDK for JavaScript](https://learn.microsoft.com/azure/javascript/)
41 changes: 41 additions & 0 deletions azure-functions-nodejs-extensions-servicebus/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.7 BLOCK -->

## Security

Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).

If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.

## Reporting Security Issues

**Please do not report security vulnerabilities through public GitHub issues.**

Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).

If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.

## Preferred Languages

We prefer all communications to be in English.

## Policy

Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).

<!-- END MICROSOFT SECURITY.MD BLOCK -->
Loading