Skip to content

Commit 9773fb1

Browse files
committed
Review & update of ASA - Functions tutorial
1 parent b648506 commit 9773fb1

File tree

3 files changed

+171
-151
lines changed

3 files changed

+171
-151
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
title: include file
3+
description: include file
4+
services: event-hubs
5+
author: spelluru
6+
ms.service: event-hubs
7+
ms.topic: include
8+
ms.date: 02/27/2023
9+
ms.author: spelluru
10+
ms.custom: "include file"
11+
12+
---
13+
14+
## Sign in to Azure
15+
16+
Sign in to the [Azure portal](https://portal.azure.com).
17+
18+
## Create an event hub
19+
20+
Before Stream Analytics can analyze the fraudulent calls data stream, the data needs to be sent to Azure. In this tutorial, you'll send data to Azure by using [Azure Event Hubs](../event-hubs/event-hubs-about.md).
21+
22+
Use the following steps to create an event hub and send call data to that event hub:
23+
24+
1. Sign in to the [Azure portal](https://portal.azure.com/).
25+
2. Select **Create a resource** > **Internet of Things** > **Event Hubs**.
26+
27+
:::image type="content" source="media/stream-analytics-real-time-fraud-detection/find-event-hub-resource.png" alt-text="Screenshot showing the Event Hubs creation page.":::
28+
3. Fill out the **Create Namespace** pane with the following values:
29+
30+
|**Setting** |**Suggested value** |**Description** |
31+
|---------|---------|---------|
32+
|Subscription | \<Your subscription\> | Select an Azure subscription where you want to create the event hub. |
33+
|Resource group | MyASADemoRG | Select **Create New** and enter a new resource-group name for your account. |
34+
|Namespace name | asaTutorialEventHubNS | A unique name to identify the event hub namespace. |
35+
|Location | West US2 | Location where the event hub namespace can be deployed. |
36+
4. Use default options on the remaining settings and select **Review + create**. Then select **Create** to start the deployment.
37+
38+
:::image type="content" source="media/stream-analytics-real-time-fraud-detection/create-event-hub-namespace.png" alt-text="Screenshot showing the Create Namespace page.":::
39+
5. After the namespace is deployed successfully, select **Go to resource** to navigate to the **Event Hubs Namespace** page.
40+
6. On the **Event Hubs Namespace** page, select **+Event Hub** on the command bar.
41+
42+
:::image type="content" source="media/stream-analytics-real-time-fraud-detection/add-event-hub-button.png" alt-text="Screenshot showing the Add event hub button on the Event Hubs Namespace page.":::
43+
1. On the **Create Event Hub** page, enter a **Name** for the event hub. Set the **Partition Count** to 2. Use the default options in the remaining settings and select **Create**. Then wait for the deployment to succeed.
44+
45+
:::image type="content" source="media/stream-analytics-real-time-fraud-detection/create-event-hub-portal.png" alt-text="Screenshot showing the Create event hub page.":::
46+
47+
### Grant access to the event hub and get a connection string
48+
49+
Before an application can send data to Azure Event Hubs, the event hub must have a policy that allows access. The access policy produces a connection string that includes authorization information.
50+
51+
1. On the **Event Hubs Namespace**, select **Event Hubs** under **Entities** on the left menu, and then select the event hub you created.
52+
53+
:::image type="content" source="media/stream-analytics-real-time-fraud-detection/select-event-hub.png" alt-text="Screenshot showing the selection of an event hub on the Event Hubs page.":::
54+
1. On the **Event Hubs instance** page, select **Shared access policies** under **Settings** on the left menu, and then select **+ Add** on the command bar.
55+
2. Name the policy **MyPolicy**, ensure **Manage** is checked, and then select **Create**.
56+
57+
:::image type="content" source="media/stream-analytics-real-time-fraud-detection/create-event-hub-access-policy.png" alt-text="Screenshot showing Shared access policies page for an event hub.":::
58+
3. Once the policy is created, select the policy name to open the policy. Find the **Connection string–primary key**. Select the **copy** button next to the connection string.
59+
60+
![Save the shared access policy connection string](media/stream-analytics-real-time-fraud-detection/save-connection-string.png)
61+
62+
4. Paste the connection string into a text editor. You need this connection string in the next section.
63+
64+
The connection string looks as follows:
65+
66+
`Endpoint=sb://<Your event hub namespace>.servicebus.windows.net/;SharedAccessKeyName=<Your shared access policy name>;SharedAccessKey=<generated key>;EntityPath=<Your event hub name>`
67+
68+
Notice that the connection string contains multiple key-value pairs separated with semicolons: **Endpoint**, **SharedAccessKeyName**, **SharedAccessKey**, and **EntityPath**.
69+
70+
## Start the event generator application
71+
72+
Before you start the TelcoGenerator app, you should configure it to send data to the Azure Event Hubs you created earlier.
73+
74+
1. Extract the contents of [TelcoGenerator.zip](https://aka.ms/asatelcodatagen) file.
75+
2. Open the `TelcoGenerator\TelcoGenerator\telcodatagen.exe.config` file in a text editor of your choice There's more than one `.config` file, so be sure that you open the correct one.
76+
3. Update the `<appSettings>` element in the config file with the following details:
77+
78+
* Set the value of the **EventHubName** key to the value of the **EntityPath** at the end of the connection string.
79+
* Set the value of the **Microsoft.ServiceBus.ConnectionString** key to the connection string **without** the EntityPath value at the end. **Don't forget** to remove the semicolon that precedes the EntityPath value.
80+
4. Save the file.
81+
82+
5. Next open a command window and change to the folder where you unzipped the TelcoGenerator application. Then enter the following command:
83+
84+
```cmd
85+
.\telcodatagen.exe 1000 0.2 2
86+
```
87+
88+
This command takes the following parameters:
89+
* Number of call data records per hour.
90+
* Percentage of fraud probability, which is how often the app should simulate a fraudulent call. The value 0.2 means that about 20% of the call records will look fraudulent.
91+
* Duration in hours, which is the number of hours that the app should run. You can also stop the app at any time by ending the process (**Ctrl+C**) at the command line.
92+
93+
After a few seconds, the app starts displaying phone call records on the screen as it sends them to the event hub. The phone call data contains the following fields:
94+
95+
|**Record** |**Definition** |
96+
|---------|---------|
97+
|CallrecTime | The timestamp for the call start time. |
98+
|SwitchNum | The telephone switch used to connect the call. For this example, the switches are strings that represent the country/region of origin (US, China, UK, Germany, or Australia). |
99+
|CallingNum | The phone number of the caller. |
100+
|CallingIMSI | The International Mobile Subscriber Identity (IMSI). It's a unique identifier of the caller. |
101+
|CalledNum | The phone number of the call recipient. |
102+
|CalledIMSI | International Mobile Subscriber Identity (IMSI). It's a unique identifier of the call recipient. |
103+
104+
## Create a Stream Analytics job
105+
106+
Now that you have a stream of call events, you can create a Stream Analytics job that reads data from the event hub.
107+
108+
1. To create a Stream Analytics job, navigate to the [Azure portal](https://portal.azure.com/).
109+
2. Select **Create a resource** and search for **Stream Analytics job**. Select the **Stream Analytics job** tile and select **Create**.
110+
3. Fill out the **New Stream Analytics job** form with the following values:
111+
112+
|**Setting** |**Suggested value** |**Description** |
113+
|---------|---------|---------|
114+
|Subscription | \<Your subscription\> | Select an Azure subscription where you want to create the job. |
115+
|Resource group | MyASADemoRG | Select **Use existing** and enter a new resource-group name for your account. |
116+
|Job name | ASATutorial | A unique name to identify the event hub namespace. |
117+
|Location | West US2 | Location where the job can be deployed. It's recommended to place the job and the event hub in the same region for best performance and so that you don't pay to transfer data between regions. |
118+
|Hosting environment | Cloud | Stream Analytics jobs can be deployed to cloud or edge. **Cloud** allows you to deploy to Azure Cloud, and **Edge** allows you to deploy to an IoT Edge device. |
119+
|Streaming units | 1 | Streaming units represent the computing resources that are required to execute a job. By default, this value is set to 1. To learn about scaling streaming units, see [understanding and adjusting streaming units](stream-analytics-streaming-unit-consumption.md) article. |
120+
4. Use default options on the remaining settings, select **Create**, and wait for the deployment to succeed.
121+
122+
![Create an Azure Stream Analytics job](media/stream-analytics-real-time-fraud-detection/create-stream-analytics-job.png)
123+
5. After the job is deployed, select **Go to resource** to navigate to the **Stream Analytics job** page.
124+
125+
## Configure job input
126+
127+
The next step is to define an input source for the job to read data using the event hub you created in the previous section.
128+
129+
2. On the **Stream Analytics job** page, in the **Job Topology** section on the left menu, select **Inputs**.
130+
3. On the **Inputs** page, select **+ Add stream input** and **Event hub**.
131+
132+
:::image type="content" source="media/stream-analytics-real-time-fraud-detection/add-input-event-hub-menu.png" lightbox="media/stream-analytics-real-time-fraud-detection/add-input-event-hub-menu.png" alt-text="Screenshot showing the Input page for a Stream Analytics job.":::
133+
4. Fill out the input form with the following values:
134+
135+
|**Setting** |**Suggested value** |**Description** |
136+
|---------|---------|---------|
137+
|Input alias | CallStream | Provide a friendly name to identify your input. Input alias can contain alphanumeric characters, hyphens, and underscores only and must be 3-63 characters long. |
138+
|Subscription | \<Your subscription\> | Select the Azure subscription where you created the event hub. The event hub can be in same or a different subscription as the Stream Analytics job. |
139+
|Event hub namespace | asaTutorialEventHub | Select the event hub namespace you created in the previous section. All the event hub namespaces available in your current subscription are listed in the dropdown. |
140+
|Event hub name | MyEventHub | Select the event hub you created in the previous section. All the event hubs available in your current subscription are listed in the dropdown. |
141+
| Authentication mode | Connection string | In this tutorial, you'll use the connection string to connect to the event hub. |
142+
|Event hub policy name | MyPolicy | Select **Use existing**, and then select the policy you created earlier in this tutorial. |
143+
144+
4. Use default options on the remaining settings and select **Save**.
145+
146+
:::image type="content" source="media/stream-analytics-real-time-fraud-detection/configure-stream-analytics-input.png" alt-text="Screenshot showing the Event Hubs configuration page for an input.":::
147+
148+
## Create a consumer group
149+
150+
We recommend that you use a distinct consumer group for each Stream Analytics job. If no consumer group is specified, the Stream Analytics job uses the $Default consumer group. When a job contains a self-join or has multiple inputs, some inputs later might be read by more than one reader. This situation affects the number of readers in a single consumer group.
151+
152+
To add a new consumer group:
153+
154+
1. In the Azure portal, go to your Event Hubs instance.
155+
1. In the left menu, under **Entities**, select **Consumer groups**.
156+
1. Select **+ Consumer group** on the command bar.
157+
158+
:::image type="content" source="media/stream-analytics-real-time-fraud-detection/create-consumer-group.png" alt-text="Screenshot that shows creating a new consumer group.":::
159+
1. In **Name**, enter a name for your new consumer group. For example, *MyConsumerGroup*.
160+
1. Select **Create**.

0 commit comments

Comments
 (0)