Skip to content

Commit

Permalink
Merge pull request #2631 from hosuaby/feature/feign-vertx
Browse files Browse the repository at this point in the history
Integrate Feign Vertx into the main project
  • Loading branch information
velo authored Nov 4, 2024
2 parents d821a54 + 4c202b1 commit 001696e
Show file tree
Hide file tree
Showing 34 changed files with 3,367 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/src/main/java/feign/RequestTemplateFactoryResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public RequestTemplate.Factory resolve(Target<?> target, MethodMetadata md) {
}
}

private static class BuildTemplateByResolvingArgs implements RequestTemplate.Factory {
static class BuildTemplateByResolvingArgs implements RequestTemplate.Factory {

private final QueryMapEncoder queryMapEncoder;

Expand All @@ -56,7 +56,7 @@ private static class BuildTemplateByResolvingArgs implements RequestTemplate.Fac
private final Map<Integer, Param.Expander> indexToExpander =
new LinkedHashMap<Integer, Param.Expander>();

private BuildTemplateByResolvingArgs(
BuildTemplateByResolvingArgs(
MethodMetadata metadata, QueryMapEncoder queryMapEncoder, Target target) {
this.metadata = metadata;
this.target = target;
Expand Down Expand Up @@ -212,11 +212,11 @@ protected RequestTemplate resolve(
}
}

private static class BuildFormEncodedTemplateFromArgs extends BuildTemplateByResolvingArgs {
static class BuildFormEncodedTemplateFromArgs extends BuildTemplateByResolvingArgs {

private final Encoder encoder;

private BuildFormEncodedTemplateFromArgs(
BuildFormEncodedTemplateFromArgs(
MethodMetadata metadata, Encoder encoder, QueryMapEncoder queryMapEncoder, Target target) {
super(metadata, queryMapEncoder, target);
this.encoder = encoder;
Expand All @@ -242,11 +242,11 @@ protected RequestTemplate resolve(
}
}

private static class BuildEncodedTemplateFromArgs extends BuildTemplateByResolvingArgs {
static class BuildEncodedTemplateFromArgs extends BuildTemplateByResolvingArgs {

private final Encoder encoder;

private BuildEncodedTemplateFromArgs(
BuildEncodedTemplateFromArgs(
MethodMetadata metadata, Encoder encoder, QueryMapEncoder queryMapEncoder, Target target) {
super(metadata, queryMapEncoder, target);
this.encoder = encoder;
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
<contributor>
<name>Guillaume Simard</name>
</contributor>
<contributor>
<name>Alexei KLENIN</name>
<email>alexei.klenin@gmail.com</email>
</contributor>
</contributors>

<modules>
Expand Down Expand Up @@ -122,6 +126,7 @@
<module>fastjson2</module>
<module>feign-form</module>
<module>feign-form-spring</module>
<module>vertx</module>
</modules>

<scm>
Expand Down
78 changes: 78 additions & 0 deletions vertx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Feign Vertx

Implementation of Feign on Vertx. Brings you the best of two worlds together :
concise syntax of Feign to write client side API on fast, asynchronous and
non-blocking HTTP client of Vertx.

## Installation

### With Maven

```xml
<dependencies>
...
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-vertx</artifactId>
<version>14.0</version>
</dependency>
...
</dependencies>
```

### With Gradle

```groovy
compile group: 'io.github.openfeign', name: 'feign-vertx', version: '14.0'
```

## Compatibility

Feign | Vertx
---------------------- | ----------------------
14.x | 4.x

## Usage

Write Feign API as usual, but every method of interface must return
`io.vertx.core.Future`.

```java
@Headers({ "Accept: application/json" })
interface IcecreamServiceApi {

@RequestLine("GET /icecream/flavors")
Future<Collection<Flavor>> getAvailableFlavors();

@RequestLine("GET /icecream/mixins")
Future<Collection<Mixin>> getAvailableMixins();

@RequestLine("POST /icecream/orders")
@Headers("Content-Type: application/json")
Future<Bill> makeOrder(IceCreamOrder order);

@RequestLine("GET /icecream/orders/{orderId}")
Future<IceCreamOrder> findOrder(@Param("orderId") int orderId);

@RequestLine("POST /icecream/bills/pay")
@Headers("Content-Type: application/json")
Future<Void> payBill(Bill bill);
}
```
Build the client :

```java
Vertx vertx = Vertx.vertx(); // get Vertx instance

/* Create instance of your API */
IcecreamServiceApi icecreamApi = VertxFeign
.builder()
.vertx(vertx) // provide vertx instance
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.target(IcecreamServiceApi.class, "http://www.icecreame.com");

/* Execute requests asynchronously */
Future<Collection<Flavor>> flavorsFuture = icecreamApi.getAvailableFlavors();
Future<Collection<Mixin>> mixinsFuture = icecreamApi.getAvailableMixins();
```
123 changes: 123 additions & 0 deletions vertx/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2012 The Feign Authors (feign@commonhaus.dev)
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
http://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.
-->
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.openfeign</groupId>
<artifactId>parent</artifactId>
<version>13.6-SNAPSHOT</version>
</parent>

<artifactId>feign-vertx</artifactId>

<name>Feign Vertx</name>
<description>Implementation of Feign on Vertx web client.</description>

<properties>
<vertx.version>4.5.10</vertx.version>
<jackson.version>2.12.0</jackson.version>
<slf4j-log4j12.version>1.8.0-beta0</slf4j-log4j12.version>
<wiremock.version>2.35.1</wiremock.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
</dependency>

<!-- Vertx -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
<scope>provided</scope>
</dependency>

<!-- Tests -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
<version>${vertx.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-slf4j</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-log4j12.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
53 changes: 53 additions & 0 deletions vertx/run-tests.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env zsh

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

CHECK_CHAR='\U2713'
CROSS_CHAR='\U2717'

function print_result() {
version=$1
result=$2

if [[ $result == 0 ]];
then
mark=$CHECK_CHAR
color=$GREEN
else
mark=$CROSS_CHAR
color=$RED
fi

echo "\t${color}${version} ${mark}${NC}"
}

feign_versions=( "12.5" "13.5" )

for feign_version in $feign_versions; do
echo "Tests with Feign ${version}:"

printf "\tRun tests with Feign %s...\n" "${feign_version}"
mvn clean compile test -Dfeign.version="$feign_version" &> /dev/null
print_result "$feign_version" $?
done

declare -A vertx_versions
vertx_versions=( [v40x]="4.0.x", [v41x]="4.1.x", [v42x]="4.2.x", [v43x]="4.3.x", [v44x]="4.4.x", [v45x]="4.5.x" )
v40x=( "4.0.2" )
v41x=( "4.1.8" )
v42x=( "4.2.7" )
v43x=( "4.3.2" )
v44x=( "4.4.9" )
v45x=( "4.5.10" )

for version in ${(k)vertx_versions}; do
echo "Tests with Vertx ${vertx_versions[${version}]}:"

for vertx_version in ${(P)version}; do
printf "\tRun tests with Vertx %s...\n" "${vertx_version}"
mvn clean compile test -Dvertx.version="$vertx_version" &> /dev/null
print_result "$vertx_version" $?
done
done
Loading

0 comments on commit 001696e

Please sign in to comment.