Skip to content

Commit

Permalink
Fix quarkiverse#257 to add quarkus-artemis-jms-ra
Browse files Browse the repository at this point in the history
  • Loading branch information
zhfeng committed Nov 28, 2023
1 parent 005e2a4 commit b0e9e9c
Show file tree
Hide file tree
Showing 24 changed files with 848 additions and 1 deletion.
26 changes: 26 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
<artifactId>quarkus-artemis-jms-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.artemis</groupId>
<artifactId>quarkus-artemis-jms-ra</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.artemis</groupId>
<artifactId>quarkus-artemis-jms-ra-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.artemis</groupId>
<artifactId>quarkus-test-artemis</artifactId>
Expand Down Expand Up @@ -92,6 +102,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jakarta-ra</artifactId>
<version>${artemis.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-server</artifactId>
Expand Down Expand Up @@ -146,6 +161,17 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-hqclient-protocol</artifactId>
<version>${artemis.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-server</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
</project>
10 changes: 10 additions & 0 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.quarkiverse.ironjacamar</groupId>
<artifactId>quarkus-ironjacamar</artifactId>
<version>${quarkus-ironjacamar.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.ironjacamar</groupId>
<artifactId>quarkus-ironjacamar-deployment</artifactId>
<version>${quarkus-ironjacamar.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/attributes.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:quarkus-version: 3.4.3
:quarkus-version: 3.6.0
:quarkus-artemis-version: 3.1.2

:quarkus-org-url: https://github.com/quarkusio
Expand Down
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<module>common-parent</module>
<module>core</module>
<module>jms</module>
<module>ra</module>
</modules>

<build>
Expand Down
55 changes: 55 additions & 0 deletions integration-tests/ra/pom.xml
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>
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;
}
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();
}
}

}
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();
}
}
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 integration-tests/ra/src/main/resources/application.properties
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
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();
}

}
Loading

0 comments on commit b0e9e9c

Please sign in to comment.