lumnik. / scenarios All scenarios · Français

Micronaut: the stores' parts read in three requests

Goal Read every spare part of a Micronaut service through its API, even while the stores work in it.

A real Micronaut 4.7 and 130 fictional parts, served as the repository's Page.

manifests/lab-docker-compose.yml
# A hand-written Micronaut 4 controller returning the repository's Page, Micronaut Data JDBC on H2.name: lumnik-micronaut-partsservices:  parts:    build: ../run/parts-app    ports: ["127.0.0.1:${PARTS_PORT:-9380}:8080"]   # this machine only
manifests/10-parts.yaml
apiVersion: connectors.lumnik.io/v1kind: Connectormetadata:  name: scenario-micronaut-a  connector_type: rest-generic  scopes: [magasin]spec:  base_url: http://host.docker.internal:9380  endpoints:    - id: parts      path: /parts      method: GET      pagination: { kind: micronaut, size: 50 }        # ?page=0&size=50, reads $.content, checks $.totalSize      target:        kind: hybrid        table: ext.scenario_micronaut_a        unique_key: $.ref        promote:          - { name: label, path: $.label, type: text }          - { name: supplier, path: $.supplier, type: text }          - { name: stock, path: $.stock, type: integer }
manifests/20-parts-watched.yaml
apiVersion: connectors.lumnik.io/v1kind: Connectormetadata:  name: scenario-micronaut-watched-a  connector_type: rest-generic  scopes: [magasin]spec:  base_url: http://host.docker.internal:9380  default_rate_limit: 1/s                              # a gentle reader: fourteen pages take fourteen seconds  endpoints:    - id: parts      path: /parts      method: GET      pagination: { kind: micronaut, size: 10 }      target:        kind: hybrid        table: ext.scenario_micronaut_watched_a        unique_key: $.ref        promote:          - { name: label, path: $.label, type: text }          - { name: supplier, path: $.supplier, type: text }          - { name: stock, path: $.stock, type: integer }

Limits

  • Micronaut serves at most 100 rows per page: a larger size is cut without a word. Declare a size of 100 or less.
  • A deleted part stays in the hub's table: a full read adds and updates, it does not erase.
  • IN counts the rows read twice; the upsert keeps one.
  • 130 fictional parts, written when the service starts.

Stores · parts

The parts live in a Micronaut service.

Every one must be read, through its API.

Micronaut 4.7, 130 parts

The problem

The API hands the list out in pages.

  • A Micronaut Data Page.
  • The stores keep working meanwhile.

What is not changed

The service stays as it is.

  • Its controller returns the Page as is.
  • No module, no setting.

The trap

Micronaut 4 sends no page count.

  • Every page carries totalSize: 130.
  • totalPages is absent.

What had to be written

pagination: { kind: micronaut, size: 50 }

One line.

  • The hub stops once it has read totalSize.
  • Three requests for 130 parts.
  • A 22-line connector.

While it is read

A part deleted: the list is read again.

  • The total moves from 130 to 129.
  • All 129 left are there.

What was fixed

Two gaps found, two fixes.

  • The total checked on every page (#1796).
  • No empty page at the end of a read (#1800).

Try it

The scenario replays locally.

Every step is published with its output.

This scenario runs on lumnik Open, free and open source.

Try lumnik Open →