Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions spring-cloud-alibaba-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<version>${revision}</version>
</dependency>

<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-rpc</artifactId>
<version>${revision}</version>
</dependency>

</dependencies>

<build>
Expand Down
25 changes: 24 additions & 1 deletion spring-cloud-alibaba-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@
<shedlock.version>4.23.0</shedlock.version>
<schedulerx.worker.version>1.11.4</schedulerx.worker.version>

<!-- dubbo-->
<dubbo.version>3.3.0-beta.4</dubbo.version>

<!-- Maven Plugin Versions -->
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<flatten-maven-plugin.version>1.2.7</flatten-maven-plugin.version>


</properties>

<dependencyManagement>
Expand Down Expand Up @@ -186,6 +191,12 @@
<artifactId>schedulerx2-worker</artifactId>
<version>${schedulerx.worker.version}</version>
</dependency>
<!-- dubbo Dependencies -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${dubbo.version}</version>
</dependency>

<!-- Own dependencies -->
<dependency>
Expand Down Expand Up @@ -265,7 +276,19 @@
<artifactId>spring-cloud-starter-alibaba-schedulerx</artifactId>
<version>${revision}</version>
</dependency>

<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-rpc</artifactId>
<version>${revision}</version>
</dependency>

<!-- Testing Dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-test</artifactId>
<version>${spring.ai.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
5 changes: 3 additions & 2 deletions spring-cloud-alibaba-starters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<packaging>pom</packaging>
<name>Spring Cloud Alibaba Starters</name>
<description>Spring Cloud Alibaba Starters</description>

<modules>

<module>spring-alibaba-nacos-config</module>
Expand All @@ -29,6 +29,7 @@
<module>spring-cloud-alibaba-sentinel-gateway</module>
<module>spring-cloud-alibaba-commons</module>
<module>spring-cloud-starter-alibaba-schedulerx</module>
<module>spring-cloud-starter-alibaba-rpc</module>
</modules>

<build>
Expand All @@ -55,4 +56,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-starters</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>spring-cloud-starter-alibaba-rpc</artifactId>
<name>Spring Cloud Starter Alibaba Rpc</name>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty4</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.cloud.rpc;

import com.alibaba.cloud.rpc.utils.UrlResolver;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;


/**
* @author :Lictory
* @date : 2024/09/27
*/

@AutoConfiguration
@ConditionalOnProperty(prefix = RpcProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(RpcProperties.class)
public class RpcConfiguration {
@Bean
@ConditionalOnMissingBean
public RpcProperties rpcProperties() {
return new RpcProperties();
}


@Bean
@ConditionalOnMissingBean
public UrlResolver initUrlResolver() {
return new UrlResolver();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.cloud.rpc;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* @author :Lictory
* @date : 2024/09/27
*/
@ConfigurationProperties("spring.cloud.rpc.netty")
public class RpcProperties {

/**
* config prefix.
*/
public static final String PREFIX = "spring.cloud.rpc";

/**
* prefix of netty port.
*/
public static final String NETTY_PORT_PREFIX = "spring.cloud.rpc.netty.port";

/**
* prefix of netty host.
*/
public static final String HOST_PREFIX = "spring.cloud.rpc.netty.host";

private Integer port;
private String host;

public Integer getPort() {
return port;
}

public String getHost() {
return host;
}

public void setPort(Integer port) {
this.port = port;
}

public void setHost(String host) {
this.host = host;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.cloud.rpc.client;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import com.alibaba.cloud.rpc.metadata.HttpMetadata;
import com.alibaba.cloud.rpc.metadata.HttpRpcResponse;
import com.alibaba.cloud.rpc.utils.UrlResolver;
import feign.Client;
import feign.Request;
import feign.Response;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.remoting.exchange.ExchangeClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Component;

/**
* @author :Lictory
* @date : 2024/08/12
*/

@Component
public class FeignRpcClient implements Client {
@Autowired
private LoadBalancerClient loadBalancerClient;
private ExchangeClient client;

@Autowired
private UrlResolver urlResolver;

@Override
public Response execute(Request request, Request.Options options) {
String url = urlResolver.resolveOriginalUrl(loadBalancerClient, request.url());
this.client = urlResolver.getClient(url);
HttpMetadata httpMetadata = initHttpMetadata(
urlResolver.getPathFromUrl(request.url()),
request.httpMethod().name(),
request.headers(),
request.body()
);
HttpRpcResponse httpRpcResponse = null;
try {
CompletableFuture<Object> future = client.request(httpMetadata);
httpRpcResponse = (HttpRpcResponse) future.get();
}
catch (RemotingException | InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
return Response.builder()
.status(httpRpcResponse.getStatusCode())
.reason(httpRpcResponse.getReasonPhrase())
.headers(httpRpcResponse.getHeaders())
.body(httpRpcResponse.getBody())
.request(request)
.build();
}

private HttpMetadata initHttpMetadata(String url, String method, Map<String, Collection<String>> headers, byte[] body) {
HttpMetadata httpMetadata = new HttpMetadata();
httpMetadata.setBody(body);
httpMetadata.setUrl(url);
httpMetadata.setHeaders(headers);
httpMetadata.setMethod(method);
return httpMetadata;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.cloud.rpc.config;

import com.alibaba.cloud.rpc.RpcProperties;
import com.alibaba.cloud.rpc.client.FeignRpcClient;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author :Lictory
* @date : 2024/08/11
*/

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = RpcProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
public class RpcFeignConfiguration {
@Bean
public feign.Client feignClient() {
return new FeignRpcClient();
}
}
Loading
Loading