Skip to content

Commit

Permalink
test service bus operation sample
Browse files Browse the repository at this point in the history
  • Loading branch information
saragluna committed Dec 17, 2020
1 parent 609a6da commit b7507cd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ completed before the run.

1. Create [Azure Storage][create-azure-storage] for checkpoint use.

1. **[Optional]** if you want to use service principal, please follow
[create service principal from Azure CLI][create-sp-using-azure-cli] to create one.

1. **[Optional]** if you want to use managed identity, please follow
[create managed identity][create-managed-identity] to set up managed identity.

## Examples

1. Update [application.yaml](src/main/resources/application.yaml).
1. Update [application.yaml](src/main/resources/application.yaml). If you choose to use
service principal or managed identity, update the `application-sp.yaml` or
`application-mi.yaml` respectively.
```yaml
spring:
cloud:
Expand Down Expand Up @@ -65,6 +73,8 @@ completed before the run.
[azure-portal]: http://ms.portal.azure.com/
[create-event-hubs]: https://docs.microsoft.com/azure/event-hubs/
[create-azure-storage]: https://docs.microsoft.com/azure/storage/
[create-managed-identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-managed-identity.md
[create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md
[eventhub-operation]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-integration-eventhubs/src/main/java/com/azure/spring/integration/eventhub/api/EventHubOperation.java
[ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist
[receive-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/src/main/java/com/azure/spring/sample/eventhubs/ReceiveController.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ completed before the run.
1. Create Azure Service Bus namespace, queue and topic. Please see
[how to create][create-service-bus].

1. **[Optional]** if you want to use service principal, please follow
[create service principal from Azure CLI][create-sp-using-azure-cli] to create one.

1. **[Optional]** if you want to use managed identity, please follow
[create managed identity][create-managed-identity] to set up managed identity.


## Examples

1. Update [application.yaml](src/main/resources/application.yaml).
1. Update [application.yaml](src/main/resources/application.yaml). If you choose to use
service principal or managed identity, update the `application-sp.yaml` or
`application-mi.yaml` respectively.
```yaml
spring:
cloud:
Expand All @@ -44,7 +52,7 @@ completed before the run.

1. Send a POST request to service bus queue

$ curl -X POST http://localhost:8080/messages?message=hello
$ curl -X POST http://localhost:8080/queues?message=hello

1. Verify in your app’s logs that a similar message was posted:

Expand Down Expand Up @@ -72,6 +80,8 @@ completed before the run.
[azure-account]: https://azure.microsoft.com/account/
[azure-portal]: http://ms.portal.azure.com/
[create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal
[create-managed-identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-managed-identity.md
[create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md
[ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist
[queue-receive-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/QueueReceiveController.java
[queue-send-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/QueueSendController.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class QueueReceiveController {
@ServiceActivator(inputChannel = INPUT_CHANNEL)
public void messageReceiver(byte[] payload, @Header(AzureHeaders.CHECKPOINTER) Checkpointer checkpointer) {
String message = new String(payload);
System.out.println(String.format("New message received: '%s'", message));
System.out.printf("New message received: '%s'%n", message);
checkpointer.success().handle((r, ex) -> {
if (ex == null) {
System.out.println(String.format("Message '%s' successfully checkpointed", message));
System.out.printf("Message '%s' successfully checkpointed.%n", message);
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
spring:
cloud:
azure:
msi-enabled: true
managed-identity:
client-id: [the-id-of-managed-identity]
resource-group: [resource-group]
subscription-id: [subscription-id]

# Uncomment below configurations if you want to enable auto creating resources.
#
# subscription-id: [subscription-id]
# auto-create-resources: true
# environment: Azure
# region: [region]

servicebus:
namespace: [servicebus-namespace]
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ spring:
client-secret: [service-principal-secret]
tenant-id: [tenant-id]
resource-group: [resource-group]

# Uncomment below configurations if you want to enable auto creating resources.
#
# subscription-id: [subscription-id]
# auto-create-resources: true
# environment: Azure
# region: [region]

servicebus:
namespace: [servicebus-namespace]

0 comments on commit b7507cd

Please sign in to comment.