Skip to content

Commit

Permalink
Updates gRPC client channel config structure to use blueprints. Chann…
Browse files Browse the repository at this point in the history
…els are now defined under grpc.client.channels.

Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
  • Loading branch information
spericas committed Jul 31, 2024
1 parent e1a76ab commit 4450e1f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 41 deletions.
31 changes: 16 additions & 15 deletions examples/microprofile/grpc/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ server:
resource-path: "server.p12"

grpc:
channels:
string-channel:
port: 0
tls:
trust:
keystore:
passphrase: "password"
trust-store: true
resource:
resource-path: "client.p12"
private-key:
keystore:
passphrase: "password"
resource:
resource-path: "client.p12"
client:
channels:
- name: "string-channel"
port: 0
tls:
trust:
keystore:
passphrase: "password"
trust-store: true
resource:
resource-path: "client.p12"
private-key:
keystore:
passphrase: "password"
resource:
resource-path: "client.p12"
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ChannelProducer {
*/
@Inject
ChannelProducer(Config config) {
provider = GrpcChannelsProvider.create(config.get("grpc"));
provider = GrpcChannelsProvider.create(config.get("grpc.client"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
@Prototype.Configured
interface GrpcChannelDescriptorBlueprint {

/**
* The name of this channel.
*
* @return channel name
*/
@Option.Configured
String name();

/**
* The host to connect to.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.microprofile.grpc.client;

import java.util.List;

import io.helidon.builder.api.Option;
import io.helidon.builder.api.Prototype;

@Prototype.Blueprint
@Prototype.Configured
interface GrpcChannelsDescriptorBlueprint {

/**
* List of channel descriptors.
*
* @return channel descriptors
*/
@Option.Configured
List<GrpcChannelDescriptor> channels();
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Channel channel(String name) {
throw new IllegalArgumentException("name cannot be empty or blank.");
}
GrpcChannelDescriptor chCfg = channelConfigs.computeIfAbsent(name, hostName ->
GrpcChannelDescriptor.builder().host(name).build());
GrpcChannelDescriptor.builder().name(name).host(name).build());
return createChannel(name, chCfg);
}

Expand Down Expand Up @@ -176,20 +176,14 @@ public static class Builder implements io.helidon.common.Builder<Builder, GrpcCh

private Builder(Config config) {
// Add the default channel (which can be overridden in the config)
channel(DEFAULT_CHANNEL_NAME, GrpcChannelDescriptor.builder().build());
channel(DEFAULT_CHANNEL_NAME, GrpcChannelDescriptor.builder().name(DEFAULT_CHANNEL_NAME).build());

if (config == null) {
return;
}

Config channelsConfig = config.get(CFG_KEY_CHANNELS);
if (channelsConfig.exists()) {
for (Config channelConfig : channelsConfig.asNodeList().get()) {
String key = channelConfig.key().name();
GrpcChannelDescriptor cfg = GrpcChannelDescriptor.builder().config(channelConfig).build();
channelConfigs.put(key, cfg);
}
}
GrpcChannelsDescriptor channelsDescriptor = GrpcChannelsDescriptor.builder().config(config).build();
channelsDescriptor.channels().forEach(ch -> channelConfigs.put(ch.name(), ch));
}

/**
Expand Down
31 changes: 16 additions & 15 deletions microprofile/grpc/client/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ server:
resource-path: "server.p12"

grpc:
channels:
echo-channel:
port: 0
tls:
trust:
keystore:
passphrase: "password"
trust-store: true
resource:
resource-path: "client.p12"
private-key:
keystore:
passphrase: "password"
resource:
resource-path: "client.p12"
client:
channels:
- name: "echo-channel"
port: 0
tls:
trust:
keystore:
passphrase: "password"
trust-store: true
resource:
resource-path: "client.p12"
private-key:
keystore:
passphrase: "password"
resource:
resource-path: "client.p12"

0 comments on commit 4450e1f

Please sign in to comment.