-
Notifications
You must be signed in to change notification settings - Fork 0
Azure Functions Service Bus Extensions with Message Settlement #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
08cbd57
Initial comments to handle single message
swapnil-nagar baf8d64
Adding the singleton for the MessageActions
swapnil-nagar 54db34a
Adding unit tests
swapnil-nagar b44b236
Fixing Unit tests and dependencies.
swapnil-nagar ecb6b61
Fixing the Rhea Library Issue
swapnil-nagar 48d4e00
Fixing code review comment and tranforming the servicebus message to …
swapnil-nagar 0a3aded
Updating package.json
swapnil-nagar 7e6d987
Code comments improvements
swapnil-nagar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
azure-functions-nodejs-extensions-servicebus/.eslintrc.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "tabWidth": 4, | ||
| "singleQuote": true, | ||
| "printWidth": 120, | ||
| "endOfLine": "auto" | ||
| } |
3 changes: 3 additions & 0 deletions
3
azure-functions-nodejs-extensions-servicebus/.vscode/extensions.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
19
azure-functions-nodejs-extensions-servicebus/.vscode/launch.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| ] | ||
| } |
8 changes: 8 additions & 0 deletions
8
azure-functions-nodejs-extensions-servicebus/.vscode/settings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
25
azure-functions-nodejs-extensions-servicebus/.vscode/tasks.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
25
azure-functions-nodejs-extensions-servicebus/CONTRIBUTING.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
swapnil-nagar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - **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/) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 --> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.