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: articles/event-hubs/event-hubs-quickstart-kafka-enabled-event-hubs.md
+61-76Lines changed: 61 additions & 76 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,10 @@ To complete this quickstart, make sure you have the following prerequisites:
19
19
20
20
* Read through the [Event Hubs for Apache Kafka](event-hubs-for-kafka-ecosystem-overview.md) article.
21
21
* An Azure subscription. If you don't have one, create a [free account](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio) before you begin.
22
-
*[Java Development Kit (JDK) 1.7+](/azure/developer/java/fundamentals/java-support-on-azure).
23
-
*[Download](https://maven.apache.org/download.cgi) and [install](https://maven.apache.org/install.html) a Maven binary archive.
24
-
*[Git](https://www.git-scm.com/)
25
-
* To run this quickstart using managed identity, you need to run it on an Azure virtual machine.
22
+
*Create a Windows virtual machine and install the following components:
23
+
*[Java Development Kit (JDK) 1.7+](/azure/developer/java/fundamentals/java-support-on-azure).
24
+
*[Download](https://maven.apache.org/download.cgi) and [install](https://maven.apache.org/install.html) a Maven binary archive.
25
+
*[Git](https://www.git-scm.com/)
26
26
27
27
## Create an Event Hubs namespace
28
28
@@ -34,78 +34,63 @@ When you create an Event Hubs namespace, the Kafka endpoint for the namespace is
34
34
## Send and receive messages with Kafka in Event Hubs
1. Managed identities for Azure resources provide Azure services with an automatically managed identity in Azure Active Directory. You can use this identity to authenticate to any service that supports Azure AD authentication, without having credentials in your code.
39
-
40
-
Azure Event Hubs supports using Azure Active Directory (Azure AD) to authorize requests to Event Hubs resources. With Azure AD, you can use Azure role-based access control (Azure RBAC) to grant permissions to a security principal, which may be a user, or an application service principal.
41
-
42
-
To use Managed Identity, you can create or configure a virtual machine using a system-assigned managed identity. For more information about configuring managed identity on a VM, see [Configure managed identities for Azure resources on a VM using the Azure portal](../active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm.md#system-assigned-managed-identity).
43
-
44
-
1. In the virtual machine that you configure managed identity, clone the [Azure Event Hubs for Kafka repository](https://github.com/Azure/azure-event-hubs-for-kafka).
45
-
46
-
1. Navigate to *azure-event-hubs-for-kafka/quickstart/java/producer*.
47
-
48
-
1. Update the configuration details for the producer in *src/main/resources/producer.config* as follows:
49
-
50
-
After you configure the virtual machine with managed identity, you need to add managed identity to Event Hubs namespace. For that you need to follow these steps.
51
-
52
-
* In the Azure portal, navigate to your Event Hubs namespace. Go to **Access Control (IAM)** in the left navigation.
53
-
54
-
* Select **Add** and select `Add role assignment`.
55
-
56
-
* In the **Role** tab, select **Azure Event Hubs Data Owner**, then select **Next**=.
57
-
58
-
* In the **Members** tab, select the **Managed Identity** radio button for the type to assign access to.
59
-
60
-
* Select the **Select members** link. In the **Managed Identity** dropdown, select **Virtual Machine**, then select your virtual machine's managed identity.
61
-
62
-
* Select **Review + Assign**.
63
-
64
-
1. After you configure managed identity, you can update *src/main/resources/producer.config* as shown below.
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/producer/src/main/java).
75
-
76
-
1. Run the producer code and stream events into Event Hubs:
77
-
78
-
```shell
79
-
mvn clean package
80
-
mvn exec:java -Dexec.mainClass="TestProducer"
81
-
```
82
-
83
-
1. Navigate to *azure-event-hubs-for-kafka/quickstart/java/consumer*.
84
-
85
-
1. Update the configuration details for the consumer in *src/main/resources/consumer.config* as follows:
86
-
87
-
1. Make sure you configure managed identity as mentioned in step 3 and use the following consumer configuration.
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/consumer/src/main/java).
98
-
99
-
You can find all the OAuth samples for Event Hubs for Kafka [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth).
100
-
101
-
1. Run the consumer code and process events from event hub using your Kafka clients:
102
-
103
-
```java
104
-
mvn clean package
105
-
mvn exec:java -Dexec.mainClass="TestConsumer"
106
-
```
107
-
108
-
If your Event Hubs Kafka cluster has events, you now start receiving them from the consumer.
37
+
1. Enable a system-assigned managed identity for the virtual machine. For more information about configuring managed identity on a VM, see [Configure managed identities for Azure resources on a VM using the Azure portal](../active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm.md#system-assigned-managed-identity). Managed identities for Azure resources provide Azure services with an automatically managed identity in Azure Active Directory. You can use this identity to authenticate to any service that supports Azure AD authentication, without having credentials in your code.
38
+
39
+
:::image type="content" source="./media/event-hubs-quickstart-kafka-enabled-event-hubs/enable-identity-vm.png" alt-text="Screenshot of the Identity tab of a virtual machine page in the Azure portal.":::
40
+
1. Using the **Access control** page of the Event Hubs namespace you created, assign **Azure Event Hubs Data Owner** role to the VM's managed identity.
41
+
Azure Event Hubs supports using Azure Active Directory (Azure AD) to authorize requests to Event Hubs resources. With Azure AD, you can use Azure role-based access control (Azure RBAC) to grant permissions to a security principal, which may be a user, or an application service principal.
42
+
1. In the Azure portal, navigate to your Event Hubs namespace. Go to "Access Control (IAM)" in the left navigation.
43
+
2. Select + Add and select `Add role assignment`.
44
+
45
+
:::image type="content" source="./media/event-hubs-quickstart-kafka-enabled-event-hubs/add-role-assignment-menu.png" alt-text="Screenshot of the Access Control page of an Event Hubs namespace.":::
46
+
1. In the Role tab, select **Azure Event Hubs Data Owner**, and select the **Next** button.
47
+
48
+
:::image type="content" source="./media/event-hubs-quickstart-kafka-enabled-event-hubs/select-event-hubs-owner-role.png" alt-text="Screenshot showing the selection of the Azure Event Hubs Data Owner role.":::
49
+
1. In the **Members** tab, select the **Managed Identity** in the **Assign access to** section.
50
+
1. Select the **+Select members** link.
51
+
1. On the **Select managed identities** page, follow these steps:
52
+
1. Select the **Azure subscription** that has the VM.
53
+
1. For **Managed identity**, select **Virtual machine**
54
+
1. Select your virtual machine's managed identity.
55
+
1. Click **Select** at the bottom of the page.
56
+
57
+
:::image type="content" source="./media/event-hubs-quickstart-kafka-enabled-event-hubs/add-vm-identity.png" alt-text="Screenshot showing the Add role assignment -> Select managed identities page.":::
58
+
1. Select **Review + Assign**.
59
+
60
+
:::image type="content" source="./media/event-hubs-quickstart-kafka-enabled-event-hubs/review-assign.png" alt-text="Screenshot showing the Add role assignment page with role assigned to VM's managed identity.":::
61
+
1. Restart the VM and log in back to the VM for which you configured the managed identity.
62
+
1. Clone the [Azure Event Hubs for Kafka repository](https://github.com/Azure/azure-event-hubs-for-kafka).
63
+
1. Navigate to `azure-event-hubs-for-kafka/tutorials/oauth/java/managedidentity/consumer`.
64
+
1. Switch to the `src/main/resources/` folder, and open `consumer.config`. Replace `namespacename` with the name of your Event Hubs namespace.
> You can find all the OAuth samples for Event Hubs for Kafka [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth).
76
+
7. Switch back to the **Consumer** folder where the pom.xml file is and, and run the consumer code and process events from event hub using your Kafka clients:
77
+
78
+
```java
79
+
mvn clean package
80
+
mvn exec:java -Dexec.mainClass="TestConsumer"
81
+
```
82
+
1. Launch another command prompt window, and navigate to `azure-event-hubs-for-kafka/tutorials/oauth/java/managedidentity/producer`.
83
+
1. Switch to the `src/main/resources/` folder, and open `producer.config`. Replace `mynamespace` with the name of your Event Hubs namespace.
84
+
4. Switch back to the **Producer** folder where the `pom.xml` file is and, run the producer code and stream events into Event Hubs:
85
+
86
+
```shell
87
+
mvn clean package
88
+
mvn exec:java -Dexec.mainClass="TestProducer"
89
+
```
90
+
91
+
You should see messages about events sent in the producer window. Now, check the consumer app window to see the messages that it receives from the event hub.
92
+
93
+
:::image type="content" source="./media/event-hubs-quickstart-kafka-enabled-event-hubs/producer-consumer-output.png" alt-text="Screenshot showing the Producer and Consumer app windows showing the events.":::
0 commit comments