0

Created a brand new micronaut application with below dependencies

dependencies {
    annotationProcessor("io.micronaut:micronaut-http-validation")
    annotationProcessor("io.micronaut.microstream:micronaut-microstream-annotations")
    implementation("io.micronaut:micronaut-http-client")
    implementation("io.micronaut:micronaut-jackson-databind")
    implementation("io.micronaut.microstream:micronaut-microstream")
    implementation("io.micronaut.microstream:micronaut-microstream-annotations")
    implementation("jakarta.annotation:jakarta.annotation-api")
    runtimeOnly("ch.qos.logback:logback-classic")
    developmentOnly("io.micronaut.microstream:micronaut-microstream-rest")
    annotationProcessor("io.micronaut.security:micronaut-security-annotations")
    implementation("io.micronaut.security:micronaut-security")
}

created a class as below

public class Fruit {
    @NonNull
    @NotBlank
    private final String name;

    @Nullable
    private String description;

    public Fruit(@NonNull String name,
                 @Nullable String description) {
        this.name = name;
        this.description = description;
    }

    @NonNull
    public String getName() {
        return name;
    }

    @Nullable
    public String getDescription() {
        return description;
    }

    public void setDescription(@Nullable String description) {
        this.description = description;
    }
}

application.yml file

micronaut:
  application:
    name: demo
  security:
    intercept-url-map:
      - pattern: /microstream/**
        http-method: GET
        access:
          - isAnonymous()
netty:
  default:
    allocator:
      max-order: 3



microstream:
  storage:
    main:
      root-class: 'com.example.FruitContainer'
      storage-directory: 'build/fruit-storage'

Reference - https://guides.micronaut.io/latest/micronaut-microstream-persistence-gradle-java.html

When I am running the application, the storage directory was not created build/fruit-storage

Even with microstream ui client not able to access the microstream rest endpoint

enter image description here

micronautVersion=3.9.3

GIT- Repo - https://github.com/anandjaisy/microstream-micronaut

tim_yates
  • 167,322
  • 27
  • 342
  • 338
San Jaisy
  • 15,327
  • 34
  • 171
  • 290

2 Answers2

2

You have the wrong Root class in your configuration.

https://github.com/anandjaisy/microstream-micronaut/blob/main/src/main/resources/application.yml#L20

You have com.example.Fruit but I believe you want to use the container class.

Sergio del Amo
  • 76,835
  • 68
  • 152
  • 179
  • Even changing to container is also not working – San Jaisy Jun 16 '23 at 13:14
  • 1
    @SanJaisy you also need to enable the rest client `microstream.rest.enabled: true`, then when you run with `./gradlew run` it will work – tim_yates Jun 16 '23 at 14:22
  • The requirement to enable it [is documented here](https://micronaut-projects.github.io/micronaut-microstream/latest/guide/#restSetup). If it's still not working, you may need to run `./gradlew clean` to remove the old storage directory from when you had the wrong object as the root object. – tim_yates Jun 16 '23 at 14:25
1

Your code that is in your GitHub Repo is not storing anything.

The MicroStream engine supports two general storing strategies: lazy and eager storing. By default, MicroStream uses the lazy storing strategy.

See: https://docs.microstream.one/manual/storage/storing-data/lazy-eager-full.html

ShingJo
  • 614
  • 1
  • 7