Skip to content

Commit f11eac6

Browse files
committed
update
1 parent 41b75af commit f11eac6

File tree

1 file changed

+38
-90
lines changed

1 file changed

+38
-90
lines changed

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

Lines changed: 38 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
You're now ready to configure your publisher and consumer applications for your event hub.
22

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.
44

55
## Create a general-purpose, standard storage account
66

@@ -28,7 +28,7 @@ In the previous exercise, we defined default values for resource group and locat
2828
```
2929
3030
> [!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.
3232
3333
1. Run the following command to obtain the access keys associated with your storage account.
3434
@@ -57,69 +57,44 @@ In the previous exercise, we defined default values for resource group and locat
5757
```
5858
5959
## 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).
6061
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:
6464
6565
```bash
6666
cd ~
6767
git clone https://github.com/Azure/azure-event-hubs.git
6868
```
69+
1. Launch VS Code on your computer.
6970
70-
The repository is cloned to your home folder.
71-
72-
## Edit SimpleSend.java
73-
74-
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-
```
8771
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
8973
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.
9175
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.
9279
1. In the editor, locate and replace the following strings under `ConnectionStringBuilder``:
9380
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.
10683
10784
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.
10886
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.":::
11287
11388
## Use Maven to build SimpleSend.java
11489
11590
Now, you build the Java application by running **mvn** commands.
11691
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.
11894
11995
```bash
12096
cd ~/azure-event-hubs/samples/Java/Basic/SimpleSend
12197
```
122-
12398
1. Build the Java SimpleSend application. This command builds your application using the connection details for your event hub.
12499
125100
```bash
@@ -130,57 +105,34 @@ Now, you build the Java application by running **mvn** commands.
130105
131106
![Build results for sender application.](../media/5-sender-build.png)
132107
133-
## Edit EventProcessorSample.java
108+
## Edit EventProcessorSample.java that receives events to the event hub
134109
135110
You now configure a **receiver** (also known as a **subscriber** or **consumer**) application to ingest data from your event hub.
136111
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.
140113
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.
142115
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:
152120
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**.
154126
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.
175127
176128
## Use Maven to build EventProcessorSample.java
177129
130+
1. In the Code Explorer, right-click **EventProcessorSample.java**, and select **Open in Integrated Terminal**.
178131
1. Change to the main **EventProcessorSample** folder by running the following command.
179132
180133
```bash
181134
cd ~/azure-event-hubs/samples/Java/Basic/EventProcessorSample
182135
```
183-
184136
1. Build the Java SimpleSend application by running the following command to ensure that your application uses the connection details for your event hub.
185137
186138
```bash
@@ -190,17 +142,21 @@ In this procedure, you use the `EventProcessorHost` method. You edit the EventPr
190142
The build process can take several minutes to complete. Ensure that you see a **[INFO] BUILD SUCCESS** message before continuing.
191143
192144
:::image type="content" source="../media/5-receiver-build.png" alt-text="Build results for receiver application." loc-scope="other"::: <!-- no-loc -->
193-
194145
## Start the sender and receiver apps
195146
196-
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
151+
java -jar ./target/eventprocessorsample-1.0.0-jar-with-dependencies.jar
152+
```
153+
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.
197154
198155
```bash
199156
cd ~/azure-event-hubs/samples/Java/Basic/SimpleSend
200157
java -jar ./target/simplesend-1.0.0-jar-with-dependencies.jar
201158
```
202-
203-
1. When you see **Send Complete...**, press <kbd>Enter</kbd>.
159+
1. When you see **Send Complete...**, <kbd>Enter</kbd> to stop the application.
204160
205161
```output
206162
jar-with-dependencies.jar
@@ -209,15 +165,7 @@ In this procedure, you use the `EventProcessorHost` method. You edit the EventPr
209165
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
210166
2018-09-18T19:42:15.146Z: Send Complete...
211167
```
212-
213-
1. Start the EventProcessorSample application by running the following command.
214-
215-
```bash
216-
cd ~/azure-event-hubs/samples/Java/Basic/EventProcessorSample
217-
java -jar ./target/eventprocessorsample-1.0.0-jar-with-dependencies.jar
218-
```
219-
220-
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.
221169
222170
```output
223171
...

0 commit comments

Comments
 (0)