LaunchDarkly: Flushing data from client in offline mode

632 Views Asked by At

I'm working on a POC using LaunchDarkly's Java + Redis SDK and one of my requirements is initializing a 2nd LaunchDarkly client in "offline" mode. Due to my existing architecture one application will connect to LaunchDarkly and hydrate a Redis instance. The 2nd application will connect to the same data store, but the client will initialize as "offline" -- is there currently a way for me to read stored events from the offline client and flush them to the LaunchDarkly servers?

In the code snippet below I am initializing the first client + redis store, then initializing a 2nd client in a background thread that connects to the same local redis instance. I can confirm that when I run this snippet I do not see events populate in the LaunchDarkly UI.

NOTE: this is POC to determine whether LaunchDarkly will work for my use case. It is not a Production-grade implementation.

public static void main(String[] args) throws IOException {
        LDConfig config = new LDConfig.Builder().dataStore(Components
                .persistentDataStore(
                        Redis.dataStore().uri(URI.create("redis://127.0.0.1:6379")).prefix("my-key-prefix"))
                .cacheSeconds(30)).build();

        LDClient ldClient = new LDClient("SDK-KEY", config);

        Runnable r = new Runnable() {
            @Override
            public void run() {
                LDConfig offlineConfig = new LDConfig.Builder().dataStore(Components
                        .persistentDataStore(
                                Redis.dataStore().uri(URI.create("redis://127.0.0.1:6379")).prefix("my-key-prefix"))
                        .cacheSeconds(30)).offline(true).build();
                LDClient offlineClient = new LDClient("SDK-KEY", offlineConfig);

                String uniqueId = "abcde";
                LDUser user = new LDUser.Builder(uniqueId).custom("customField", "customValue").build();

                boolean showFeature = offlineClient.boolVariation("test-feature-flag", user, false);
                if (showFeature) {
                    System.out.println("Showing your feature");
                } else {
                    System.out.println("Not showing your feature");
                }

                try {
                    offlineClient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };

        ExecutorService executor = Executors.newCachedThreadPool();
        executor.submit(r);
        executor.shutdown();

        ldClient.close();
    }
0

There are 0 best solutions below