Skip to content

Commit

Permalink
feat: updated content for module 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayzrian committed Nov 20, 2023
1 parent 5b1a6d0 commit 39d475e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 deletions.
54 changes: 53 additions & 1 deletion docs/06-servicebus/05-integration-with-function-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,56 @@ sidebar_position: 5

# Integration with Function App

TODO: Add content

## Integration with Service Bus Using Bindings

Here's an example of how you can integrate an Azure Function App with an Azure Service Bus using triggers.

1. Specify a trigger to use [Service Bus](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=python-v2%2Cisolated-process%2Cnodejs-v3%2Cextensionv5&pivots=programming-language-typescript) in `function.json`
2. Implement a business logic
3. Test it with help of `http://localhost:<PORT>/admin/functions/<FUNCTION_NAME>` endpoints, for more detailed instructions read [here](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Cisolated-process%2Cnode-v3%2Cpython-v2%2Cnon-http-trigger%2Ccontainer-apps&pivots=programming-language-typescript).

## Integration with Azure Storage Using Azure Service Bus SDK

Alternatively, you can manually interact with Azure Service Bus using the Azure Service Bus SDK. Here's an example:

1. Install Azure Storage SDK `npm install @azure/service-bus`
2. Azure Function business logic to interact with Service Bus
```javascript
const { ServiceBusClient } = require("@azure/service-bus");

module.exports = async function (context, req) {
// Don't forget to specify env variables :)
const serviceBusConnectionString = process.env.ServiceBusConnectionString;
const queueName = "your-queue-name";

const serviceBusClient = new ServiceBusClient(serviceBusConnectionString);
const sender = serviceBusClient.createSender(queueName);

try {
const messageBody = "Hello, Service Bus!";
const message = {
body: messageBody,
label: "greeting",
};

// Send a message to the Service Bus queue
await sender.sendMessages(message);
context.res = {
status: 200,
body: "Message sent successfully to Service Bus queue.",
};
} catch (error) {
context.res = {
status: 500,
body: `Error sending message to Service Bus: ${error.message}`,
};
} finally {
await sender.close();
await serviceBusClient.close();
}
};

```

In this example, the function is triggered by an HTTP request and sends messages to Service Bus queue.
15 changes: 9 additions & 6 deletions docs/06-servicebus/06-reading-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ sidebar_position: 6
3. Dead-lettering and Scheduling: https://learn.microsoft.com/en-us/azure/service-bus-messaging/advanced-features-overview
4. Architecture: https://hevodata.com/learn/azure-service-bus/
5. Metrics: https://learn.microsoft.com/en-us/azure/service-bus-messaging/monitor-service-bus-reference
6. REST API: https://learn.microsoft.com/en-us/rest/api/servicebus/
7. CLI: https://learn.microsoft.com/en-us/cli/azure/servicebus?view=azure-cli-latest
8. Tutorials: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues?tabs=passwordless
9. Managed Identity: https://learn.microsoft.com/en-us/azure/stream-analytics/service-bus-managed-identity
10. Built-in Roles: https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles
11. Error Codes: https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.exceptionerrorcodes?view=azure-dotnet
6. Managed Identity: https://learn.microsoft.com/en-us/azure/stream-analytics/service-bus-managed-identity
7. Built-in Roles: https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles
8. Error Codes: https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.exceptionerrorcodes?view=azure-dotnet

## Nice to have

1. REST API: https://learn.microsoft.com/en-us/rest/api/servicebus/
2. CLI: https://learn.microsoft.com/en-us/cli/azure/servicebus?view=azure-cli-latest
3. Tutorials: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues?tabs=passwordless
11 changes: 4 additions & 7 deletions docs/06-servicebus/07-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@
sidebar_position: 7
---

# Prereqs
# Task

- The task is continuation of Task #5;
- The goal is to create a service to be able to save products which were provided in csv file to the Cosmos DB.


# Tasks
---

## Task 6.1
1. Create a service-bus and create topic with a subscription.
2. In the products-service create a function that will be triggered by a service-bus.
1. Create a service-bus and create a queue.
2. In the `products-service` create a function `service-bus-import-product` that will be triggered by a service-bus.
3. The function should insert each product into the Cosmos DB.

## Task 6.2
1. Update the `blob-import-products-from-file` to push the products to the service-bus topic created previously.
2. Remove the logs that included each product.

## Task 6.3
TODO: UPD to send emails

## Task 6.4

1. Commit all your work to separate branch (e.g. `task-6` from the latest `master`) in BE (backend) and if needed in FE (frontend) repositories.
2. Create a pull request to the `master` branch.
Expand All @@ -40,6 +36,7 @@ Reviewers should verify the functions by invoking them through provided URLs.
## Optional Tasks

- **+10** - The functions are covered with unit tests
- **+20** - Service Bus Topic with multiple subscriptions is used. A subscription has a filter by property.

# Description Template for PRs
---
Expand Down
3 changes: 3 additions & 0 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ Each section/module consists of:
- Reading list. A selected list of documentation and articles that you need to read to have a better understanding on the topic.
- Recommendations and crux. Sections that provide summaries and teach you how to assemble different pieces together and how to build systems.
- Practical task. A practical task that you need to implement as your assignment (usually referred as home task).

## Example of solution
In case you stuck with implementation and need to look up how to do something, feel free to use [this example of solution](https://github.com/EPAM-JS-Competency-center/shop-nodejs-azure-serverless).

0 comments on commit 39d475e

Please sign in to comment.