Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc over http/2 poc #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ext {
slf4j_version = "2.0.7"
javax_version = "1.3.2"
vertx_version = "4.4.4"
protoc_version = "3.23.2"
grpc_version = "1.56.0"

otl_version = "1.25.0"
micrometer_version = "1.10.6"
Expand Down
30 changes: 30 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

buildscript {
dependencies {
// ASSUMES GRADLE 2.12 OR HIGHER. Use plugin version 0.7.5 with earlier gradle versions
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.9.3'
}
}

plugins {
id 'com.flipkart.varadhi.java-application-conventions'
id 'com.google.protobuf' version "0.9.3"
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protoc_version"
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:$grpc_version"
}
vertx {
artifact = "io.vertx:vertx-grpc-protoc-plugin2:$vertx_version"
}
}
generateProtoTasks {
all()*.plugins {
grpc
vertx
}
}
}

dependencies {

Expand All @@ -22,6 +49,9 @@ dependencies {
implementation("io.vertx:vertx-config")
implementation("io.vertx:vertx-config-yaml")
implementation("io.vertx:vertx-web")
implementation("io.vertx:vertx-grpc-server:$vertx_version")
implementation("io.vertx:vertx-grpc-client:$vertx_version")
implementation("io.vertx:vertx-grpc-context-storage:$vertx_version")
implementation("io.vertx:vertx-auth-common")
implementation("io.vertx:vertx-auth-jwt")
implementation("io.vertx:vertx-opentelemetry")
Expand Down
29 changes: 29 additions & 0 deletions server/src/main/java/com/flipkart/varadhi/RestVerticle.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package com.flipkart.varadhi;

import com.flipkart.varadhi.exceptions.InvalidStateException;
import com.flipkart.varadhi.web.Extensions;
import com.flipkart.varadhi.web.FailureHandler;
import com.flipkart.varadhi.web.routes.RouteBehaviour;
import com.flipkart.varadhi.web.routes.RouteConfigurator;
import com.flipkart.varadhi.web.routes.RouteDefinition;
import com.flipkart.varadhi.web.v1.proto.MessageProducerGrpc;
import com.flipkart.varadhi.web.v1.proto.SingleMessageResponse;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.HttpVersion;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.Router;
import io.vertx.grpc.common.GrpcStatus;
import io.vertx.grpc.server.GrpcServer;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand All @@ -36,6 +44,27 @@ public void start(Promise<Void> startPromise) {
log.info("HttpServer Starting.");
Router router = Router.router(vertx);

// grpc
GrpcServer grpcServer = GrpcServer.server(vertx);

grpcServer.callHandler(MessageProducerGrpc.getProduceMethod(), request -> {
request.response().status(GrpcStatus.OK).statusMessage("OK")
.end(SingleMessageResponse.newBuilder().setOffset("0001").build());
});

router.route()
.consumes("application/grpc")
.produces("application/grpc")
.handler(req -> grpcServer.handle(req.request()));

router.route()
.consumes("application/json")
.produces("application/json")
.path("/topics/produce")
.method(HttpMethod.POST)
.handler(rc -> Extensions.RoutingContextExtension.endRequestWithResponse(rc, 200, "0001"));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Planning to keep it or move it appropriately to ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya. its a TODO, will fix it in this PR.

// http
FailureHandler failureHandler = new FailureHandler();
for (RouteDefinition def : apiRoutes) {
Route route = router.route().method(def.method()).path(def.path());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.flipkart.varadhi.services.VaradhiTopicService;
import com.flipkart.varadhi.web.Extensions.RequestBodyExtension;
import com.flipkart.varadhi.web.Extensions.RoutingContextExtension;
import com.flipkart.varadhi.web.HandlerUtil;
import com.flipkart.varadhi.web.routes.RouteDefinition;
import com.flipkart.varadhi.web.routes.RouteProvider;
import com.flipkart.varadhi.web.routes.SubRoutes;
Expand Down
19 changes: 19 additions & 0 deletions server/src/main/proto/api.v1.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.flipkart.varadhi.web.v1.proto";
option java_outer_classname = "ProduceApi";

// The greeting service definition.
service MessageProducer {
// Sends a greeting
rpc produce (SingleMessageRequest) returns (SingleMessageResponse) {}
}

message SingleMessageRequest {
string payload = 1;
}

message SingleMessageResponse {
string offset = 1;
}