Skip to content

Java SDK

The можно Java SDK provides local evaluation of feature flags on the JVM. Compatible with JDK 17+, supports synchronous evaluation, and integrates with Spring Boot via auto-configuration.

Installation

Gradle (Kotlin DSL)

kotlin
repositories {
    mavenCentral()
}

dependencies {
    implementation("dev.mozhno:mozhno-client-java:1.1.1")
}

Gradle (Groovy DSL)

groovy
repositories {
    mavenCentral()
}

dependencies {
    implementation 'dev.mozhno:mozhno-client-java:1.1.1'
}

Tip: Check the GitHub releases page for the latest version.

Configuration

The SDK uses a builder pattern for client construction. Create a single client instance and reuse it across your application:

java
import dev.mozhno.sdk.MozhnoClient;
import dev.mozhno.sdk.MozhnoConfig;
import dev.mozhno.sdk.MozhnoContext;
import dev.mozhno.sdk.DefaultMozhnoClient;

MozhnoConfig config = MozhnoConfig.builder()
    .appName("my-app")
    .instanceId("instance-1")
    .mozhnoUrl("https://mozhno.example.com")
    .apiKey("<api-key>")
    .fetchTogglesInterval(15)
    .sendMetricsInterval(60)
    .environment("production")
    .build();

MozhnoClient client = new DefaultMozhnoClient(config);
client.start();

Builder Options

MethodTypeDefaultDescription
appName(String)StringRequiredYour application identifier
instanceId(String)StringRequiredUnique instance identifier
mozhnoUrl(String)StringRequiredBase URL of your можно instance
apiKey(String)StringRequiredAPI key for the target environment
fetchTogglesInterval(int)int15 secPolling interval
sendMetricsInterval(int)int60 secMetrics reporting interval
environment(String)StringnullEnvironment name
disableMetrics(boolean)booleanfalseDisable metrics reporting
synchronousFetchOnInitialisation(boolean)booleanfalseBlock on initial flag fetch
stickyAnonId(boolean)booleantrueAuto-generate a stable anonymous ID for rollout bucketing
contextProvider(MozhnoContextProvider)nullCustom context provider

Spring Boot Auto-Configuration

The SDK provides auto-configuration via MozhnoAutoConfiguration. Configure via application.yml:

yaml
mozhno:
  url: https://mozhno.example.com
  api-key: <api-key>
  app-name: my-app
  instance-id: ${random.uuid}
  environment: production
  fetch-toggles-interval: 15
  send-metrics-interval: 60
  sticky-anon-id: true

The client is automatically created and available as a Spring bean:

java
@Service
public class CheckoutService {

    private final MozhnoClient mozhnoClient;

    public CheckoutService(MozhnoClient mozhnoClient) {
        this.mozhnoClient = mozhnoClient;
    }

    public boolean isNewCheckoutEnabled(String userId) {
        MozhnoContext context = MozhnoContext.builder()
            .userId(userId)
            .addProperty("country", "DE")
            .build();
        return mozhnoClient.isEnabled("checkout_v2", context);
    }
}

MozhnoContext

A builder-based context object for providing attributes at evaluation time.

java
import dev.mozhno.sdk.MozhnoContext;

MozhnoContext context = MozhnoContext.builder()
    .userId("user-12345")
    .sessionId("session-abc")
    .addProperty("country", "DE")
    .addProperty("plan", "enterprise")
    .addProperty("appVersion", "2.4.1")
    .build();

All attribute values are strings. For numeric comparisons, set contextType: number in your targeting rules.

Anonymous Users and Rollout

For percentage rollout, the SDK uses userId, then sessionId, as the bucketing identifier. When neither is present in the context, the client auto-generates a stable anonymousId (a random UUID created at client startup) and uses it instead — anonymous traffic is bucketed uniformly and stays stable for each application instance. To disable this behavior, use stickyAnonId(false) (or mozhno.sticky-anon-id: false in Spring); in that case all anonymous requests without an identifier land in a single bucket and the SDK logs a warning. See the rollout guide for upgrade behavior details.

MethodDescription
userId(String)User ID (used for percentage rollout hashing)
sessionId(String)Session ID (fallback for hashing)
addProperty(String key, String value)Arbitrary attribute

Next Steps

Released under the BSL 1.1 License.