-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathFrontend.java
42 lines (35 loc) · 1.66 KB
/
Frontend.java
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
package brave.example;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.server.Server;
import com.linecorp.armeria.server.brave.BraveService;
import com.linecorp.armeria.server.healthcheck.HealthCheckService;
import com.linecorp.armeria.server.logging.LoggingService;
import java.util.Properties;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
public final class Frontend {
public static void main(String[] args) {
TracingConfiguration tracing = TracingConfiguration.create("frontend", true);
Properties configs = new Properties();
String kafkaBootstrapServers = System.getProperty("kafka.bootstrap-servers", "localhost:19092");
configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaBootstrapServers);
StringSerializer keySerializer = new StringSerializer();
StringSerializer valueSerializer = new StringSerializer();
Producer<String, String> producer =
tracing.kafkaTracing.producer(new KafkaProducer<>(configs, keySerializer, valueSerializer));
Server server = Server.builder()
.http(8081)
.service("/health", HealthCheckService.of())
.service("/", (ctx, req) -> {
producer.send(new ProducerRecord<>("input", "hello", "world"));
return HttpResponse.of(202);
})
.decorator(BraveService.newDecorator(tracing.httpTracing))
.decorator(LoggingService.newDecorator())
.build();
server.start().join();
}
}