Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Relay Proxy #7

Open
shanman190 opened this issue Aug 23, 2023 · 0 comments
Open

Use Relay Proxy #7

shanman190 opened this issue Aug 23, 2023 · 0 comments
Labels

Comments

@shanman190
Copy link
Collaborator

shanman190 commented Aug 23, 2023

Update the LDClient configuration to use a defined Relay Proxy.

Before:

import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key");
        LDContext context = LDContext.builder("context-key")
                .name("user")
                .build();
        boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}

After (5.9 or later):

import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key", new LDConfig.Builder()
                .serviceEndpoints(Components.serviceEndpoints()
                        .relayProxy("https://your-relay-proxy.com:8030"))
                .build());
        LDContext context = LDContext.builder("context-key")
                .name("user")
                .build();
        boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}

After (5.8 or earlier):

import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key", LDConfig.Builder()
                .dataSource(Components.streamingDataSource()
                        .baseURI(URI.create("https://your-relay-proxy.com:8030"))
                .events(Components.sendEvents()
                        .baseURI(URI.create("https://your-relay-proxy.com:8030"))
                .build());
        LDContext context = LDContext.builder("context-key")
                .name("user")
                .build();
        boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}
@timtebeek timtebeek moved this to Recipes Wanted in OpenRewrite Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Recipes Wanted
Development

No branches or pull requests

1 participant