forked from quarkiverse/quarkus-artemis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix quarkiverse#257 to add quarkus-artemis-jms-ra
- Loading branch information
Showing
24 changed files
with
848 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkiverse.artemis</groupId> | ||
<artifactId>quarkus-artemis-integration-tests-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>quarkus-integration-test-artemis-jms-ra</artifactId> | ||
<name>Quarkus - Artemis - Integration Tests - JMS Resource Adapter</name> | ||
<description>The Apache ActiveMQ Artemis JMS Resource Adapter integration tests</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-orm-panache</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jdbc-postgresql</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-micrometer-registry-prometheus</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-narayana-jta</artifactId> | ||
</dependency> | ||
|
||
<!-- Artemis --> | ||
<dependency> | ||
<groupId>io.quarkiverse.artemis</groupId> | ||
<artifactId>quarkus-artemis-jms-ra</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>3.24.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
11 changes: 11 additions & 0 deletions
11
integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/Gift.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.quarkus.it.artemis.ra; | ||
|
||
import jakarta.persistence.Entity; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
|
||
@Entity | ||
public class Gift extends PanacheEntity { | ||
|
||
public String name; | ||
} |
88 changes: 88 additions & 0 deletions
88
integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/JcaResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package io.quarkus.it.artemis.ra; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.jms.ConnectionFactory; | ||
import jakarta.jms.JMSContext; | ||
import jakarta.jms.JMSProducer; | ||
import jakarta.jms.Queue; | ||
import jakarta.jms.TextMessage; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.DELETE; | ||
import jakarta.ws.rs.DefaultValue; | ||
import jakarta.ws.rs.FormParam; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.QueryParam; | ||
|
||
import io.quarkus.narayana.jta.QuarkusTransaction; | ||
|
||
@Path("/jca") | ||
@ApplicationScoped | ||
public class JcaResource { | ||
// add some rest methods here | ||
|
||
@Inject | ||
ConnectionFactory factory; | ||
|
||
@GET | ||
@Transactional | ||
public String hello(@QueryParam("name") @DefaultValue("JCA") String name) { | ||
try (JMSContext context = factory.createContext()) { | ||
Queue myQueue = context.createQueue("MyQueue"); | ||
JMSProducer producer = context.createProducer(); | ||
producer.send(myQueue, "Hello " + name); | ||
Gift gift = new Gift(); | ||
gift.name = name; | ||
gift.persist(); | ||
if (name.equals("rollback")) | ||
QuarkusTransaction.setRollbackOnly(); | ||
} | ||
return "Hello " + name; | ||
} | ||
|
||
@POST | ||
@Transactional | ||
@Path("/sales") | ||
public void sendToSalesQueue(@FormParam("name") String name) throws Exception { | ||
try (JMSContext context = factory.createContext()) { | ||
JMSProducer producer = context.createProducer(); | ||
TextMessage msg = context.createTextMessage(name); | ||
msg.setJMSReplyTo(context.createQueue("inventory")); | ||
producer.send(context.createQueue("sales"), msg); | ||
} | ||
} | ||
|
||
@DELETE | ||
@Path("/gifts") | ||
@Transactional | ||
public void deleteGifts() { | ||
Gift.deleteAll(); | ||
} | ||
|
||
@GET | ||
@Path("/gifts/count") | ||
@Transactional | ||
public long countGifts() { | ||
return Gift.count(); | ||
} | ||
|
||
@GET | ||
@Path("/transacted") | ||
@Transactional | ||
public boolean isTransacted() { | ||
try (JMSContext context = factory.createContext()) { | ||
return context.getTransacted(); | ||
} | ||
} | ||
|
||
@GET | ||
@Path("/not-transacted") | ||
public boolean isNotTransacted() { | ||
try (JMSContext context = factory.createContext()) { | ||
return context.getTransacted(); | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/MyQueueMessageEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.quarkus.it.artemis.ra; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import jakarta.inject.Singleton; | ||
import jakarta.jms.Message; | ||
import jakarta.jms.MessageListener; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.PUT; | ||
import jakarta.ws.rs.Path; | ||
|
||
import io.quarkiverse.ironjacamar.ResourceEndpoint; | ||
import io.quarkus.logging.Log; | ||
import io.quarkus.narayana.jta.QuarkusTransaction; | ||
|
||
@Singleton | ||
@ResourceEndpoint(activationSpecConfigKey = "myqueue") | ||
@Path("/myqueue") | ||
public class MyQueueMessageEndpoint implements MessageListener { | ||
|
||
AtomicInteger counter = new AtomicInteger(0); | ||
|
||
@Override | ||
@Transactional | ||
public void onMessage(Message message) { | ||
try { | ||
String body = message.getBody(String.class); | ||
Log.infof("Received message: %s", body); | ||
counter.incrementAndGet(); | ||
if (body.contains("rollback")) { | ||
QuarkusTransaction.setRollbackOnly(); | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@PUT | ||
@Path("/reset") | ||
public void resetCounter() { | ||
counter.set(0); | ||
} | ||
|
||
@GET | ||
public int getCounter() { | ||
return counter.get(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
integration-tests/ra/src/main/java/io/quarkus/it/artemis/ra/SalesEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.quarkus.it.artemis.ra; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.jms.ConnectionFactory; | ||
import jakarta.jms.JMSContext; | ||
import jakarta.jms.Message; | ||
import jakarta.jms.MessageListener; | ||
import jakarta.transaction.Transactional; | ||
|
||
import io.quarkiverse.ironjacamar.ResourceEndpoint; | ||
import io.quarkus.logging.Log; | ||
import io.quarkus.narayana.jta.QuarkusTransaction; | ||
|
||
@ApplicationScoped | ||
@ResourceEndpoint(activationSpecConfigKey = "sales") | ||
public class SalesEndpoint implements MessageListener { | ||
|
||
@Inject | ||
ConnectionFactory connectionFactory; | ||
|
||
AtomicInteger count = new AtomicInteger(0); | ||
|
||
@Override | ||
@Transactional | ||
public void onMessage(Message message) { | ||
try { | ||
Log.info("####### QuarkusTransaction.isActive = " + QuarkusTransaction.isActive()); | ||
String body = message.getBody(String.class); | ||
Log.infof("######### Received message from Sales queue: %s", body); | ||
Log.info("######### Redelivered: " + message.getJMSRedelivered()); | ||
Log.infof("######### Delivered %d times", message.getIntProperty("JMSXDeliveryCount")); | ||
try (JMSContext context = connectionFactory.createContext()) { | ||
context.createProducer().send(message.getJMSReplyTo(), "Replied: " + body); | ||
} | ||
count.incrementAndGet(); | ||
QuarkusTransaction.setRollbackOnly(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public int getCount() { | ||
return count.get(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
integration-tests/ra/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
quarkus.ironjacamar.ra.kind=artemis | ||
quarkus.ironjacamar.ra.config.connection-parameters=host=localhost;port=61616;protocols=AMQP | ||
#quarkus.ironjacamar.ra.config.protocol-manager-factory=org.apache.activemq.artemis.core.protocol.hornetq.client.HornetQClientProtocolManagerFactory | ||
quarkus.ironjacamar.ra.config.user=guest | ||
quarkus.ironjacamar.ra.config.password=guest | ||
|
||
#Enable pool metrics | ||
quarkus.ironjacamar.metrics.enabled=true | ||
|
||
# Enable recovery | ||
quarkus.transaction-manager.enable-recovery=true | ||
|
||
#Activation Configs | ||
quarkus.ironjacamar.activation-spec.myqueue.config.destination-type=jakarta.jms.Queue | ||
quarkus.ironjacamar.activation-spec.myqueue.config.destination=MyQueue | ||
#quarkus.ironjacamar.activation-spec.myqueue.config.destination=jms.queue.MyQueue | ||
quarkus.ironjacamar.activation-spec.myqueue.config.max-session=2 | ||
quarkus.ironjacamar.activation-spec.myqueue.config.rebalance-connections=true | ||
|
||
quarkus.ironjacamar.activation-spec.sales.config.destination-type=jakarta.jms.Queue | ||
quarkus.ironjacamar.activation-spec.sales.config.destination=sales | ||
#quarkus.ironjacamar.activation-spec.sales.config.destination=jms.queue.sales | ||
quarkus.ironjacamar.activation-spec.sales.config.max-session=2 | ||
quarkus.ironjacamar.activation-spec.sales.config.rebalance-connections=true | ||
|
||
quarkus.log.category."org.apache.activemq.audit".level=WARN | ||
#quarkus.log.category."org.jboss.jca".level=TRACE | ||
#quarkus.log.category."org.jboss.jca".min-level=TRACE | ||
#quarkus.log.category."org.apache.activemq.artemis.ra".level=TRACE | ||
#quarkus.log.category."org.apache.activemq.artemis.ra".min-level=TRACE |
31 changes: 31 additions & 0 deletions
31
integration-tests/ra/src/test/java/io/quarkus/it/artemis/ra/InjectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.it.artemis.ra; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.jms.ConnectionFactory; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkiverse.ironjacamar.runtime.IronJacamarContainer; | ||
import io.quarkus.arc.Arc; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class InjectionTest { | ||
|
||
@Inject | ||
ConnectionFactory connectionFactory; | ||
|
||
@Test | ||
public void testProducer() { | ||
assertThat(Arc.container().listAll(IronJacamarContainer.class)).hasSize(1); | ||
} | ||
|
||
@Test | ||
public void shouldInjectConnectionFactory() { | ||
assertThat(Arc.container().listAll(ConnectionFactory.class)).hasSize(1); | ||
assertThat(connectionFactory).isNotNull(); | ||
} | ||
|
||
} |
Oops, something went wrong.