This repository was archived by the owner on Dec 8, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathPublisher.java
More file actions
54 lines (45 loc) · 1.68 KB
/
Copy pathPublisher.java
File metadata and controls
54 lines (45 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package lesson05.solution;
import com.google.common.collect.ImmutableMap;
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.setup.Environment;
import io.jaegertracing.internal.JaegerTracer;
import io.opentracing.Scope;
import io.opentracing.Tracer;
import lib.Tracing;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
public class Publisher extends Application<Configuration> {
private final Tracer tracer;
private Publisher(Tracer tracer) {
this.tracer = tracer;
}
@Path("/publish")
@Produces(MediaType.TEXT_PLAIN)
public class PublisherResource {
@GET
public String format(@QueryParam("helloStr") String helloStr, @Context HttpHeaders httpHeaders) {
try (Scope scope = Tracing.startServerSpan(tracer, httpHeaders, "publish")) {
System.out.println(helloStr);
scope.span().log(ImmutableMap.of("event", "println", "value", helloStr));
return "published";
}
}
}
@Override
public void run(Configuration configuration, Environment environment) throws Exception {
environment.jersey().register(new PublisherResource());
}
public static void main(String[] args) throws Exception {
System.setProperty("dw.server.applicationConnectors[0].port", "8082");
System.setProperty("dw.server.adminConnectors[0].port", "9082");
try (JaegerTracer tracer = Tracing.init("publisher")) {
new Publisher(tracer).run(args);
}
}
}