-
Notifications
You must be signed in to change notification settings - Fork 2k
Using Spring Cloud Azure with Azure Emulators
zhihaoguo edited this page Jun 21, 2022
·
1 revision
This article describes how to use Cosmos and Storage emulators with Spring Cloud Azure.
The demos used in this article are spring-cloud-azure-data-cosmos-sample and storage-blob-sample.
- Follow the instruction on this page to run the cosmos emulator on Docker.
- After the emulator is running, using a different terminal, load the IP address of your local machine into a variable.
ipaddr="`ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' | head -n 1`"
- Next, download the certificate for the emulator.
curl -k https://$ipaddr:8081/_explorer/emulator.pem > emulatorcert.crt
Run the following bash script to import the certificate:
#!/bin/bash
# If emulator was started with /AllowNetworkAccess, replace the below with the actual IP address of it:
EMULATOR_HOST=localhost
EMULATOR_PORT=8081
EMULATOR_CERT_PATH=/Users/plato1233/Desktop/emulatorcert.crt
openssl s_client -connect ${EMULATOR_HOST}:${EMULATOR_PORT} </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > $EMULATOR_CERT_PATH
# delete the cert if already exists
# you may need to input the keystore password:changeit
sudo $JAVA_HOME/bin/keytool -cacerts -delete -alias cosmos_emulator
# import the cert
# you may need to input the keystore password:changeit
sudo $JAVA_HOME/bin/keytool -cacerts -importcert -alias cosmos_emulator -file $EMULATOR_CERT_PATH
Update application.yml in spring-cloud-azure-data-cosmos-sample with following configuration:
spring:
cloud:
azure:
cosmos:
endpoint: https://localhost:8081
database: test-emulator
key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
In your terminal, run mvn clean spring-boot:run
.
mvn clean spring-boot:run
docker run -p 10000:10000 mcr.microsoft.com/azure-storage/azurite azurite-blob --blobHost 0.0.0.0
Please refer to this page for more information about Azurite.
Update application.yml in storage-blob-sample with following configuration:
spring:
cloud:
azure:
storage:
blob:
account-name: devstoreaccount1
container-name: testcantainer
account-key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==
endpoint: http://127.0.0.1:10000/devstoreaccount1
In your terminal, run mvn clean spring-boot:run
.
mvn clean spring-boot:run
- Frequently Asked Questions
- Azure Identity Examples
- Configuration
- Performance Tuning
- Android Support
- Unit Testing
- Test Proxy Migration
- Azure Json Migration
- New Checkstyle and Spotbugs pattern migration
- Protocol Methods
- TypeSpec-Java Quickstart
- Getting Started Guidance
- Adding a Module
- Building
- Writing Performance Tests
- Working with AutoRest
- Deprecation
- BOM guidelines
- Release process
- Access helpers