Azure Spring Cloud 已进入公开预览阶段

工程 | Josh Long | 2019 年 11 月 04 日 | ...

大家好,Spring 的粉丝们!今天我们很高兴地宣布,由 Microsoft 和 Pivotal 联合开发的 Spring Boot 和 Spring Cloud 微服务应用程序运行时 Azure Spring Cloud 已进入公开测试阶段。现在任何人都可以尝试!

随着客户将工作负载迁移到云端,我们看到了云原生架构,特别是微服务的增长。基于微服务的架构有助于提高可伸缩性和开发速度,但实现它们可能带来挑战。对于许多 Java 开发人员来说,Spring Boot 和 Spring Cloud 有助于应对这些挑战,提供了一个健壮的平台,其中包含用于开发和操作微服务应用程序的成熟模式。

问题在于,创建和维护 Spring Cloud 基础架构——例如服务注册中心、分布式跟踪和分布式配置——需要少量组织愿意承担的管理工作。Spring Cloud 提供了实现这一目标的机制,但安全性、可伸缩性、负载均衡等方面仍需您自行解决。Azure Spring Cloud 是一个构建在 Microsoft Azure 之上的托管环境,其中包含预先配置、具有最佳实践、可直接部署的基础架构服务以及用于 Spring 应用程序的运行时。

以 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 构建应用程序,激活 cloud Maven 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 Spring Cloud 的应用程序中利用更广泛的 Azure 平台的丰富功能,并且可以利用 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 大会上发表的这个演讲!

生产环境中见!

获取 Spring 新闻通讯

通过 Spring 新闻通讯保持联系

订阅

领先一步

VMware 提供培训和认证,助您加速进步。

了解更多

获得支持

Tanzu Spring 提供 OpenJDK™、Spring 和 Apache Tomcat® 的支持和二进制文件,只需一份简单的订阅。

了解更多

即将举行的活动

查看 Spring 社区所有即将举行的活动。

查看所有