Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFLY-18195] Added smallrye reactive messaging in-memory connector #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions boms/common-expansion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,17 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-reactive-messaging-in-memory</artifactId>
<version>${version.io.smallrye.smallrye-reactive-messaging}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.vertx</groupId>
Expand Down
12 changes: 11 additions & 1 deletion galleon-pack/galleon-shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny-reactive-streams-operators</artifactId>
Expand Down Expand Up @@ -454,6 +453,17 @@
</exclusions>
</dependency>

<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-reactive-messaging-in-memory</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2023, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<layer-spec xmlns="urn:jboss:galleon:layer-spec:1.0" name="microprofile-reactive-messaging-inmemory">
<dependencies>
<layer name="microprofile-reactive-messaging"/>
</dependencies>

<packages>
<package name="io.smallrye.reactive.messaging.connector.inmemory"/>
</packages>
</layer-spec>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" ?>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a license header like in the file above :-)

<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2023, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<module xmlns="urn:jboss:module:1.9" name="io.smallrye.reactive.messaging.connector.inmemory">

<resources>
<artifact name="${io.smallrye.reactive:smallrye-reactive-messaging-in-memory}"/>
</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="io.smallrye.reactive.mutiny.zero"/>
<module name="io.smallrye.reactive.mutiny.zero-flow-adapters"/>
<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"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<!-- Add the kafka API module and a few other central ones so that it will be added to the deployment classpath by the DUP -->
<module name="io.smallrye.reactive.messaging.connector.kafka.api" optional="true" export="true" services="export"/>
<module name="org.wildfly.reactive.messaging.kafka" optional="true" export="true" services="export"/>
<module name="io.smallrye.reactive.messaging.connector.inmemory" optional="true" export="true" services="export"/>

<module name="io.smallrye.reactive.messaging.connector.mqtt" optional="true" export="true" services="export"/>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" ?>

<package-spec xmlns="urn:jboss:galleon:package:2.0" name="io.smallrye.reactive.messaging.connector.inmemory">
</package-spec>
95 changes: 95 additions & 0 deletions microprofile/reactive-messaging-smallrye/inmemory/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2021, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-microprofile-reactive-messaging-parent</artifactId>
<!--
Maintain separation between the artifact id and the version to help prevent
merge conflicts between commits changing the GA and those changing the V.
-->
<version>29.0.0.Beta1-SNAPSHOT</version>
</parent>


<artifactId>wildfly-microprofile-reactive-messaging-inmemory</artifactId>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kuhhpid I don't think we need this module any longer?

<name>WildFly: MicroProfile Reactive Messaging In-Memory</name>


<dependencies>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-reactive-messaging-in-memory</artifactId>
<version>${version.io.smallrye.smallrye-reactive-messaging}</version>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny-zero-flow-adapters</artifactId>
<version>${version.io.smallrye.smallrye-mutiny-zero}</version>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny-zero</artifactId>
<version>${version.io.smallrye.smallrye-mutiny-zero}</version>
</dependency>

<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<!--
This is a compile-time dependency of this project, but is not needed at compile or runtime by other
projects that depend on this project.
-->
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jboss.msc</groupId>
<artifactId>jboss-msc</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-server</artifactId>
</dependency>
<dependency>
<groupId>${full.maven.groupId}</groupId>
<artifactId>wildfly-microprofile-reactive-messaging-common</artifactId>
</dependency>
<dependency>
<groupId>${full.maven.groupId}</groupId>
<artifactId>wildfly-microprofile-reactive-messaging-config</artifactId>
</dependency>
</dependencies>
</project>
8 changes: 8 additions & 0 deletions testsuite/integration/microprofile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@
<scope>test</scope>
</dependency>

<!-- MicroProfile Reactive Messaging In-Memory Connector Test Dependencies -->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this dependency. Basically, this pom is stuff that needs to be on the compile classpath. And the tests classes don't seem to contain anything from this module.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Test the InMemoryConnector is used which come from smallrye-reactive-messaging-in-memory, so it is needed. Or did I not get the point here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed that. In that case I think the test looks a bit strange, in that it is using implementation details :-)

Can you rework it so it uses @Outgoing/@incoming like the Kafka tests do? Generally we should just be using MP Reactive Messaging classes, and not SmallRye ones in user code (i.e the tests)

<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-reactive-messaging-in-memory</artifactId>
<version>${version.io.smallrye.smallrye-reactive-messaging}</version>
<scope>test</scope>
</dependency>

<!-- MicroProfile Reactive Messaging Kafka Connector Test Dependencies -->
<dependency>
<groupId>io.smallrye.reactive</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.test.integration.microprofile.reactive.messaging.inmemory;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Emitter;
import org.eclipse.microprofile.reactive.messaging.Incoming;

@ApplicationScoped
public class InMemoryBean {

private String message;

@Inject
@Channel("to-inmemory")
Emitter<String> outgoingEmitter;

@Incoming("from-inmemory")
public void incoming(String message) {
this.message = message;
}

public void outgoing(String payload) {
outgoingEmitter.send(payload);
}

public String getMessage() {
return message;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.test.integration.microprofile.reactive.messaging.inmemory;

import io.smallrye.reactive.messaging.memory.InMemoryConnector;
import jakarta.enterprise.inject.Any;
import jakarta.inject.Inject;
import org.eclipse.microprofile.reactive.messaging.Message;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.shared.CLIServerSetupTask;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.reactive.EnableReactiveExtensionsSetupTask;

import java.util.List;
import java.util.PropertyPermission;

import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;

/**
* Run with
* mvn clean install -DallTests -pl testsuite/integration/microprofile -Dtest=ReactiveMessagingInMemoryUserApiTestCase
*/
@RunWith(Arquillian.class)
@ServerSetup({EnableReactiveExtensionsSetupTask.class})
public class ReactiveMessagingInMemoryTestCase {

@Inject
InMemoryBean inMemoryBean;

@Inject
@Any
InMemoryConnector connector;

@Deployment
public static WebArchive getDeployment() {

return ShrinkWrap.create(WebArchive.class, "reactive-messaging-connector-inmemory.war")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addPackage(ReactiveMessagingInMemoryTestCase.class.getPackage())
.addClasses(EnableReactiveExtensionsSetupTask.class, CLIServerSetupTask.class)
.addAsWebInfResource(ReactiveMessagingInMemoryTestCase.class.getPackage(), "microprofile-config.properties", "classes/META-INF/microprofile-config.properties")
.addClass(TimeoutUtil.class)
.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")
), "permissions.xml");
}

@Test
public void testIncomingMessageSendFromInMemoryConnector() throws InterruptedException {
connector.source("from-inmemory").send("IncomingTestMessage");
Assert.assertEquals("IncomingTestMessage",inMemoryBean.getMessage());
}

@Test
public void testOutgoingMessageReceivedByInMemoryConnector() throws InterruptedException {
inMemoryBean.outgoing("OutgoingTestMessage");
List<? extends Message<Object>> messages = connector.sink("to-inmemory").received();
Assert.assertEquals(1,messages.size());
Assert.assertEquals("OutgoingTestMessage",messages.get(0).getPayload());
}

}
Loading