Hotfix: Add grpc max message length argument. (#94)

This commit is contained in:
Junyi Yi 2018-04-26 01:02:21 -04:00
Родитель c1f426f91b
Коммит e6c21f8c0d
4 изменённых файлов: 26 добавлений и 2 удалений

Просмотреть файл

@ -1,6 +1,5 @@
package com.microsoft.azure.webjobs.script;
import java.io.*;
import java.util.logging.*;
import javax.annotation.*;
@ -21,6 +20,8 @@ public final class Application implements IApplication {
public int getPort() { return this.port; }
@Override
public boolean logToConsole() { return this.logToConsole; }
@Override
public Integer getMaxMessageSize() { return this.maxMessageSize; }
private String getWorkerId() { return this.workerId; }
private String getRequestId() { return this.requestId; }
@ -41,6 +42,9 @@ public final class Application implements IApplication {
this.workerId = this.parseWorkerId(commands.getOptionValue("w"));
this.requestId = this.parseRequestId(commands.getOptionValue("q"));
this.logToConsole = commands.hasOption("l");
if (commands.hasOption("m")) {
this.maxMessageSize = this.parseMaxMessageSize(commands.getOptionValue("m"));
}
this.commandParseSucceeded = true;
} catch (ParseException ex) {
WorkerLogManager.getSystemLogger().severe(ex.toString());
@ -67,11 +71,20 @@ public final class Application implements IApplication {
private String parseWorkerId(String input) { return input; }
private Integer parseMaxMessageSize(String input) {
try {
return Integer.parseInt(input);
} catch (NumberFormatException ex) {
return null;
}
}
private boolean commandParseSucceeded = false;
private String host;
private int port;
private String workerId, requestId;
private boolean logToConsole;
private Integer maxMessageSize = null;
private final Options OPTIONS = new Options()
.addOption(Option.builder("h").longOpt("host")
@ -96,6 +109,10 @@ public final class Application implements IApplication {
.build())
.addOption(Option.builder("l").longOpt("consoleLog")
.desc("Whether to duplicate all host logs to console as well")
.build())
.addOption(Option.builder("m").longOpt("grpcMaxMessageLength")
.hasArg().argName("MessageSizeInBytes")
.desc("The maximum message size could be used by GRPC protocol")
.build());

Просмотреть файл

@ -4,4 +4,5 @@ public interface IApplication {
boolean logToConsole();
String getHost();
int getPort();
Integer getMaxMessageSize();
}

Просмотреть файл

@ -22,7 +22,11 @@ import com.microsoft.azure.webjobs.script.rpc.messages.*;
public class JavaWorkerClient implements AutoCloseable {
public JavaWorkerClient(IApplication app) {
WorkerLogManager.initialize(this, app.logToConsole());
this.channel = ManagedChannelBuilder.forAddress(app.getHost(), app.getPort()).usePlaintext(true).build();
ManagedChannelBuilder<?> chanBuilder = ManagedChannelBuilder.forAddress(app.getHost(), app.getPort()).usePlaintext(true);
if (app.getMaxMessageSize() != null) {
chanBuilder.maxInboundMessageSize(app.getMaxMessageSize());
}
this.channel = chanBuilder.build();
this.peer = new AtomicReference<>(null);
this.handlerSuppliers = new HashMap<>();
this.classPathProvider = new DefaultClassLoaderProvider();

Просмотреть файл

@ -66,6 +66,8 @@ public final class FunctionsTestHost implements AutoCloseable, IApplication {
public String getHost() { return "localhost"; }
@Override
public int getPort() { return 55005; }
@Override
public Integer getMaxMessageSize() { return null; }
private JavaWorkerClient client;
private HostGrpcImplementation grpcHost;