This project demonstrates an Azure Functions application written in Java that processes messages from Azure Event Hubs. It includes an Event Hub trigger function that reads messages from an input Event Hub, processes them, and sends the processed messages to an output Event Hub.
- Event Hub Trigger: Automatically processes messages from an input Event Hub
- Event Hub Output Binding: Sends processed messages to an output Event Hub
- Java: Azure Functions v4 programming model with Java annotations
- Infrastructure as Code: Complete Bicep templates for Azure resources
- Azure Developer CLI: Streamlined deployment with
azd
Input Event Hub → Azure Function → Output Event Hub
↓
Application Insights
- Java 21 or later
- Apache Maven 3.8+
- Azure Functions Core Tools v4
- Azure Developer CLI (azd)
- Azure CLI
- An Azure subscription
.
├── src/
│ └── main/
│ └── java/
│ └── com/
│ └── function/
│ ├── EventHubsTrigger.java # Event Hub trigger function
│ └── TimerTrigger.java # Timer trigger to generate test messages
├── infra/ # Bicep infrastructure files
│ ├── main.bicep # Main deployment template
│ ├── app/
│ │ ├── api.bicep # Function App configuration
│ │ ├── eventhubs.bicep # Event Hub resources
│ │ ├── rbac.bicep # Role assignments
│ │ └── vnet.bicep # Virtual network
│ ├── abbreviations.json # Resource naming conventions
│ └── main.parameters.json # Deployment parameters
├── pom.xml # Maven build configuration
├── host.json
└── azure.yaml # Azure Developer CLI configuration
The EventHubsTrigger function:
- Receives messages from the input Event Hub
- Parses and processes each message
- Adds metadata (ID, timestamp)
- Sends processed messages to the output Event Hub
- Logs processing information to Application Insights
mvn clean packageCreate or update local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "java",
"EventHubConnection__fullyQualifiedNamespace": "<your-eventhub-namespace>.servicebus.windows.net",
"INPUT_EVENTHUB_NAME": "input-events",
"OUTPUT_EVENTHUB_NAME": "output-events"
}
}mvn clean package
mvn azure-functions:run-
Login to Azure:
azd auth login
-
Initialize the environment:
azd env new
Enter an environment name (e.g., "dev").
-
Build and deploy:
mvn clean package azd up
This command will:
- Create all Azure resources (Event Hubs, Function App, Storage, Application Insights)
- Deploy your function code
- Configure all connections and settings
-
Create Azure resources:
az group create --name rg-eventhubs-java --location eastus az deployment group create --resource-group rg-eventhubs-java --template-file infra/main.bicep
-
Deploy function code:
mvn clean package func azure functionapp publish <function-app-name>
Use Azure CLI to send test messages to the input Event Hub:
az eventhubs eventhub message send \
--namespace-name <your-namespace> \
--eventhub-name input-events \
--messages '[{"id": "1", "message": "Hello from CLI"}]'-
View logs in the portal:
- Navigate to your Function App in Azure Portal
- Go to "Monitor" → "Logs"
-
View in Application Insights:
az monitor app-insights query \ --app <app-insights-name> \ --analytics-query "traces | where message contains 'Event hub function' | order by timestamp desc | take 20"
-
Check output Event Hub:
- Verify processed messages in the output Event Hub using Azure Portal or Event Hub Explorer
| Variable | Description |
|---|---|
EventHubConnection__fullyQualifiedNamespace |
Event Hub namespace (uses managed identity) |
INPUT_EVENTHUB_NAME |
Name of the input Event Hub |
OUTPUT_EVENTHUB_NAME |
Name of the output Event Hub |
APPLICATIONINSIGHTS_CONNECTION_STRING |
Application Insights connection string |
The Function App uses managed identity to connect to Event Hubs. The infrastructure automatically assigns the "Event Hubs Data Owner" role to both your user account and the Function App's managed identity.
- Verify the Event Hub connection string and names
- Check that messages are being sent to the input Event Hub
- Review Application Insights logs for errors
- Ensure managed identity is enabled on the Function App
- Verify role assignments (Event Hubs Data Owner) are configured
- Check that the namespace FQDN is correct in settings
- Run
npm installto ensure all dependencies are installed - Verify Node.js version (22.x or later)
To delete all Azure resources:
azd downOr manually:
az group delete --name rg-eventhubs-javascript- Azure Functions JavaScript Developer Guide
- Azure Event Hubs Documentation
- Azure Developer CLI
- Bicep Documentation
This project is licensed under the MIT License.