You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: learn-pr/azure/enable-reliable-messaging-for-big-data-apps-using-event-hubs/includes/5-exercise-configure-applications-to-send-or-receive-messages-through-an-event-hub.md
+38-90Lines changed: 38 additions & 90 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
You're now ready to configure your publisher and consumer applications for your event hub.
2
2
3
-
In this unit, you configure applications to send or receive messages through your event hub. One application acts as the message sender (**SimpleSend**), the other as the message receiver (**EventProcessorSample**). Because these applications are written in Java, you can do all developing, test, and management in your browser. However, the same configuration must be used for each platform, such as .NET. The applications are stored in a GitHub repository.
3
+
In this unit, you configure applications to send or receive messages through your event hub. One application acts as the message sender (**SimpleSend**), the other as the message receiver (**EventProcessorSample**). The applications are stored in a GitHub repository.
4
4
5
5
## Create a general-purpose, standard storage account
6
6
@@ -28,7 +28,7 @@ In the previous exercise, we defined default values for resource group and locat
28
28
```
29
29
30
30
> [!TIP]
31
-
> It may take a moment to create this storage account. If storage account creation fails, change your environment variable, and try again.
31
+
> It can take a moment to create this storage account. If storage account creation fails, change your environment variable, and try again.
32
32
33
33
1. Run the following command to obtain the access keys associated with your storage account.
34
34
@@ -57,69 +57,44 @@ In the previous exercise, we defined default values for resource group and locat
57
57
```
58
58
59
59
## Clone the event hubs GitHub repository
60
+
The source files for the applications that you build in this unit are located in a [GitHub repository](https://github.com/Azure/azure-event-hubs).
60
61
61
-
In Cloud Shell, clone the event hubs GitHub repository with `git`. The source files for the applications that you build in this unit are located in a [GitHub repository](https://github.com/Azure/azure-event-hubs).
62
-
63
-
1. Run the following commands to make sure that you are in your home directory in Cloud Shell, and then to clone this repository.
62
+
1. Launch GitBash on your computer.
63
+
1. Run the following command to clone the Git project solution:
In this exercise, you use the built-in Cloud Shell editor to modify the SimpleSend application. You need to add your Event Hubs namespace, event hub name, shared access policy name, and primary key.
75
-
76
-
1. Change to the **SimpleSend** folder.
77
-
78
-
```bash
79
-
cd ~/azure-event-hubs/samples/Java/Basic/SimpleSend/src/main/java/com/microsoft/azure/eventhubs/samples/SimpleSend
80
-
```
81
-
82
-
1. Open Cloud Shell editor in the current folder.
83
-
84
-
```bash
85
-
code .
86
-
```
87
71
88
-
The files in the current folder are listed in the left-hand menu, and the editor space on the right side displays the contents of the filename listed in the title bar.
72
+
## Edit SimpleSend.java that sends events to the event hub
89
73
90
-
1. If not already open, open **SimpleSend.java** by selecting it from the file list.
74
+
In this exercise, you use Visual Studio Code (VS Code) to modify the SimpleSend application. You need to add your Event Hubs namespace, event hub name, shared access policy name, and primary key.
91
75
76
+
1. Launch VS Code.
77
+
1. Select **File** -> **Open Folder**, and select the **SimpleSend** folder under c:/users/USERID/azure-event-hubs/samples/java/basic.
78
+
1. In the Code Explorer in the left pane, double-click **SimpleSend.java** to open it in the editor.
92
79
1. In the editor, locate and replace the following strings under `ConnectionStringBuilder``:
93
80
94
-
- `"Your Event Hubs namespace name"` with the name of your Event Hubs namespace.
95
-
- `"Your Event Hub"` with the name of your event hub.
96
-
- `"Your policy name"` with **RootManageSharedAccessKey**.
97
-
- `"Your primary SAS key"` with the value of the **primaryKey** key for your Event Hubs namespace that you saved earlier.
98
-
99
-
If you forget these values, you can switch to the terminal window below the editor and run the `echo` command to list the environment variables. For example:
100
-
101
-
```bash
102
-
echo $NS_NAME
103
-
echo $HUB_NAME
104
-
echo $STORAGE_NAME
105
-
```
81
+
- `<EVENT HUBS NAMESPACE - CONNECTION STRING>` with the connection string to your Event Hubs namespace.
82
+
- `<EVENT HUB NAME>` with the name of your event hub.
106
83
107
84
For your primary SAS key, when you create an Event Hubs namespace, a 256-bit SAS key called **RootManageSharedAccessKey** is created and includes primary and secondary keys that grant send, listen, and manage rights to the namespace. Earlier in this exercise, you obtained the key by running an Azure CLI command; however, you can also find the keys and connection strings by selecting your Event Hubs namespace in the Azure portal, and then in the menu under the **Settings**, select **Shared access policies**; now select the policy name **RootManageSharedAccessKey** to display the SAS Policy keys.
85
+
1. Save the **SimpleSend.java** file.
108
86
109
-
1. Save the **SimpleSend.java** file, and then close the editor. Select in the upper right corner of the editor, and use the **Save** and **Close Editor** menu items.
110
-
111
-
:::image type="content" source="../media/5-save-and-close-editor.png" alt-text="Screenshot showing menu items to save the file and close the editor.":::
112
87
113
88
## Use Maven to build SimpleSend.java
114
89
115
90
Now, you build the Java application by running **mvn** commands.
116
91
117
-
1. In the Cloud Shell, enter the following command to navigate to the main **SimpleSend** folder.
92
+
1. In the Code Explorer, right-click **SimpleSend.java**, and select **Open in Integrated Terminal**.
93
+
1. Enter the following command to navigate to the main **SimpleSend** folder.
118
94
119
95
```bash
120
96
cd ~/azure-event-hubs/samples/Java/Basic/SimpleSend
121
97
```
122
-
123
98
1. Build the Java SimpleSend application. This command builds your application using the connection details for your event hub.
124
99
125
100
```bash
@@ -130,57 +105,34 @@ Now, you build the Java application by running **mvn** commands.
130
105
131
106

132
107
133
-
## Edit EventProcessorSample.java
108
+
## Edit EventProcessorSample.java that receives events to the event hub
134
109
135
110
You now configure a **receiver** (also known as a **subscriber** or **consumer**) application to ingest data from your event hub.
136
111
137
-
For the receiver application, two classes are available: **EventHubReceiver** and **EventProcessorHost**. EventProcessorHost is built on top of EventHubReceiver, but provides a simpler programmatic interface than EventHubReceiver. EventProcessorHost can automatically distribute message partitions across multiple instances of EventProcessorHost using the same storage account.
138
-
139
-
In this procedure, you use the `EventProcessorHost` method. You edit the EventProcessorSample application to add the following values: Your Event Hubs namespace, event hub name, shared access policy name and primary key, storage account name, connection string, and container name.
112
+
For the receiver application, two classes are available: **EventHubReceiver** and **EventProcessorClient**. EventProcessorClient is built on top of EventHubReceiver, but provides a simpler programmatic interface than EventHubReceiver. EventProcessorClient can automatically distribute message partitions across multiple instances of EventProcessorClient using the same storage account.
140
113
141
-
1. Change to the **EventProcessorSample** folder by running the following command.
114
+
In this procedure, you use the `EventProcessorClient` method. You edit the EventProcessorSample application to add the following values: Your Event Hubs namespace, event hub name, shared access policy name and primary key, storage account name, connection string, and container name.
142
115
143
-
```bash
144
-
cd ~/azure-event-hubs/samples/Java/Basic/EventProcessorSample/src/main/java/com/microsoft/azure/eventhubs/samples/eventprocessorsample
145
-
```
146
-
147
-
1. Open Cloud Shell editor.
148
-
149
-
```bash
150
-
code .
151
-
```
116
+
1. Launch another instance of the VS Code.
117
+
1. Select **File** -> **Open Folder**, and select the **EventProcessorSample** folder under c:/users/USERID/azure-event-hubs/samples/java/basic.
118
+
1. In the Code Explorer in the left pane, double-click **EventProcessorSample.java** to open it in the editor.
119
+
1. In the editor, locate and replace the following strings in the editor:
152
120
153
-
1. Select the **EventProcessorSample.java** file in the file explorer to the left.
121
+
- `<EVENT HUBS NAMESPACE - CONNECTION STRING>` - connection string to the Event Hubs namespace.
122
+
- `<EVENT HUB NAME>` - name of the event hub.
123
+
- `<AZURE STORAGE - CONNECTION STRING>` - connection string to the Azure Storage account.
124
+
- Confirm that the blob container name is **messages**. If you're using a different name for the container, use that name.
125
+
1. Save **EventProcessorSample.java**.
154
126
155
-
1. Locate and replace the following strings in the editor:
156
-
157
-
- `----EventHubNamespaceName----` with the name of your Event Hubs namespace.
158
-
- `----EventHubName----` with the name of your event hub.
159
-
- `----SharedAccessSignatureKeyName----` with **RootManageSharedAccessKey**.
160
-
- `----SharedAccessSignatureKey----` with the value of the **primaryKey** key for your Event Hubs namespace that you saved earlier.
161
-
- `----AzureStorageConnectionString----` with your storage account connection string that you saved earlier.
162
-
- `----StorageContainerName----` with **messages**.
163
-
- `----HostNamePrefix----` with the name of your storage account.
164
-
165
-
If you forget these values, you can switch to the terminal window below the editor and run the `echo` command to list the environment variables. For example:
166
-
167
-
```bash
168
-
echo $NS_NAME
169
-
echo $HUB_NAME
170
-
echo $STORAGE_NAME
171
-
```
172
-
1. Save **EventProcessorSample.java** either with the "..." menu, or the accelerator key (<kbd>Ctrl+S</kbd> on Windows and Linux, <kbd>Cmd+S</kbd> on macOS).
173
-
174
-
1. Close the editor.
175
127
176
128
## Use Maven to build EventProcessorSample.java
177
129
130
+
1. In the Code Explorer, right-click **EventProcessorSample.java**, and select **Open in Integrated Terminal**.
178
131
1. Change to the main **EventProcessorSample** folder by running the following command.
179
132
180
133
```bash
181
134
cd ~/azure-event-hubs/samples/Java/Basic/EventProcessorSample
182
135
```
183
-
184
136
1. Build the Java SimpleSend application by running the following command to ensure that your application uses the connection details for your event hub.
185
137
186
138
```bash
@@ -190,17 +142,21 @@ In this procedure, you use the `EventProcessorHost` method. You edit the EventPr
190
142
The build process can take several minutes to complete. Ensure that you see a **[INFO] BUILD SUCCESS** message before continuing.
1. Run the Java application from the command line by running the following `java` command, and specifying a .jar package. Run the following commands to start the SimpleSend application.
147
+
1. Start the EventProcessorSample application by running the following command.
148
+
149
+
```bash
150
+
cd ~/azure-event-hubs/samples/Java/Basic/EventProcessorSample
1. Switch to the VS Code window that has the sending application (SimpleSend) code open. In the integrated terminal, run the Java application from the command line by running the following `java` command, and specifying a .jar package.
197
154
198
155
```bash
199
156
cd ~/azure-event-hubs/samples/Java/Basic/SimpleSend
1. When messages stop appearing on the console, press <kbd>Enter</kbd> or press <kbd>CTRL+C</kbd> to end the program.
168
+
1. In the VS Code with the receiver application running, verify that you see messages. Press <kbd>Enter</kbd> or press <kbd>CTRL+C</kbd> to end the program.
0 commit comments