|
1 | | -# Azure Spring Cloud Messaging Sample client library for Java |
| 1 | +# Spring Cloud Azure Messaging Sample shared library for Java |
2 | 2 |
|
3 | 3 | ## Key concepts |
| 4 | + |
| 5 | +This code sample demonstrates how to use [AzureMessageListener.java][annotation-azure-message-listener] to listen to events from Event Hubs. |
| 6 | + |
4 | 7 | ## Getting started |
5 | 8 |
|
| 9 | +Running this sample will be charged by Azure. You can check the usage and bill at |
| 10 | +[this link][azure-account]. |
| 11 | + |
6 | 12 | ### Prerequisites |
7 | 13 | - [Environment checklist][environment_checklist] |
8 | 14 |
|
| 15 | +### Create Azure resources |
| 16 | + |
| 17 | +1. Create [Azure Event Hubs Namespace][create-event-hubs-namespace]. |
| 18 | + Please note `Basic` tier is unsupported. After creating the Azure Event Hub, you |
| 19 | + can create your own Consumer Group or use the default `$Default` Consumer Group. |
| 20 | + |
| 21 | +1. Create [Azure Event Hub][create-event-hub-instance] and named `event-hub-name`. |
| 22 | + |
| 23 | +1. Create [Azure Storage][create-azure-storage] for checkpoint use. |
| 24 | + |
9 | 25 | ## Examples |
| 26 | + |
| 27 | +1. Update [application.yaml][application.yaml]. |
| 28 | + ```yaml |
| 29 | + spring: |
| 30 | + cloud: |
| 31 | + azure: |
| 32 | + eventhub: |
| 33 | + connection-string: [eventhub-namespace-connection-string] |
| 34 | + checkpoint-storage-account: [checkpoint-storage-account] |
| 35 | + checkpoint-access-key: [checkpoint-access-key] |
| 36 | + checkpoint-container: [checkpoint-container] |
| 37 | + ``` |
| 38 | +
|
| 39 | +1. Run the `mvn spring-boot:run` in the root of the code sample to get the app running. |
| 40 | + |
| 41 | +1. Send a POST request |
| 42 | + |
| 43 | + $ curl -H "Content-type: application/json" -X POST http://localhost:8080/messages -d "{\"name\":\"hello\"}" |
| 44 | + |
| 45 | +1. Verify in your app’s logs that a similar message was posted: |
| 46 | + |
| 47 | + New message received: 'User{name='hello'}' |
| 48 | + |
| 49 | +1. Delete the resources on [Azure Portal][azure-portal] to avoid unexpected charges. |
| 50 | + |
10 | 51 | ## Troubleshooting |
| 52 | + |
11 | 53 | ## Next steps |
| 54 | + |
12 | 55 | ## Contributing |
13 | 56 |
|
| 57 | + |
14 | 58 | <!-- LINKS --> |
| 59 | + |
| 60 | +[azure-account]: https://azure.microsoft.com/account/ |
| 61 | +[azure-portal]: https://ms.portal.azure.com/ |
| 62 | +[create-event-hubs-namespace]: https://docs.microsoft.com/azure/event-hubs/event-hubs-create#create-an-event-hubs-namespace |
| 63 | +[create-event-hub-instance]: https://docs.microsoft.com/azure/event-hubs/event-hubs-create#create-an-event-hub |
| 64 | +[create-azure-storage]: https://docs.microsoft.com/azure/storage/ |
| 65 | +[annotation-azure-message-listener]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-cloud-messaging/src/main/java/com/azure/spring/messaging/annotation/AzureMessageListener.java |
15 | 66 | [environment_checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/ENVIRONMENT_CHECKLIST.md#ready-to-run-checklist |
| 67 | +[application.yaml]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-operation/src/main/resources/application.yaml |
0 commit comments