You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2024/01/10 23:01:45 UTC

(tomee) branch tomee-9.x updated (5e5ab5f54b -> 6ceaf06881)

This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a change to branch tomee-9.x
in repository https://gitbox.apache.org/repos/asf/tomee.git


    from 5e5ab5f54b TOMEE-4294 exclude CDI 4 as a transitive dependency from SmallRye Fault Tolerance
     new 856ec24335 TOMEE-3902: Allow properties to be injected into any activation properties
     new 6ceaf06881 TOMEE-3902 missed on last commit

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/openejb/core/mdb/MdbContainer.java  |  45 ++++--
 .../openejb/core/mdb/ActivationConfigTest.java     | 131 +++++++++++++++++
 .../mdb/MdbContainerClientIdActivationTest.java    | 159 +++++++++++++++++++++
 itests/{jaxrs => ejb}/pom.xml                      |  20 ++-
 .../apache/tomee/itests/ejb/MessageCounter.java    |  24 ++--
 .../apache/tomee/itests/ejb/MessageReceiver.java   |  19 +--
 .../apache/tomee/itests/ejb/MessageResource.java   |  42 +++---
 .../apache/tomee/itests/ejb}/MessageSender.java    |  34 ++---
 .../itests/ejb/MultiTomEETopicSubscriberTest.java  | 115 +++++++++++++++
 itests/itest-common/pom.xml                        |   1 -
 itests/pom.xml                                     |   1 +
 11 files changed, 513 insertions(+), 78 deletions(-)
 create mode 100644 container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ActivationConfigTest.java
 create mode 100644 container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerClientIdActivationTest.java
 copy itests/{jaxrs => ejb}/pom.xml (83%)
 copy examples/async-servlet/src/main/java/org/superbiz/asyncservlet/CalcBean.java => itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageCounter.java (74%)
 copy arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSReceiverBean.java => itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageReceiver.java (79%)
 copy utils/openejb-mockito/src/test/java/org/apache/openejb/mockito/Facade.java => itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageResource.java (62%)
 copy {examples/websocket-jms/src/main/java/org/superbiz/websockets => itests/ejb/src/test/java/org/apache/tomee/itests/ejb}/MessageSender.java (63%)
 create mode 100644 itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MultiTomEETopicSubscriberTest.java


(tomee) 02/02: TOMEE-3902 missed on last commit

Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch tomee-9.x
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 6ceaf06881655893672acef73cc2f1f7e878b8e7
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Wed Jan 10 23:01:18 2024 +0000

    TOMEE-3902 missed on last commit
---
 itests/ejb/pom.xml | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/itests/ejb/pom.xml b/itests/ejb/pom.xml
new file mode 100644
index 0000000000..cd7602c2f9
--- /dev/null
+++ b/itests/ejb/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<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/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>itests</artifactId>
+    <groupId>org.apache.tomee</groupId>
+    <version>9.1.3-SNAPSHOT</version>
+  </parent>
+
+  <groupId>org.apache.tomee.itests</groupId>
+  <artifactId>ejb</artifactId>
+  <packaging>jar</packaging>
+  <name>TomEE :: iTests :: EJB</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <systemPropertyVariables>
+            <version>${project.version}</version>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.tomee</groupId>
+      <artifactId>tomee-server-composer</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomee</groupId>
+      <artifactId>apache-tomee</artifactId>
+      <version>${project.version}</version>
+      <type>tar.gz</type>
+      <classifier>microprofile</classifier>
+      <exclusions>
+        <exclusion>
+          <groupId>*</groupId>
+          <artifactId>*</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomee.bom</groupId>
+      <artifactId>tomee-webprofile-api</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomee</groupId>
+      <artifactId>openejb-client</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-broker</artifactId>
+      <version>${version.activemq}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+  </dependencies>
+</project>


(tomee) 01/02: TOMEE-3902: Allow properties to be injected into any activation properties

Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch tomee-9.x
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 856ec24335d6e974e4f4870559107fa33370a931
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Wed Apr 13 11:37:11 2022 +0100

    TOMEE-3902: Allow properties to be injected into any activation properties
---
 .../org/apache/openejb/core/mdb/MdbContainer.java  |  45 ++++--
 .../openejb/core/mdb/ActivationConfigTest.java     | 131 +++++++++++++++++
 .../mdb/MdbContainerClientIdActivationTest.java    | 159 +++++++++++++++++++++
 .../apache/tomee/itests/ejb/MessageCounter.java    |  37 +++++
 .../apache/tomee/itests/ejb/MessageReceiver.java   |  38 +++++
 .../apache/tomee/itests/ejb/MessageResource.java   |  53 +++++++
 .../org/apache/tomee/itests/ejb/MessageSender.java |  54 +++++++
 .../itests/ejb/MultiTomEETopicSubscriberTest.java  | 115 +++++++++++++++
 itests/itest-common/pom.xml                        |   1 -
 itests/pom.xml                                     |   1 +
 10 files changed, 624 insertions(+), 10 deletions(-)

diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
index 898e7858d0..bda66db61d 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java
@@ -38,6 +38,7 @@ import org.apache.openejb.resource.XAResourceWrapper;
 import org.apache.openejb.spi.SecurityService;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.StringTemplate;
 import org.apache.xbean.recipe.ObjectRecipe;
 import org.apache.xbean.recipe.Option;
 
@@ -67,12 +68,9 @@ import jakarta.validation.ConstraintViolationException;
 import jakarta.validation.Validator;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.TreeSet;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -274,17 +272,46 @@ public class MdbContainer implements RpcContainer, BaseMdbContainer {
         }
     }
 
-    private ActivationSpec createActivationSpec(final BeanContext beanContext) throws OpenEJBException {
+    // visibility to allow unit testing
+    public ActivationSpec createActivationSpec(final BeanContext beanContext) throws OpenEJBException {
         try {
             // initialize the object recipe
             final ObjectRecipe objectRecipe = new ObjectRecipe(activationSpecClass);
             objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
             objectRecipe.disallow(Option.FIELD_INJECTION);
 
-
             final Map<String, String> activationProperties = beanContext.getActivationProperties();
+
+            final Map<String, String> context = new HashMap<>();
+            context.put("ejbJarId", beanContext.getModuleContext().getId());
+            context.put("ejbName", beanContext.getEjbName());
+            context.put("appId", beanContext.getModuleContext().getAppContext().getId());
+
+            String hostname;
+            try {
+                hostname = InetAddress.getLocalHost().getHostName();
+            } catch (UnknownHostException e) {
+                hostname = "hostname-unknown";
+            }
+
+            context.put("hostName", hostname);
+
+            String uniqueId = Long.toString(System.currentTimeMillis());
+            try {
+                Class idGen = Class.forName("org.apache.activemq.util.IdGenerator");
+                final Object generator = idGen.getConstructor().newInstance();
+                final Method generateId = idGen.getDeclaredMethod("generateId");
+                final Object ID = generateId.invoke(generator);
+
+                uniqueId = ID.toString();
+            } catch (Exception e) {
+                // ignore and use the timestamp
+            }
+
+            context.put("uniqueId", uniqueId);
+
             for (final Map.Entry<String, String> entry : activationProperties.entrySet()) {
-                objectRecipe.setMethodProperty(entry.getKey(), entry.getValue());
+                objectRecipe.setMethodProperty(entry.getKey(), new StringTemplate(entry.getValue()).apply(context));
             }
             objectRecipe.setMethodProperty("beanClass", beanContext.getBeanClass());
 
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ActivationConfigTest.java b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ActivationConfigTest.java
new file mode 100644
index 0000000000..519912b93d
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ActivationConfigTest.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.core.mdb;
+
+import org.apache.activemq.ra.ActiveMQActivationSpec;
+import org.apache.activemq.ra.ActiveMQResourceAdapter;
+import org.apache.openejb.AppContext;
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.ModuleContext;
+import org.apache.openejb.core.ivm.naming.IvmContext;
+import org.apache.openejb.loader.SystemInstance;
+import org.junit.Assert;
+import org.junit.Test;
+
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
+import jakarta.resource.spi.ActivationSpec;
+import jakarta.resource.spi.ResourceAdapter;
+import jakarta.validation.ConstraintViolation;
+import jakarta.validation.Validator;
+import jakarta.validation.executable.ExecutableValidator;
+import jakarta.validation.metadata.BeanDescriptor;
+import java.net.InetAddress;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+public class ActivationConfigTest {
+
+    @Test
+    public void testShouldResolvePlaceHolder() throws Exception {
+        final ResourceAdapter ra = new ActiveMQResourceAdapter();
+        final MdbContainer container = new MdbContainer("TestMdbContainer", null, ra, MessageListener.class, ActiveMQActivationSpec.class, 10, false);
+
+
+        final Map<String, String> properties = new HashMap<>();
+        properties.put("clientId", "{appId}#{ejbJarId}#{ejbName}#{hostName}#{uniqueId}");
+        properties.put("subscriptionName", "subscription-{appId}#{ejbJarId}#{ejbName}#{hostName}#{uniqueId}");
+        properties.put("destination", "MyTopic");
+        properties.put("destinationType", "jakarta.jms.Topic");
+
+        final BeanContext beanContext = getMockBeanContext(properties);
+
+        final ActivationSpec activationSpec = container.createActivationSpec(beanContext);
+        Assert.assertTrue(activationSpec instanceof ActiveMQActivationSpec);
+
+        ActiveMQActivationSpec spec = (ActiveMQActivationSpec) activationSpec;
+
+        final String clientId = spec.getClientId();
+        final String[] parts = clientId.split("#");
+
+        final String hostname = (InetAddress.getLocalHost()).getHostName();
+
+        Assert.assertEquals("appId", parts[0]);
+        Assert.assertEquals("moduleId", parts[1]);
+        Assert.assertEquals("MyEjb", parts[2]);
+        Assert.assertEquals(hostname, parts[3]);
+
+        final Pattern pattern = Pattern.compile("ID:.*?-\\d+-\\d+-\\d+:\\d");
+        Assert.assertTrue(pattern.matcher(parts[4]).matches());
+    }
+
+    private BeanContext getMockBeanContext(final Map<String, String> properties) throws Exception {
+        final IvmContext context = new IvmContext();
+        context.bind("comp/Validator", new NoOpValidator());
+
+        final AppContext mockAppContext = new AppContext("appId", SystemInstance.get(),  this.getClass().getClassLoader(), context, context, false);
+        final ModuleContext mockModuleContext =  new ModuleContext("moduleId", new URI(""), "uniqueId", mockAppContext, context, this.getClass().getClassLoader());
+        final BeanContext mockBeanContext = new BeanContext("test", context, mockModuleContext, MyListener.class, MessageListener.class, properties);
+        mockBeanContext.setEjbName("MyEjb");
+
+        return mockBeanContext;
+    }
+
+    public static class MyListener implements MessageListener {
+
+        @Override
+        public void onMessage(Message message) {
+
+        }
+    }
+
+    public static class NoOpValidator implements Validator {
+        @Override
+        public <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups) {
+            return Collections.emptySet();
+        }
+
+        @Override
+        public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups) {
+            return Collections.emptySet();
+        }
+
+        @Override
+        public <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups) {
+            return Collections.emptySet();
+        }
+
+        @Override
+        public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
+            return null;
+        }
+
+        @Override
+        public <T> T unwrap(Class<T> type) {
+            return null;
+        }
+
+        @Override
+        public ExecutableValidator forExecutables() {
+            return null;
+        }
+    }
+}
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerClientIdActivationTest.java b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerClientIdActivationTest.java
new file mode 100644
index 0000000000..19f12acb75
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerClientIdActivationTest.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.core.mdb;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.TransportConnector;
+import org.apache.activemq.broker.region.Destination;
+import org.apache.activemq.broker.region.Subscription;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.openejb.jee.MessageDrivenBean;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Configuration;
+import org.apache.openejb.testing.Module;
+import org.apache.openejb.testng.PropertiesBuilder;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import jakarta.annotation.Resource;
+import jakarta.ejb.ActivationConfigProperty;
+import jakarta.ejb.MessageDriven;
+import jakarta.jms.*;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.regex.Pattern;
+
+@RunWith(ApplicationComposer.class)
+public class MdbContainerClientIdActivationTest {
+
+    private static BrokerService broker;
+
+    @Resource(name = "target")
+    private Topic destination;
+
+    @Resource(name = "cf")
+    private ConnectionFactory cf;
+
+    @Configuration
+    public Properties config() throws Exception{
+        final TransportConnector tc = broker.getTransportConnectors().iterator().next();
+        final int port = tc.getConnectUri().getPort();
+
+        return new PropertiesBuilder()
+
+                .p("amq", "new://Resource?type=ActiveMQResourceAdapter")
+
+                .p("amq.DataSource", "")
+                .p("amq.BrokerXmlConfig", "") //connect to an external broker
+                .p("amq.ServerUrl", "tcp://localhost:" + port)
+
+                .p("target", "new://Resource?type=Topic")
+
+                .p("mdbs", "new://Container?type=MESSAGE")
+                .p("mdbs.ResourceAdapter", "amq")
+                .p("mdbs.pool", "false")
+                .p("cf", "new://Resource?type=" + ConnectionFactory.class.getName())
+                .p("cf.ResourceAdapter", "amq")
+
+                .p("mdb.activation.clientId", "{ejbName}-{uniqueId}")
+
+                .build();
+    }
+
+    @Module
+    public MessageDrivenBean jar() {
+        return new MessageDrivenBean(Listener.class);
+    }
+
+    @BeforeClass
+    public static void beforeClass() throws Exception {
+        broker = new BrokerService();
+        broker.setPersistent(false);
+        broker.setUseJmx(true);
+        broker.addConnector("tcp://localhost:0"); // pick a random available port
+
+        broker.start();
+    }
+
+    @AfterClass
+    public static void afterClass() throws Exception {
+        broker.stop();
+    }
+
+    @Test
+    public void shouldHaveAUniqueClientID() throws Exception {
+        final Connection connection = cf.createConnection();
+        connection.start();
+
+        final Session session = connection.createSession();
+        final MessageProducer producer = session.createProducer(this.destination);
+        final TextMessage msg = session.createTextMessage("Hello");
+        producer.send(msg);
+        producer.close();
+        session.close();
+        connection.close();
+
+        Listener.latch.await();
+
+
+        final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
+        final Set<ObjectName> objectNames = platformMBeanServer.queryNames(new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Topic,destinationName=target,endpoint=Consumer,*"), null);
+
+        ObjectName match = null;
+
+        for (final ObjectName objectName : objectNames) {
+            if (objectName.getKeyProperty("clientId").startsWith("testMDB")) {
+                match = objectName;
+                break;
+            }
+        }
+
+        Assert.assertNotNull(match);
+
+        final String clientId = match.getKeyProperty("clientId");
+        final String uniquePart = clientId.substring(8);
+
+        Assert.assertNotNull(clientId);
+        Assert.assertNotNull(uniquePart);
+
+        final Pattern pattern = Pattern.compile("ID_.*?-\\d+-\\d+-\\d+_\\d");
+        Assert.assertTrue(pattern.matcher(uniquePart).matches());
+    }
+
+    @MessageDriven(name="testMDB", activationConfig = {
+            @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"),
+            @ActivationConfigProperty(propertyName = "destination", propertyValue = "target")
+    })
+    public static class Listener implements MessageListener {
+        public static CountDownLatch latch = new CountDownLatch(1);
+
+        @Override
+        public void onMessage(final Message message) {
+            latch.countDown();
+        }
+
+
+    }
+
+}
\ No newline at end of file
diff --git a/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageCounter.java b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageCounter.java
new file mode 100644
index 0000000000..2a2ff2589b
--- /dev/null
+++ b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageCounter.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.itests.ejb;
+
+import jakarta.ejb.Lock;
+import jakarta.ejb.LockType;
+import jakarta.ejb.Singleton;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@Singleton
+@Lock(LockType.READ)
+public class MessageCounter {
+
+    private static final AtomicInteger COUNTER = new AtomicInteger();
+
+    public void increment() {
+        COUNTER.incrementAndGet();
+    }
+
+    public int getCount() {
+        return COUNTER.get();
+    }
+}
diff --git a/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageReceiver.java b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageReceiver.java
new file mode 100644
index 0000000000..284272bef8
--- /dev/null
+++ b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageReceiver.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.itests.ejb;
+
+import jakarta.ejb.ActivationConfigProperty;
+import jakarta.ejb.EJB;
+import jakarta.ejb.MessageDriven;
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
+
+@MessageDriven(name="Receiver", activationConfig = {
+        @ActivationConfigProperty(propertyName = "destination", propertyValue = "target"),
+        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic")
+})
+public class MessageReceiver implements MessageListener {
+
+    @EJB
+    private MessageCounter counter;
+
+    @Override
+    public void onMessage(Message message) {
+        counter.increment();
+    }
+}
diff --git a/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageResource.java b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageResource.java
new file mode 100644
index 0000000000..ffe3d60701
--- /dev/null
+++ b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageResource.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.itests.ejb;
+
+import jakarta.ejb.EJB;
+import jakarta.ejb.Lock;
+import jakarta.ejb.LockType;
+import jakarta.ejb.Singleton;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
+@Singleton
+@Lock(LockType.READ)
+@Path("api/messages")
+public class MessageResource {
+
+    @EJB
+    private MessageCounter counter;
+
+    @EJB
+    private MessageSender sender;
+
+    @GET
+    @Path("count")
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response count() {
+        return Response.ok(counter.getCount()).build();
+    }
+
+    @GET
+    @Path("test")
+    public void sendTestMessages() {
+        sender.sendMessage();
+    }
+
+}
diff --git a/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageSender.java b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageSender.java
new file mode 100644
index 0000000000..bc699b2d8c
--- /dev/null
+++ b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MessageSender.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.itests.ejb;
+
+import jakarta.annotation.Resource;
+import jakarta.ejb.Lock;
+import jakarta.ejb.LockType;
+import jakarta.ejb.Singleton;
+import jakarta.inject.Inject;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.JMSContext;
+import jakarta.jms.Topic;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@Singleton
+@Lock(LockType.READ)
+public class MessageSender {
+
+    @Resource
+    private ConnectionFactory cf;
+
+    @Inject
+    private JMSContext jmsContext;
+
+    @Resource(name = "target")
+    private Topic eventTopic;
+
+
+    public void sendMessage() {
+        final String message = "hello world";
+        for (int i = 0; i < 1000; i++) {
+            sendMessage(eventTopic, message);
+        }
+    }
+
+    private void sendMessage(final Topic topic, final String message) {
+        jmsContext.createProducer().send(topic, jmsContext.createTextMessage(message));
+    }
+
+}
diff --git a/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MultiTomEETopicSubscriberTest.java b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MultiTomEETopicSubscriberTest.java
new file mode 100644
index 0000000000..bb9520e04a
--- /dev/null
+++ b/itests/ejb/src/test/java/org/apache/tomee/itests/ejb/MultiTomEETopicSubscriberTest.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.itests.ejb;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.TransportConnector;
+import org.apache.tomee.server.composer.Archive;
+import org.apache.tomee.server.composer.TomEE;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.tomitribe.util.Files;
+import org.tomitribe.util.IO;
+
+import jakarta.jms.ConnectionFactory;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+public class MultiTomEETopicSubscriberTest {
+
+    private BrokerService broker;
+
+    @Before
+    public void setUp() throws Exception {
+        // start an ActiveMQ broker
+        broker = new BrokerService();
+        broker.setPersistent(false);
+        broker.setUseJmx(true);
+        broker.addConnector("tcp://localhost:0"); // pick a random available port
+
+        broker.start();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        broker.stop();
+    }
+
+    @Test
+    public void test() throws Exception {
+        // get the ActiveMQ OpenWire port
+        final TransportConnector tc = broker.getTransportConnectors().iterator().next();
+        final int port = tc.getConnectUri().getPort();
+
+        // start 2 TomEE servers
+        final TomEE tomee1 = buildTomEE(port);
+        final TomEE tomee2 = buildTomEE(port);
+
+        // the key thing here is that both of these servers should be able to subscribe to the topic
+        // from their respective MDBs without exceptions.
+
+        // lets send some test messages from 1 of the servers
+        IO.slurp(new URL("http://localhost:" + tomee1.getPort() + "/test/api/messages/test"));
+        Thread.sleep(5000);
+
+        // and check that all the messages were received on both servers
+        final String result1 = IO.slurp(new URL("http://localhost:" + tomee1.getPort() + "/test/api/messages/count"));
+        final String result2 = IO.slurp(new URL("http://localhost:" + tomee2.getPort() + "/test/api/messages/count"));
+
+        Assert.assertEquals(1000, Integer.parseInt(result1));
+        Assert.assertEquals(1000, Integer.parseInt(result2));
+    }
+
+    private TomEE buildTomEE(final int activemqPort) throws Exception {
+        return TomEE.plus()
+                .add("webapps/test/WEB-INF/lib/app.jar", Archive.archive()
+                        .add(MessageCounter.class)
+                        .add(MessageReceiver.class)
+                        .add(MessageResource.class)
+                        .add(MessageSender.class)
+                        .asJar())
+                .home(h -> updateSystemProperties(h, activemqPort))
+                .build();
+    }
+
+    private void updateSystemProperties(final File home, final int activemqPort) {
+        try {
+            final File systemProps = Files.file(home, "conf", "system.properties");
+            String props = IO.slurp(systemProps);
+
+            props = props + "\namq=new://Resource?type=ActiveMQResourceAdapter" +
+                    "\namq.DataSource=" +
+                    "\namq.BrokerXmlConfig=" +
+                    "\namq.ServerUrl=tcp://localhost:" + activemqPort +
+                    "\ntarget=new://Resource?type=Topic" +
+                    "\nmdbs=new://Container?type=MESSAGE" +
+                    "\nmdbs.ResourceAdapter=amq" +
+                    "\nmdbs.pool=false" +
+                    "\ncf=new://Resource?type=" + ConnectionFactory.class.getName() +
+                    "\ncf.ResourceAdapter=amq" +
+                    "\nmdb.activation.clientId={ejbName}-{uniqueId}";
+
+            IO.copy(IO.read(props), systemProps);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/itests/itest-common/pom.xml b/itests/itest-common/pom.xml
index 8b899bb817..94b5912939 100644
--- a/itests/itest-common/pom.xml
+++ b/itests/itest-common/pom.xml
@@ -62,4 +62,3 @@
     </dependency>
   </dependencies>
 </project>
-
diff --git a/itests/pom.xml b/itests/pom.xml
index 0fe6e99f8a..1259a04e74 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -47,6 +47,7 @@
     <module>openejb-itests-servlets</module>
     <module>openejb-itests-web</module>
     <module>jaxrs</module>
+    <module>ejb</module>
     <module>itest-common</module>
     <module>itest-util</module>
     <module>tomee-security-itests</module>