|
| 1 | +package com.freemanan.example; |
| 2 | + |
| 3 | +import com.freemanan.starter.grpc.client.EnableGrpcClients; |
| 4 | +import io.grpc.testing.protobuf.SimpleRequest; |
| 5 | +import io.grpc.testing.protobuf.SimpleResponse; |
| 6 | +import io.grpc.testing.protobuf.SimpleServiceGrpc; |
| 7 | +import io.micrometer.core.instrument.Counter; |
| 8 | +import io.micrometer.core.instrument.MeterRegistry; |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; |
| 10 | +import org.springframework.boot.ApplicationArguments; |
| 11 | +import org.springframework.boot.ApplicationRunner; |
| 12 | +import org.springframework.boot.SpringApplication; |
| 13 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 14 | + |
| 15 | +/** |
| 16 | + * @author Freeman |
| 17 | + */ |
| 18 | +@SpringBootApplication |
| 19 | +@EnableGrpcClients("io.grpc") |
| 20 | +public class App implements ApplicationRunner { |
| 21 | + private final Counter counter; |
| 22 | + |
| 23 | + public App(MeterRegistry mr) { |
| 24 | + this.counter = Counter.builder("app_run") |
| 25 | + .description("app run") |
| 26 | + .tags("app", "metrics-test") |
| 27 | + .register(mr); |
| 28 | + } |
| 29 | + |
| 30 | + @Autowired |
| 31 | + SimpleServiceGrpc.SimpleServiceBlockingStub stub; |
| 32 | + |
| 33 | + public static void main(String[] args) { |
| 34 | + SpringApplication.run(App.class, args); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public void run(ApplicationArguments args) throws Exception { |
| 39 | + counter.increment(); |
| 40 | + SimpleResponse resp = stub.unaryRpc( |
| 41 | + SimpleRequest.newBuilder().setRequestMessage("Hello").build()); |
| 42 | + System.out.println(resp); |
| 43 | + } |
| 44 | +} |
0 commit comments