title: Cannot access KTable from a different app as StateStore
body: <p>I have two Java Application (App1, App2) to test how to access a <code>KTable</code> from a different app on a single instance environment in docker.</p>
  
  <p>The first App (App1) writes to a <code>KTable</code> with following code.</p>
  
  <pre><code>public static void main(String[] args)
      {
          final Properties props = new Properties();
  
      props.put(StreamsConfig.APPLICATION_ID_CONFIG,"gateway-service");   
      props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "172.18.0.11:9092");
      props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG,Serdes.String().getClass().getName());
      props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, ServiceTransactionSerde.class);
  
  
      KStreamBuilder builder = new KStreamBuilder();
  
  
      KStream&lt;String,ServiceTransaction&gt; source = builder.stream("gateway_request_processed");
  
  
      KStream&lt;String, Long&gt; countByApi = source.groupBy((key,value)-&gt; value.getApiId().toString()).count("Counts").toStream();
  
      countByApi.to(Serdes.String(), Serdes.Long(),"countByApi");
  
      countByApi.print();
  
      final KafkaStreams streams = new KafkaStreams(builder,props);
  
      streams.start();
      System.out.println(streams.state());
  
      System.out.println(streams.allMetadata());
      System.out.println(streams.allMetadataForStore("countByApi"));
  
      Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
  
  
          @Override
          public void run() {
              System.out.println(streams.allMetadata());
              streams.close();
          }
      }));
  }
  </code></pre>
  
  <p>When I run my producer I got following output for the code in App1</p>
  
  <pre><code>    RUNNING
  []
  []
  [KTABLE-TOSTREAM-0000000006]: c00af5ee-3c2d-4d12-9c4b-3b55c1284dd6, 19
  </code></pre>
  
  <p>This shows me state = RUNNING. Metadata are empty also for the store. But the request gets processed and store in the KTable successfully (String,Long).</p>
  
  <p>When I run <code>kafka-topics.sh --list --zookeeper:2181</code>
  I get the following topics. </p>
  
  <pre><code>bash-4.3# kafka-topics.sh --list --zookeeper zookeeper:2181
  __consumer_offsets
  countByApi
  gateway-Counts-changelog
  gateway-Counts-repartition
  gateway-service-Counts-changelog
  gateway-service-Counts-repartition
  gateway_request_processed
  </code></pre>
  
  <p>This shows me that the KTable is somehow persisted with new topics.</p>
  
  <p>I then have a secound command line app (App2) with following code which tries to access this <code>KTable</code> as a state store (<code>ReadOnlyKeyValueStore</code>) and access it.</p>
  
  <pre><code> public static void main( String[] args )
      {
          final Properties props = new Properties();
          props.put(StreamsConfig.APPLICATION_ID_CONFIG, "gateway-service-table-client");
          props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "172.18.0.11:9092");
  
  
          KStreamBuilder builder = new KStreamBuilder();
          KafkaStreams streams = new KafkaStreams(builder,props);
  
          streams.cleanUp();
          streams.start();
          System.out.println( "Hello World!" );
          System.out.println(streams.state());
  
          ReadOnlyKeyValueStore&lt;String,Long&gt; keyValueStore =
          streams.store("countByApi", QueryableStoreTypes.keyValueStore());
  
          final KeyValueIterator&lt;String,Long&gt; range = keyValueStore.all();
  
          while(range.hasNext()){
              KeyValue&lt;String,Long&gt; next = range.next();
              System.out.println(String.format("key: %s | value: %s", next.key,next.value));
  
          }
  
          Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
  
  
                          @Override
                          public void run() {
                              System.out.println(streams.allMetadata());
                              streams.close();
                          }
          }));
  
      }
  </code></pre>
  
  <p>When I run the 2. App I do get the error message:</p>
  
  <pre><code>    RUNNING
  Exception in thread "main" org.apache.kafka.streams.errors.InvalidStateStoreException: the state store, countByApi, may have migrated to another instance.
      at org.apache.kafka.streams.state.internals.QueryableStoreProvider.getStore(QueryableStoreProvider.java:60)
      at org.apache.kafka.streams.KafkaStreams.store(KafkaStreams.java:728)
      at com.comp.streamtable.App.main(App.java:37)
  </code></pre>
  
  <p>Unfortunatly I do have only 1 instance and I verify that the state is equal "RUNNING".</p>
  
  <p>Note: I had to choose different application.id for each app since this thew another Exception. Just wanted to point this out since this might be for interest.</p>
  
  <p>What do I miss here to access my KTable from another app?</p>