Spring Cloud Azure 4.0 Quick Review

...<properties>
...
<spring-cloud-azure.version>4.0.0</spring-cloud-azure.version>
</
properties>
...
<dependencyManagement>
<
dependencies>
<
dependency>
<
groupId>com.azure.spring</groupId>
<
artifactId>spring-cloud-azure-dependencies</artifactId>
<version>${spring-cloud-azure.version}</version>
<
type>pom</type>
<
scope>import</scope>
</
dependency>
</
dependencies>
</
dependencyManagement>

DefaultAzureCredential

2022-04-05 17:52:43.191  INFO [sca4-sample,,] 95253 --- [     parallel-1] c.azure.identity.ChainedTokenCredential  : Azure Identity => Attempted credential EnvironmentCredential is unavailable.
2022-04-05 17:52:43.195 INFO [sca4-sample,,] 95253 --- [ parallel-1] c.azure.identity.ChainedTokenCredential : Azure Identity => Attempted credential ManagedIdentityCredential is unavailable.
2022-04-05 17:52:43.231 INFO [sca4-sample,,] 95253 --- [ parallel-1] c.azure.identity.ChainedTokenCredential : Azure Identity => Attempted credential SharedTokenCacheCredential is unavailable.
2022-04-05 17:52:43.232 INFO [sca4-sample,,] 95253 --- [ parallel-1] c.azure.identity.ChainedTokenCredential : Azure Identity => Attempted credential IntelliJCredential is unavailable.
2022-04-05 17:52:45.882 INFO [sca4-sample,,] 95253 --- [ parallel-1] c.azure.identity.ChainedTokenCredential : Azure Identity => Attempted credential VisualStudioCodeCredential is unavailable.
Authentication chain sequence

spring-cloud-azure-starter-actuator

<dependency>
<
groupId>com.azure.spring</groupId>
<
artifactId>spring-cloud-azure-starter-actuator</artifactId>
</
dependency>
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
doHealthCheck(Builder builder) throws Exception {
if (this.blobServiceAsyncClient == null) {
builder.status(StorageHealthConstants.NOT_CONFIGURED_STATUS);
} else {
builder.withDetail("URL", this.blobServiceAsyncClient.getAccountUrl());
Response<BlobServiceProperties> info = (Response)this.blobServiceAsyncClient.getPropertiesWithResponse().block(this.timeout);

Enable Sleuth traces to Azure core SDK

<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-trace-sleuth</artifactId>
</dependency>
Storage Account SDK trace

AzureStorageBlobProtocolResolver and AzureStorageFileProtocolResolver

package io.jaylee.sca4sample.service;

import com.azure.spring.cloud.core.resource.AzureStorageBlobProtocolResolver;
import com.azure.storage.blob.BlobServiceAsyncClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Component
@Slf4j
public class BlobService {

@Value("${spring.cloud.azure.storage.blob.container-name}")
String containerName;

private final AzureStorageBlobProtocolResolver azureStorageBlobProtocolResolver;

public BlobService(AzureStorageBlobProtocolResolver azureStorageBlobProtocolResolver) {
this.azureStorageBlobProtocolResolver = azureStorageBlobProtocolResolver;
}

public String listFilesInCSV() throws IOException {
log
.info("containerName : " + containerName);
Resource[] resources = azureStorageBlobProtocolResolver.getResources("azure-blob://" + containerName + "/*");

return Stream.of(resources).map(Resource::getFilename).collect(Collectors.joining(","));
}

}

Azure Resource Manager

package io.jaylee.sca4sample.service;

import com.azure.spring.cloud.autoconfigure.redis.AzureRedisAutoConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CacheForRedisService {

@Autowired
RedisTemplate redisTemplate;


public String testRedis(String value) {
redisTemplate.opsForValue().set(value, value);

return redisTemplate.opsForValue().get(value).toString();
}
}
Zipkin captured Redis interaction

Wrapping Up

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store