title: Local Pubsub Emulator won't work with Dataflow
body: <p>I am developing Dataflow in Java, the input comes from a Pubsub. Later, I saw a guide <a href="https://cloud.google.com/pubsub/docs/emulator" rel="nofollow noreferrer">here</a> on how to use local Pubsub emulator so I would not need to deploy to GCP in order to test.</p>
  
  <p>Here is my simple code:</p>
  
  <pre><code>private interface Options extends PipelineOptions, PubsubOptions, StreamingOptions {
  
      @Description("Pub/Sub topic to read messages from")
      String getTopic();
      void setTopic(String topic);
  
      @Description("Pub/Sub subscription to read messages from")
      String getSubscription();
      void setSubscription(String subscription);
  
      @Description("Local file output")
      String getOutput();
      void setOutput(String output);
  }
  
  public static void main(String[] args) {
  
      Options options = PipelineOptionsFactory
              .fromArgs(args)
              .withValidation()
              .as(Options.class);
      options.setStreaming(true);
      options.setPubsubRootUrl("localhost:8085");
  
      Pipeline pipeline = Pipeline.create(options);
      pipeline
          .apply("IngestFromPubsub", PubsubIO.readStrings().fromTopic(options.getTopic()))
          // other .apply's
  
      pipeline.run();
  
  }
  </code></pre>
  
  <p>I was able to follow the guide, including the part where I need to use the example Python code to create topic, subscription, publisher and even publish messages. When I use the Python code to interact with the Pubsub emulator, I notice the message <code>Detected HTTP/2 connection</code> in the command-line where I run the emulator:</p>
  
  <pre><code>Executing: cmd /c C:\...\google-cloud-sdk\platform\pubsub-emulator\bin\cloud-pubsub-emulator.bat --host=localhost --port=8085
  [pubsub] This is the Google Pub/Sub fake.
  [pubsub] Implementation may be incomplete or differ from the real system.
  [pubsub] Apr 10, 2020 3:33:26 PM com.google.cloud.pubsub.testing.v1.Main main
  [pubsub] INFO: IAM integration is disabled. IAM policy methods and ACL checks are not supported
  [pubsub] Apr 10, 2020 3:33:26 PM io.gapi.emulators.netty.NettyUtil applyJava7LongHostnameWorkaround
  [pubsub] INFO: Unable to apply Java 7 long hostname workaround.
  [pubsub] Apr 10, 2020 3:33:27 PM com.google.cloud.pubsub.testing.v1.Main main
  [pubsub] INFO: Server started, listening on 8085
  [pubsub] Apr 10, 2020 3:34:38 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
  [pubsub] INFO: Adding handler(s) to newly registered Channel.
  [pubsub] Apr 10, 2020 3:34:38 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
  [pubsub] INFO: Detected HTTP/2 connection.
  [pubsub] Apr 10, 2020 3:34:52 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
  [pubsub] INFO: Adding handler(s) to newly registered Channel.
  [pubsub] Apr 10, 2020 3:34:52 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
  [pubsub] INFO: Detected HTTP/2 connection.
  </code></pre>
  
  <p>I compiled/run the code in Eclipse using Dataflow Pipeline Run Configuration, but I get a problem.</p>
  
  <p><a href="https://i.stack.imgur.com/RZq3Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RZq3Z.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/fTQ4u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fTQ4u.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/DBbCX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DBbCX.png" alt="enter image description here"></a></p>
  
  <pre><code>Exception in thread "main" org.apache.beam.sdk.Pipeline$PipelineExecutionException: java.lang.RuntimeException: Failed to create subscription: 
  ...
  Caused by: java.lang.RuntimeException: Failed to create subscription: 
      at org.apache.beam.sdk.io.gcp.pubsub.PubsubUnboundedSource.createRandomSubscription(PubsubUnboundedSource.java:1427)
  ...
  Caused by: java.lang.IllegalArgumentException: java.net.MalformedURLException: unknown protocol: localhost
  ...
  Caused by: java.net.MalformedURLException: unknown protocol: localhost
  </code></pre>
  
  <p>When I try to add <code>http</code> in the line <code>options.setPubsubRootUrl("localhost:8085")</code>, I get an infinitely repeated exception:</p>
  
  <pre><code>com.google.api.client.http.HttpRequest execute
  WARNING: exception thrown while executing request
  java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
  </code></pre>
  
  <p>It seems to reach the Pubsub emulator but can't connect as the command-line where I run the emulator generates this infinitely also:</p>
  
  <pre><code>[pubsub] Apr 10, 2020 3:49:30 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
  [pubsub] INFO: Adding handler(s) to newly registered Channel.
  [pubsub] Apr 10, 2020 3:49:30 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
  [pubsub] INFO: Detected non-HTTP/2 connection.
  </code></pre>
  
  <p>How can I make my Dataflow work with Pubsub emulator?</p>