Repository: Azure/azure-functions-java-worker
Pull request #94 (2018-04-26 05:00:07)

HOTFIX: Add grpc max message length argument.
hotfix to unblock the worker publish.


Patch:
diff --git a/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/Application.java b/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/Application.java
index c83c036..6280b7d 100644
--- a/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/Application.java
+++ b/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/Application.java
@@ -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());
 
 
diff --git a/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/IApplication.java b/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/IApplication.java
index 01b61e7..921eef7 100644
--- a/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/IApplication.java
+++ b/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/IApplication.java
@@ -4,4 +4,5 @@ public interface IApplication {
     boolean logToConsole();
     String getHost();
     int getPort();
+    Integer getMaxMessageSize();
 }
diff --git a/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/JavaWorkerClient.java b/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/JavaWorkerClient.java
index 599e9ff..84d2fa4 100644
--- a/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/JavaWorkerClient.java
+++ b/azure-functions-java-worker/src/main/java/com/microsoft/azure/webjobs/script/JavaWorkerClient.java
@@ -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();


Test patch:
diff --git a/azure-functions-java-worker/src/test/java/com/microsoft/azure/webjobs/script/test/utilities/FunctionsTestHost.java b/azure-functions-java-worker/src/test/java/com/microsoft/azure/webjobs/script/test/utilities/FunctionsTestHost.java
index 637043e..a3e8b9d 100644
--- a/azure-functions-java-worker/src/test/java/com/microsoft/azure/webjobs/script/test/utilities/FunctionsTestHost.java
+++ b/azure-functions-java-worker/src/test/java/com/microsoft/azure/webjobs/script/test/utilities/FunctionsTestHost.java
@@ -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;