5分钟搞定Dubbo应用接入华为云微服务引擎CSE

5分钟搞定Dubbo应用接入华为云微服务引擎CSE

Dubbo和CSE底层都使用了Spring的依赖注入和bean管理系统,所以使用Dubbo的服务迁移到华为云微服务引擎CSE的工作量较小, 主要改动在依赖和配置方面。

本示例的完整代码已放在GitHub上,其中目录dubbo-demo是原始的Dubbo DEMO,目录dubbo-demo-servicecomb是改造后的可直接运行于华为云CSE的DEMO。

1、管理依赖:/dubbo-demo/pom.xml

在主项目pom里的dependencyManagement中增加如下配置来管理CSE包依赖,子项目就不需要指定CSE版本号。
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.huawei.paas.cse</groupId>
        <artifactId>cse-dependency</artifactId>
        <version>2.3.9</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

注意,maven的settings需添加cse的mirror才能正常下载到cse的相关依赖包:

    <mirror>
      <id>nexus-cse</id>
      <mirrorOf>*</mirrorOf>
      <name>cse nexus</name>
      <url>http://maven.huaweicse.com/nexus/content/groups/public</url>
    </mirror>

2、服务提供方:dubbo-demo-provider

2.1、替换依赖:/dubbo-demo-provider/pom.xml

将对Dubbo的依赖替换为对CSE的依赖pom.xml

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是使用Perl编写的代码示例,用于调用华为云刷新CDN缓存预热API接口: ``` #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use JSON qw(encode_json); # Set the AK and SK my $ak = '<YOUR_AK>'; my $sk = '<YOUR_SK>'; # Set the API endpoint and request URL my $endpoint = 'https://cdn.myhuaweicloud.com'; my $request_url = '/v1.0/refreshtasks'; # Set the request body parameters my $request_body = { 'tasks' => [ { 'type' => 'flush', 'urls' => [ 'http://example.com', 'https://example.com' ] }, { 'type' => 'preheating', 'urls' => [ 'http://example.com', 'https://example.com' ], 'urls_type' => 'file', 'area' => 'mainland', 'refresh_type' => 'url' } ] }; # Encode the request body parameters as JSON my $json_request_body = encode_json($request_body); # Generate the authorization header my $date = `date -u +%a, %d %b %Y %H:%M:%S GMT`; chomp($date); my $auth_header = 'HWS ' . $ak . ':' . hmac_sha1_hex($date, $sk); # Create a new LWP::UserAgent object my $ua = LWP::UserAgent->new; # Set the request headers my $request_headers = [ 'Content-Type' => 'application/json', 'X-Auth-Date' => $date, 'Authorization' => $auth_header ]; # Send the API request my $response = $ua->post($endpoint . $request_url, content => $json_request_body, headers => $request_headers); # Check for errors if ($response->is_success) { print "API request successful!\n"; print "Response:\n" . $response->content . "\n"; } else { print "API request failed!\n"; print "Response:\n" . $response->status_line . "\n"; } ``` 注意:在此示例中,我们使用了HMAC-SHA1算法来生成授权头。您需要安装Crypt::Digest::SHA1模块来使用此算法。您还需要将YOUR_AK和YOUR_SK替换为您自己的华为云AK和SK。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值