Skip to content

Commit

Permalink
test storage queue operation sample
Browse files Browse the repository at this point in the history
  • Loading branch information
saragluna committed Dec 17, 2020
1 parent 822158f commit 609a6da
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,39 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<!-- mvn azure-webapp:config -->
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>1.12.0</version>
<configuration>
<schemaVersion>V2</schemaVersion>
<resourceGroup>[your-resource-group]</resourceGroup>
<appName>[your-app-name]</appName>
<runtime>
<os>Linux</os>
<javaVersion>Java 8</javaVersion>
<webContainer>Java SE</webContainer>
</runtime>
<deployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>
</plugins>
</build>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Spring Cloud Azure Storage Queue Integration Code Sample shared library for Java

## Key concepts

This code sample demonstrates how to use Spring Integration for Azure Storage Queue.

## Getting started

Running this sample will be charged by Azure. You can check the usage and bill at
[this link][azure-account].

### Environment checklist

We need to ensure that this [environment checklist][ready-to-run-checklist] is
completed before the run.

### Create Azure resources

1. Create [Azure Storage][create-azure-storage].

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 stream binding related properties in
[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:
azure:
storage:
account: [storage-account-name]
access-key: [storage-account-access-key]
```
2. Update queue name in
[SendController.java][send-controller] and
[ReceiveController.java][receive-controller].
1. Run the `mvn spring-boot:run` in the root of the code sample to get
the app running.

1. Send a POST request

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

1. Receive the message you posted

$ curl -X GET localhost:8080/messages

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

New message received: 'hello'
Message 'hello' successfully checkpointed

1. Delete the resources on [Azure Portal][azure-portal] to avoid unexpected charges.


## Troubleshooting

## Next steps

## Contributing

<!-- LINKS -->

[azure-account]: https://azure.microsoft.com/account/
[azure-portal]: http://ms.portal.azure.com/
[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
[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
[send-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-storage-queue/src/main/java/com/azure/spring/sample/storage/queue/SendController.java
[receive-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-storage-queue/src/main/java/com/azure/spring/sample/storage/queue/ReceiveController.java

Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,40 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<!-- mvn azure-webapp:config -->
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>1.12.0</version>
<configuration>
<schemaVersion>V2</schemaVersion>
<resourceGroup>[your-resource-group]</resourceGroup>
<appName>[your-app-name]</appName>
<runtime>
<os>Linux</os>
<javaVersion>Java 8</javaVersion>
<webContainer>Java SE</webContainer>
</runtime>
<deployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public StorageQueueMessageSource storageQueueMessageSource(StorageQueueOperation
storageQueueOperation.setCheckpointMode(CheckpointMode.MANUAL);
storageQueueOperation.setVisibilityTimeoutInSeconds(10);

StorageQueueMessageSource messageSource =
new StorageQueueMessageSource(STORAGE_QUEUE_NAME, storageQueueOperation);
return messageSource;
return new StorageQueueMessageSource(STORAGE_QUEUE_NAME, storageQueueOperation);
}

/**
Expand All @@ -43,10 +41,10 @@ public StorageQueueMessageSource storageQueueMessageSource(StorageQueueOperation
@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()
.doOnError(Throwable::printStackTrace)
.doOnSuccess(t -> System.out.println(String.format("Message '%s' successfully checkpointed", message)))
.doOnSuccess(t -> System.out.printf("Message '%s' successfully checkpointed%n", message))
.subscribe();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
spring:
cloud:
azure:
msi-enabled: true
managed-identity:
client-id: [the-id-of-managed-identity]
resource-group: [resource-group]
subscription-id: [subscription-id]
storage:
account: [storage-account]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring:
cloud:
azure:
client-id: [service-principal-id]
client-secret: [service-principal-secret]
tenant-id: [tenant-id]
resource-group: [resource-group]
storage:
account: [storage-account]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
spring:
cloud:
azure:
storage:
account: [storage-account]
access-key: [storage-account-access-key]

0 comments on commit 609a6da

Please sign in to comment.