Skip to content

Commit 6bbf9a0

Browse files
committed
tested & updated
1 parent 9d6efa1 commit 6bbf9a0

File tree

1 file changed

+43
-76
lines changed

1 file changed

+43
-76
lines changed

articles/event-hubs/event-hubs-quickstart-kafka-enabled-event-hubs.md

Lines changed: 43 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ To complete this quickstart, make sure you have the following prerequisites:
1919

2020
* Read through the [Event Hubs for Apache Kafka](event-hubs-for-kafka-ecosystem-overview.md) article.
2121
* 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/)
2626

2727
## Create an Event Hubs namespace
2828

@@ -34,78 +34,45 @@ When you create an Event Hubs namespace, the Kafka endpoint for the namespace is
3434
## Send and receive messages with Kafka in Event Hubs
3535

3636
### [Passwordless (Recommended)](#tab/passwordless)
37-
38-
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.
65-
66-
```xml
67-
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
68-
security.protocol=SASL_SSL
69-
sasl.mechanism=OAUTHBEARER
70-
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;
71-
sasl.login.callback.handler.class=CustomAuthenticateCallbackHandler;
72-
```
73-
74-
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.
88-
89-
```xml
90-
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
91-
security.protocol=SASL_SSL
92-
sasl.mechanism=OAUTHBEARER
93-
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;
94-
sasl.login.callback.handler.class=CustomAuthenticateCallbackHandler;
95-
```
96-
97-
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+
2. 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.
39+
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.
40+
1. In the Azure portal, navigate to your Event Hubs namespace. Go to "Access Control (IAM)" in the left navigation.
41+
2. Select + Add and select `Add role assignment`.
42+
3. In the Role tab, select `Azure Event Hubs Data Owner` and select the Next button.
43+
4. In the `Members` tab, select the `Managed Identity` radio button for type to assign access to.
44+
5. Select the `+Select members` link. In the Managed Identity dropdown, select Virtual Machine and select your virtual machine's managed identity.
45+
6. Select `Review + Assign`.
46+
1. Log in to the VM for which you configured the managed identity, and clone the [Azure Event Hubs for Kafka repository](https://github.com/Azure/azure-event-hubs-for-kafka).
47+
1. Navigate to `azure-event-hubs-for-kafka/tutorials/oauth/java/managedidentity/consumer`.
48+
6. Switch to the `src/main/resources/` folder, and open `consumer.config`. Replace `namespacename` with the name of your Event Hubs namespace.
49+
50+
```xml
51+
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
52+
security.protocol=SASL_SSL
53+
sasl.mechanism=OAUTHBEARER
54+
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;
55+
sasl.login.callback.handler.class=CustomAuthenticateCallbackHandler;
56+
```
57+
58+
> [!NOTE]
59+
> 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).
60+
7. Run the consumer code and process events from event hub using your Kafka clients:
61+
62+
```java
63+
mvn clean package
64+
mvn exec:java -Dexec.mainClass="TestConsumer"
65+
```
66+
1. Navigate to `azure-event-hubs-for-kafka/tutorials/oauth/java/managedidentity/producer`.
67+
1. Switch to the `src/main/resources/` folder, and open `producer.config`. Replace `mynamespace` with the name of your Event Hubs namespace.
68+
4. Switch back to the **Producer** folder where the `pom.xml` file is and, run the producer code and stream events into Event Hubs:
69+
70+
```shell
71+
mvn clean package
72+
mvn exec:java -Dexec.mainClass="TestProducer"
73+
```
74+
75+
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.
10976

11077
### [Connection string](#tab/connection-string)
11178

0 commit comments

Comments
 (0)