/
Program.cs
70 lines (64 loc) · 2.62 KB
/
Program.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using Grpc.Core;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System.Collections.Generic;
using System.Linq;
using System;
namespace grpc_test
{
public class Program
{
public static void Main(string[] args)
{
if (args.Count() >= 1 && args[0] == "ping") {
Console.WriteLine("Doing initial bounce");
DoTheBounce();
} else {
CreateHostBuilder(args).Build().Run();
}
}
public static string EnvVarOrDefault(string varname, string defaultVal)
{
var env = Environment.GetEnvironmentVariable(varname);
if (env == null || env == "") {
return defaultVal;
}
return env;
}
public static void DoTheBounce() {
Environment.SetEnvironmentVariable("GRPC_TRACE", "api");
Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "debug");
Grpc.Core.GrpcEnvironment.SetLogger(new Grpc.Core.Logging.ConsoleLogger());
var targetA = EnvVarOrDefault("TARGET_A", "localhost:5001");
var targetB = EnvVarOrDefault("TARGET_B", "localhost:5002");
Console.WriteLine($"A: {targetA} B: {targetB}");
var nextTargetA = false;
var chanceToDoIt = 0.70;
var channel = new Channel(targetA, ChannelCredentials.Insecure);
var client = new Bouncer.BouncerClient(channel);
try {
var reply = client.BounceIt(new BounceRequest {
TargetA = targetA,
TargetB = targetB,
DoTargetA = nextTargetA,
ChanceOfBounce = chanceToDoIt,
TabLevel = ""
});
Console.WriteLine($"Reply: {reply.Msg}");
} catch (RpcException e) {
Console.WriteLine("Woops, looks like we got an exception. " +
"Just make sure to run this a few times to get " +
"some data for Jaeger.");
Console.WriteLine("*** RpcException Start ***");
Console.WriteLine(e);
Console.WriteLine("*** RpcException End ***");
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}