Skip to content

Commit

Permalink
Added opentracing, resteasy, mutiny example
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Nov 11, 2020
1 parent 9bb0d17 commit 46577f7
Show file tree
Hide file tree
Showing 20 changed files with 528 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 010-quarkus-opentracing-reactive-grpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Module that test whether the opentracing data is transmitted among REST resources using Rest Client.
There are two applications:
- Ping application that will invoke the Pong application using the RestClient and will return the expected "ping pong" output.
- Pong application that will return the "pong" output.
67 changes: 67 additions & 0 deletions 010-quarkus-opentracing-reactive-grpc/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus.qe</groupId>
<artifactId>beefy-scenarios</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>010-quarkus-opentracing-reactive-grpc</artifactId>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-opentracing</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.qe.ping;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import io.quarkus.example.PongRequest;
import io.quarkus.example.PongServiceGrpc;
import io.quarkus.grpc.runtime.annotations.GrpcService;
import io.quarkus.qe.traceable.TraceableResource;

@Path("/grpc-ping")
public class GrpcPingResource extends TraceableResource {

@Inject
@GrpcService("pong")
PongServiceGrpc.PongServiceBlockingStub pongClient;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String getPing() {
recordTraceId();

return "ping " + pongClient.sayPong(PongRequest.newBuilder().build()).getMessage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.qe.ping;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.qe.ping.clients.PongClient;
import io.quarkus.qe.traceable.TraceableResource;

@Path("/rest-ping")
public class PingResource extends TraceableResource {

@Inject
@RestClient
PongClient pongClient;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String getPing() {
recordTraceId();

return "ping " + pongClient.getPong();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.quarkus.qe.ping;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.qe.ping.clients.ReactivePongClient;
import io.quarkus.qe.traceable.TraceableResource;
import io.smallrye.mutiny.Uni;

@Path("/reactive-ping")
public class ReactivePingResource extends TraceableResource {

@Inject
@RestClient
ReactivePongClient pongClient;

@GET
@Produces(MediaType.TEXT_PLAIN)
public Uni<String> getPing() {
recordTraceId();
return pongClient.getPong().onItem().transform(response -> {
return "ping " + response;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.quarkus.qe.ping.clients;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterRestClient
public interface PongClient {
@GET
@Path("/rest-pong")
@Produces(MediaType.TEXT_PLAIN)
String getPong();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.qe.ping.clients;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import io.smallrye.mutiny.Uni;

@RegisterRestClient
public interface ReactivePongClient {
@GET
@Path("/reactive-pong")
@Produces(MediaType.TEXT_PLAIN)
Uni<String> getPong();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.quarkus.qe.pong;

import javax.inject.Singleton;

import org.jboss.logmanager.MDC;

import io.grpc.stub.StreamObserver;
import io.quarkus.example.PongReply;
import io.quarkus.example.PongRequest;
import io.quarkus.example.PongServiceGrpc;

@Singleton
public class GrpcPongService extends PongServiceGrpc.PongServiceImplBase {

private String lastTraceId;

@Override
public void sayPong(PongRequest request, StreamObserver<PongReply> responseObserver) {
lastTraceId = MDC.get("traceId");
responseObserver.onNext(PongReply.newBuilder().setMessage("pong").build());
responseObserver.onCompleted();
}

public String getLastTraceId() {
return lastTraceId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.qe.pong;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import io.quarkus.qe.traceable.TraceableResource;

@Path("/rest-pong")
public class PongResource extends TraceableResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String getPong() {
recordTraceId();
return "pong";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.qe.pong;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import io.quarkus.qe.traceable.TraceableResource;
import io.smallrye.mutiny.Uni;

@Path("/reactive-pong")
public class ReactivePongResource extends TraceableResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public Uni<String> getPong() {
recordTraceId();
return Uni.createFrom().item("pong");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.qe.traceable;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.jboss.logging.Logger;
import org.jboss.logmanager.MDC;

public abstract class TraceableResource {

private static final Logger LOG = Logger.getLogger(TraceableResource.class);

private String lastTraceId;

@GET
@Path("/lastTraceId")
@Produces(MediaType.TEXT_PLAIN)
public String getLastTraceId() {
return lastTraceId;
}

protected void recordTraceId() {
lastTraceId = MDC.get("traceId");
LOG.info("Recorded trace ID: " + lastTraceId);
}
}
18 changes: 18 additions & 0 deletions 010-quarkus-opentracing-reactive-grpc/src/main/proto/pong.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.quarkus.example";
option java_outer_classname = "PongProto";

package io.quarkus.example;

service PongService {
rpc SayPong (PongRequest) returns (PongReply) {}
}

message PongRequest {
}

message PongReply {
string message = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Quarkus
quarkus.http.port=8081

# Jaeger
quarkus.jaeger.service-name=pingpong
quarkus.jaeger.sampler-type=const
quarkus.jaeger.sampler-param=1
quarkus.log.console.format=%d{HH:mm:ss} %-5p traceId=%X{traceId}, parentId=%X{parentId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{2.}] (%t) %s%e%n

# RestClient
io.quarkus.qe.ping.clients.PongClient/mp-rest/url=http://localhost:8081
io.quarkus.qe.ping.clients.PongClient/mp-rest/scope=javax.inject.Singleton

io.quarkus.qe.ping.clients.ReactivePongClient/mp-rest/url=http://localhost:8081
io.quarkus.qe.ping.clients.ReactivePongClient/mp-rest/scope=javax.inject.Singleton

# gRPC
quarkus.grpc.clients.pong.host=localhost
Loading

0 comments on commit 46577f7

Please sign in to comment.