Skip to content

Commit 0e33390

Browse files
authored
Refactor messaging sample and readme for Spring Cloud Messaging(Azure#20214)
1 parent a6a44a9 commit 0e33390

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed
Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,67 @@
1-
# Azure Spring Cloud Messaging Sample client library for Java
1+
# Spring Cloud Azure Messaging Sample shared library for Java
22

33
## 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+
47
## Getting started
58

9+
Running this sample will be charged by Azure. You can check the usage and bill at
10+
[this link][azure-account].
11+
612
### Prerequisites
713
- [Environment checklist][environment_checklist]
814

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+
925
## 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+
1051
## Troubleshooting
52+
1153
## Next steps
54+
1255
## Contributing
1356

57+
1458
<!-- 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
1566
[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

sdk/spring/azure-spring-boot-samples/azure-spring-cloud-sample-messaging/src/main/java/com/azure/spring/sample/messaging/WebController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
@RestController
1818
public class WebController {
1919

20-
private static final String EVENT_HUB_NAME = "eventhub1";
21-
private static final String CONSUMER_GROUP = "cg1";
20+
private static final String EVENT_HUB_NAME = "event-hub-name";
21+
private static final String CONSUMER_GROUP = "$Default";
2222

2323
@Autowired
2424
EventHubOperation eventHubOperation;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spring:
2+
cloud:
3+
azure:
4+
eventhub:
5+
connection-string: [eventhub-namespace-connection-string]
6+
checkpoint-storage-account: [checkpoint-storage-account]
7+
checkpoint-access-key: [checkpoint-access-key]
8+
checkpoint-container: [checkpoint-container]

0 commit comments

Comments
 (0)