Search code examples
reactive-programmingquarkusquarkus-panache

Can a DB2/400 Panache Stream be used with a Mutiny Multi


I'm fetching all rows from a DB2/400 table and returning them in a reactive request

My service look like this

package example.y2.api.service.impl;

import java.util.stream.Stream;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import example.y2.api.entity.impl.Y2ModelListEntry;
import example.y2.api.mapper.CoreMapper;
import example.y2.api.model.impl.ObjectListEntry;

import io.smallrye.mutiny.Multi;

@ApplicationScoped
public class Y2ListServiceAsync {

    @Inject
    CoreMapper mapper;

    public Multi<ObjectListEntry> asyncAll() {
        return Multi.createFrom().items(getStream()).map(this::map);
    }

    private Stream<Y2ModelListEntry> getStream() {
        return Y2ModelListEntry.streamAll();
    }

    private ObjectListEntry map(Y2ModelListEntry y) {
        ObjectListEntry listEntry = new ObjectListEntry();
        mapper.directMap(listEntry, y);
        return listEntry;
    }
}

A Panache stream should be wrapped in a @Transactional method. I'm trying to understand if I can wrap a Panache stream when using the stream with a Multi.

This is my first attempt to write a reactive application.


Solution

  • There is no reactive JDBC driver in your app, right? Then streamAll() will block. It would work but it is kind of pointless because the blocking operation will block the worker thread this way.