Microstream with micronaut application is not working

96 Views Asked by At

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

2

There are 2 best solutions below

3
Sergio del Amo On

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.

0
ShingJo On

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