领先一步
VMware 提供培训和认证,助您飞速发展。
了解更多大家好,各位 Spring 爱好者!今天我们很高兴地宣布 Azure Spring Cloud 现已进入公开测试阶段,它是 Microsoft 和 Pivotal 联合开发的基于 Spring Boot 的应用程序和基于 Spring Cloud 的微服务的运行时环境。现在任何人都可以试用它!
随着客户将其工作负载迁移到云端,我们看到了云原生架构,特别是微服务使用的增长。基于微服务的架构有助于提高可伸缩性和速度,但实现它们可能会带来挑战。对于许多 Java 开发人员来说,Spring Boot 和 Spring Cloud 帮助解决了这些挑战,为开发和运维微服务应用提供了强大的平台和成熟的模式。
问题在于创建和维护 Spring Cloud 基础设施——例如服务注册中心、分布式跟踪和分布式配置——需要很少组织愿意承担的管理工作。Spring Cloud 提供了机制,但如何确保安全、伸缩、负载均衡等等则取决于您自己。Azure Spring Cloud 是一个构建在 Microsoft Azure 之上的托管环境,为基于 Spring 的应用程序提供了预配置、有主张、可立即部署的基础设施服务和运行时环境。
假设您有一个典型的基于 Spring Cloud 的微服务,它依赖于 Spring Cloud Config Server 中的配置,并使用 Spring Cloud Eureka 的 DiscoveryClient
抽象实现参与服务注册和发现。
src/main/java/demo/DemoApplication.java
package demo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@RestController
class GreetingsRestController {
private final String message;
GreetingsRestController(@Value("${application.message}") String msg) {
this.message = msg;
}
@GetMapping("/hello")
public String hello() {
return message;
}
}
当然,这个应用程序还需要一个属性文件,其中包含应用程序在服务注册表中的名称
src/main/resources/application.properties
spring.application.name = account-service
这个演示应用程序非常简单。但是,要将其投入生产,您需要设置一个 Spring Cloud Config Server(包括安全和 Git 仓库)、一个 Spring Cloud Eureka Server 服务注册中心(包括横向伸缩),以及应用程序本身的部署。
Azure Spring Cloud 改变了一切。
要设置环境,您需要设置一个 Azure Spring Cloud 环境。
然后,您可以轻松配置 Spring Cloud Config Server 及其身份验证。
在 Azure Spring Cloud 中将服务部署到生产环境时,需要进行自动配置。在您的构建中使用 Maven profile 启用它,如下所示
<profiles>
<profile>
<id>cloud</id>
<repositories>
<repository>
<id>nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>spring-cloud-starter-azure-spring-cloud-client</artifactId>
<version>2.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
</profiles>
使用 Maven 构建应用程序,激活 Maven cloud
profile
mvn -Pcloud clean package
现在,您可以使用 Azure CLI az
部署应用程序
az spring-cloud app create -n demo-app # create the logical application
az spring-cloud app deploy -n demo-app --jar-path target/demo-0.0.1-SNAPSHOT.jar # deploy the Boot .jar
部署应用程序后,您可以看到它可以通过 Azure Spring Cloud 上的托管服务注册中心被发现,例如以下处于各种状态的应用程序
这对您意味着什么?嗯,这仅仅是个开始!Microsoft Azure 是一个充满活力的平台,提供有竞争力的价格,比世界上任何其他 IaaS 提供商都多的区域,以及一个面向生产的 Spring 应用环境。在这篇文章中,我们介绍了一些 Azure Spring Cloud 的功能。然而,您仍然可以利用更大的 Azure 平台的丰富性来构建您的 Azure Spring Cloud 应用,并且可以利用 Spring Cloud Azure 开源项目轻松绑定到 Azure 托管服务。这些服务是我最感兴趣的。接下来的步骤,您可以探索与 Spring Security 和 Active Directory 的紧密集成,或 Azure CosmosDB 的响应式 Spring Data 支持,或 Microsoft SQL Server 的响应式 R2DBC 集成,这些服务都完全托管在 Microsoft Azure 上。
有一些很棒的资源供您进一步探索。您可以在此处查阅更详细的培训资料,并在此处查看一些关于如何部署和扩展应用程序的示例。
当然,如果您想了解更多关于 Azure Spring Cloud 的信息,那么您一定不要错过 Microsoft 的 Julien Dubois 和我在最近的 SpringOne Platform 2019 大会上所做的演讲!
生产环境中见!