0

During development redeploy time is critical, so it would be nice to eliminate as much as possible. In my Jakarta EE 10 .war project I connected 10 channels to Kafka topics via microprofile reactive streams. I bring up Kafka via Docker before and deploy the .war to Wildfly 28.0.1 which use smallrye-reactive-messaging. The channels are connected after the deployment is finished and this takes only a short amount of time.

But on undeployment the channels are closed synchronously one by one and the overall time is up to 10 seconds. I checked out if it is possible to reduce this time, by defining a shorter timeout or something else. But I did not find anything what can be configured here.

So my question would be if it is possible to add the smallrye-in-memory connector to Wildfly and use it during development? This would also reduce the dependency to a running Kafka during development.

Kuhpid
  • 606
  • 6
  • 14

2 Answers2

1

Yes, it can be done by adding the smallrye-in-memory connector as module to Wildfly. Unfortunately there are a few steps to be done:

  1. Add beans.xml to smallrye-reactive-messaging-in-memory-4.5.0.jar META-INF directory and name it smallrye-reactive-messaging-in-memory-4.5.0-beans.jar (the name is not important). This step is needed so that the io.smallrye.reactive.messaging.memory.InMemoryConnector can be injected via CDI to the io.smallrye.reactive.messaging.providers.impl.ConnectorFactories.

  2. Add modules mutiny and zero-flow-adapters to Wildfly via jboss-cli.sh:

    module add --name=io.smallrye.reactive.mutiny.zero-flow-adapters --resources=mutiny-zero-flow-adapters-1.0.0.jar --dependencies=org.reactivestreams

    module add --name=io.smallrye.reactive.mutiny.zero --resources=mutiny-zero-1.0.0.jar

  3. Copy smallrye-reactive-messaging-in-memory-4.5.0-beans.jar to ${WILDFLY_HOME}/modules/io/smallrye/reactive/messaging/connector/inmemory/main and create module.xml. Maybe this could be done via jboss-cli.sh but unfortunately I did not find how to specify optional and services attributes. This was the closet answer.

<module xmlns="urn:jboss:module:1.1" name="io.smallrye.reactive.messaging.connector.inmemory">

    <resources>
        <resource-root path="smallrye-reactive-messaging-in-memory-4.5.0-beans.jar"/>
    </resources>

    <dependencies>
        <module name="io.smallrye.config" services="import"/>
        <module name="io.smallrye.common.annotation"/>
        <module name="io.smallrye.reactive.converters.api"/>
        <module name="io.smallrye.reactive.messaging"/>
        <module name="io.smallrye.reactive.mutiny"/>
        <module name="io.smallrye.reactive.mutiny.reactive-streams-operators"/>
        <module name="javax.annotation.api"/>
        <module name="javax.enterprise.api"/>
        <module name="org.eclipse.microprofile.reactive-messaging.api"/>
        <module name="org.eclipse.microprofile.reactive-streams-operators.api"/>
        <module name="org.eclipse.microprofile.reactive-streams-operators.core" services="import"/>
        <module name="org.eclipse.microprofile.config.api"/>
        <module name="org.jboss.logging"/>
        <module name="org.jboss.weld.api"/>
        <module name="org.jboss.weld.core"/>
        <module name="org.jboss.weld.spi"/>
        <module name="org.reactivestreams"/>
        <module name="org.wildfly.reactive.messaging.config" optional="true" export="true" services="export"/>
        <module name="org.slf4j"/>
        <module name="io.smallrye.reactive.mutiny.zero"/>
        <module name="io.smallrye.reactive.mutiny.zero-flow-adapters"/>
    </dependencies>
</module>
  1. Add io.smallrye.reactive.messaging.connector.inmemory as dependency in ${WILDFLY_HOME}/modules/system/layers/base/io/smallrye/reactive/messaging/connector/main/module.xml:
<module name="io.smallrye.reactive.messaging.connector" xmlns="urn:jboss:module:1.9">
    ...

    <dependencies>
        ...
        <module name="io.smallrye.reactive.messaging.connector.inmemory" optional="false" export="true" services="export"/>
    </dependencies>
</module>

You should now see the debug output with the found im-memory connector:

DEBUG [io.smallrye.reactive.messaging.provider] (MSC service thread 1-2) SRMSG00226: Found incoming connectors: [smallrye-in-memory, smallrye-kafka]
DEBUG [io.smallrye.reactive.messaging.provider] (MSC service thread 1-2) SRMSG00227: Found outgoing connectors: [smallrye-in-memory, smallrye-kafka]

Now you can use it in your config e.g. microprofile-config.properties:

mp.messaging.incoming.<channel>.connector=smallrye-in-memory

mp.messaging.outgoing.<channel>.connector=smallrye-in-memory

Kuhpid
  • 606
  • 6
  • 14
  • Maybe the in-memory connector will get integrated in the future: https://issues.redhat.com/browse/WFLY-18195 I started to implement it, but its not ready for a pull request. If you are interested in the code you can find it here: https://github.com/kuhhpid/wildfly-smallrye-in-memory – Kuhpid Jul 12 '23 at 10:37
1

Kafka connector waits some grace period while closing channels to ensure that ongoing message processing and messages pending for sending are terminated.

These can be adjusted using configuration options: graceful-shutdown (true by default) for incoming channels and close-timeout (10s by default) for outgoing channels.

Hope this helps.

  • Ah great, I missed that configuration options :-/ Here an example to set it in microprofile-config.properties: mp.messaging.incoming..graceful-shutdown=false and here the link to that config option: https://smallrye.io/smallrye-reactive-messaging/4.7.0/kafka/receiving-kafka-records/#configuration-reference – Kuhpid Jul 12 '23 at 10:31