use of io.grpc.Codec in project opentelemetry-java by open-telemetry.
the class DefaultGrpcExporterBuilder method build.
@Override
public GrpcExporter<T> build() {
ManagedChannel channel = this.channel;
if (channel == null) {
ManagedChannelBuilder<?> managedChannelBuilder = ManagedChannelBuilder.forTarget(endpoint.getAuthority());
if (endpoint.getScheme().equals("https")) {
managedChannelBuilder.useTransportSecurity();
} else {
managedChannelBuilder.usePlaintext();
}
if (metadata != null) {
managedChannelBuilder.intercept(MetadataUtils.newAttachHeadersInterceptor(metadata));
}
if (trustedCertificatesPem != null) {
try {
ManagedChannelUtil.setTrustedCertificatesPem(managedChannelBuilder, trustedCertificatesPem);
} catch (SSLException e) {
throw new IllegalStateException("Could not set trusted certificates for gRPC TLS connection, are they valid " + "X.509 in PEM format?", e);
}
}
if (retryPolicy != null) {
managedChannelBuilder.defaultServiceConfig(toServiceConfig(grpcServiceName, retryPolicy));
}
channel = managedChannelBuilder.build();
}
Codec codec = compressionEnabled ? new Codec.Gzip() : Codec.Identity.NONE;
MarshalerServiceStub<T, ?, ?> stub = stubFactory.apply(channel).withCompression(codec.getMessageEncoding());
return new DefaultGrpcExporter<>(type, channel, stub, meterProvider, timeoutNanos);
}
use of io.grpc.Codec in project grpc-spring-boot-starter by yidongnan.
the class AnnotationGrpcCodecDiscoverer method findGrpcCodecs.
@Override
public Collection<GrpcCodecDefinition> findGrpcCodecs() {
if (this.definitions == null) {
log.debug("Searching for codecs...");
final String[] beanNames = this.applicationContext.getBeanNamesForAnnotation(GrpcCodec.class);
final ImmutableList.Builder<GrpcCodecDefinition> builder = ImmutableList.builder();
for (final String beanName : beanNames) {
final Codec codec = this.applicationContext.getBean(beanName, Codec.class);
final GrpcCodec annotation = this.applicationContext.findAnnotationOnBean(beanName, GrpcCodec.class);
builder.add(new GrpcCodecDefinition(codec, annotation.advertised(), annotation.codecType()));
log.debug("Found gRPC codec: {}, bean: {}, class: {}", codec.getMessageEncoding(), beanName, codec.getClass().getName());
}
this.definitions = builder.build();
log.debug("Done");
}
return this.definitions;
}
use of io.grpc.Codec in project hummer-framework by hummer-team.
the class GrpcCommonCodecAutoConfiguration method defaultDecompressorRegistry.
@ConditionalOnBean(GrpcCodecDiscoverer.class)
@ConditionalOnMissingBean
@Bean
public DecompressorRegistry defaultDecompressorRegistry(final GrpcCodecDiscoverer codecDiscoverer) {
log.debug("Found GrpcCodecDiscoverer -> Creating custom DecompressorRegistry");
DecompressorRegistry registry = DecompressorRegistry.getDefaultInstance();
for (final GrpcCodecDefinition definition : codecDiscoverer.findGrpcCodecs()) {
if (definition.getCodecType().isForDecompression()) {
final Codec codec = definition.getCodec();
final boolean isAdvertised = definition.isAdvertised();
log.debug("Registering {} decompressor: '{}' ({})", isAdvertised ? "advertised" : "", codec.getMessageEncoding(), codec.getClass().getName());
registry = registry.with(codec, isAdvertised);
}
}
return registry;
}
use of io.grpc.Codec in project hummer-framework by hummer-team.
the class AnnotationGrpcCodecDiscoverer method findGrpcCodecs.
@Override
public Collection<GrpcCodecDefinition> findGrpcCodecs() {
if (this.definitions == null) {
log.debug("Searching for codecs...");
final String[] beanNames = this.applicationContext.getBeanNamesForAnnotation(GrpcCodec.class);
final ImmutableList.Builder<GrpcCodecDefinition> builder = ImmutableList.builder();
for (final String beanName : beanNames) {
final Codec codec = this.applicationContext.getBean(beanName, Codec.class);
final GrpcCodec annotation = this.applicationContext.findAnnotationOnBean(beanName, GrpcCodec.class);
builder.add(new GrpcCodecDefinition(codec, annotation.advertised(), annotation.codecType()));
log.debug("Found gRPC codec: {}, bean: {}, class: {}", codec.getMessageEncoding(), beanName, codec.getClass().getName());
}
this.definitions = builder.build();
log.debug("Done");
}
return this.definitions;
}
use of io.grpc.Codec in project opentelemetry-java by open-telemetry.
the class DefaultGrpcServiceBuilder method build.
@Override
public GrpcService<ReqT, ResT> build() {
ManagedChannel channel = this.channel;
if (channel == null) {
ManagedChannelBuilder<?> managedChannelBuilder = ManagedChannelBuilder.forTarget(endpoint.getAuthority());
if (endpoint.getScheme().equals("https")) {
managedChannelBuilder.useTransportSecurity();
} else {
managedChannelBuilder.usePlaintext();
}
if (metadata != null) {
managedChannelBuilder.intercept(MetadataUtils.newAttachHeadersInterceptor(metadata));
}
if (trustedCertificatesPem != null) {
try {
ManagedChannelUtil.setTrustedCertificatesPem(managedChannelBuilder, trustedCertificatesPem);
} catch (SSLException e) {
throw new IllegalStateException("Could not set trusted certificates for gRPC TLS connection, are they valid " + "X.509 in PEM format?", e);
}
}
if (retryPolicy != null) {
managedChannelBuilder.defaultServiceConfig(toServiceConfig(grpcServiceName, retryPolicy));
}
channel = managedChannelBuilder.build();
}
Codec codec = compressionEnabled ? new Codec.Gzip() : Codec.Identity.NONE;
MarshalerServiceStub<ReqT, ResT, ?> stub = stubFactory.apply(channel).withCompression(codec.getMessageEncoding());
return new DefaultGrpcService<>(type, channel, stub, timeoutNanos);
}
Aggregations