diff --git a/build-parent/pom.xml b/build-parent/pom.xml index 050d22fe..3ce5aa26 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 io.quarkiverse.artemis @@ -28,6 +29,13 @@ pom import + + io.quarkus.platform + quarkus-camel-bom + ${camel-quarkus.platform.version} + pom + import + diff --git a/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/ArtemisCoreProcessor.java b/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/ArtemisCoreProcessor.java index 952ea68e..d360f0e3 100644 --- a/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/ArtemisCoreProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/artemis/core/deployment/ArtemisCoreProcessor.java @@ -108,6 +108,7 @@ ArtemisCoreConfiguredBuildItem configure( return null; } + boolean isSoleServerLocator = bootstrap.getConfigurationNames().size() == 1; for (String name : bootstrap.getConfigurationNames()) { if (!shadowRunTimeConfigs.getNames().contains(name) && buildTimeConfigs.getAllConfigs().getOrDefault(name, new ArtemisBuildTimeConfig()).isEmpty()) { @@ -117,7 +118,7 @@ ArtemisCoreConfiguredBuildItem configure( name, runtimeConfigs, buildTimeConfigs); - SyntheticBeanBuildItem serverLocator = toSyntheticBeanBuildItem(name, supplier); + SyntheticBeanBuildItem serverLocator = toSyntheticBeanBuildItem(supplier, name, isSoleServerLocator); syntheticBeanProducer.produce(serverLocator); } return new ArtemisCoreConfiguredBuildItem(); @@ -141,21 +142,23 @@ private static void addBuiltinReflectiveBuildItems( } private SyntheticBeanBuildItem toSyntheticBeanBuildItem( + Supplier supplier, String name, - Supplier supplier) { + boolean isSoleServerLocator) { SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem .configure(ServerLocator.class) .supplier(supplier) .scope(ApplicationScoped.class); - return addQualifiers(configurator, name) + return addQualifiers(name, isSoleServerLocator, configurator) .setRuntimeInit() .done(); } public static SyntheticBeanBuildItem.ExtendedBeanConfigurator addQualifiers( - SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator, - String name) { - if (ArtemisUtil.isDefault(name)) { + String name, + boolean isSoleArtemisBean, + SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator) { + if (ArtemisUtil.isDefault(name) || isSoleArtemisBean) { configurator .unremovable() .addQualifier().annotation(Default.class).done(); diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index 1167cd41..05e2ab15 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -105,7 +105,7 @@ public class MyClass { } ---- -It is also registered with `@Identifier("")`, so we can inject it with +It is also registered with link:https://github.com/smallrye/smallrye-common/blob/main/annotation/src/main/java/io/smallrye/common/annotation/Identifier.java[`@Identifier("")`], so we can inject it with .Injection of default `ServerLocator` by its explicit name when using `quarkus-artemis-core` [source,java,subs=attributes+] @@ -201,8 +201,11 @@ public class MyClass { IMPORTANT: We strongly recommend the usage of link:https://javadoc.io/doc/io.smallrye.common/smallrye-common-annotation/latest/io/smallrye/common/annotation/Identifier.html[`@Identifier` annotation] instead of the link:https://www.javadoc.io/doc/javax/javaee-api/latest/javax/inject/Named.html[`@Named` annotation]. Some other feature rely on the usage of `@Identifier`. Please see section <> for details. +== `@Default` Bean [[default-bean]] +When an unnamed configuration is provided, this configuration will be registered as link:https://jakarta.ee/specifications/cdi/2.0/apidocs/javax/enterprise/inject/default[`@Default`] bean. Otherwise, if only a single configuration is provided, this configuration will be registered as `@Default` bean. This mechanism allows us to inject this bean without any qualifier. + == Setting properties at runtime results in a warning -When we override the properties `url`, `username` or `password` of a configuration at runtime - either through the implicit environment variable (`QUARKUS_ARTEMIS_URL`, `QUARKUS_ARTEMIS\__CONNECTION_NAME__URL`), a custom environment variable (`quarkus.artemis.url=${ARTEMIS_URL:tcp://dummy:12345}`) or a runtime-provided `.properties` files, we will see a warning at startup similar to this one: +When we override the properties `url`, `username` or `password` of a configuration at runtime - either through the implicit environment variable (`QUARKUS_ARTEMIS_URL`, `QUARKUS_ARTEMIS\__CONNECTION_NAME__URL`), a custom environment variable (`quarkus.artemis.url=${ARTEMIS_URL:tcp://dummy:12345}`) or a runtime-provided `.properties`-/`.yaml` files, we will see a warning at startup similar to this one: .Warning at startup [source,subs=attributes+] @@ -211,15 +214,56 @@ When we override the properties `url`, `username` or `password` of a configurati - quarkus.artemis.url is set to 'tcp://localhost:61616' but it is build time fixed to 'tcp://dummy:12345'. Did you change the property quarkus.artemis.url after building the application? ---- -This is expected. We bind some properties twice: once as build-time property, once as run time property. We do so to analyze the (run time-)configuration at build time to get a list of named connections. The overwritten configuration will take effect. The correct behaviour enforced by https://github.com/quarkiverse/quarkus-artemis/tree/main/integration-tests/core/with-default-change-url[two] different https://github.com/quarkiverse/quarkus-artemis/tree/main/integration-tests/jms/with-default-change-url[tests]. The above example is taken from the logs of our tests. +This is expected. We bind some properties twice: once as build-time property, once as run time property. We do so to analyze the (run time-)configuration at build time to get a list of named connections. The overwritten configuration will take effect. The correct behaviour is enforced by https://github.com/quarkiverse/quarkus-artemis/tree/main/integration-tests/core/with-default-change-url[two] different https://github.com/quarkiverse/quarkus-artemis/tree/main/integration-tests/jms/with-default-change-url[tests]. The above example is taken from the logs of those tests. == Configuration detection at build-time -We took special care so the configurations behave "as intuitively as possible". This means that if no connection-related configuration (`enabled`, `url`, `username`, `password`, `devservices...`, `health-exclude`, `xa-enabled`) is present at build-time, it is assumed that the configuration is not used and disabled. Therefore, if we want to use any configuration, but not configure it, we should set `quarkus.artemis.enabled` / `quarkus.artemis."named-configuration".enabled` to *true* to explicitly enable the configuration. +We took special care so the configurations behave "as intuitively as possible". This means that if no connection-related configuration (`enabled`, `url`, `username`, `password`, `devservices...`, `health-exclude`, `xa-enabled`) is present at build-time, it is assumed that the configuration is not used and disabled. Therefore, if we want to use any configuration, but not configure it, we should set `quarkus.artemis.enabled` / `quarkus.artemis."named-configuration".enabled` to *true* to explicitly enable the configuration. Due to the fact how the configuration system works in quarkus, we are only able to analyze properties defined in the default profile, i.e. properties without a prefix (`%dev`, `%text`, ...). If in doubt, we recommend setting `quarkus.artemis.enabled`/`quarkus.artemis."named-configuration".enabled` to **true**. + +NOTE: This is also the case if we bind properties in the default profile to environment variables, without a default value. For example, `quarkus.artemis.url=$\{ARTEMIS_URL}` has no value at build-time, thus this property is "invisible" at build time. -NOTE: binding a property to an environment variable, like `quarkus.artemis.url=$\{ARTEMIS_URL}` is sufficient, so the extension can pick up the configuration at build-time. +NOTE: Binding a property to an environment variable, like `quarkus.artemis.url=$\{ARTEMIS_URL}` is sufficient, so the extension can pick up the configuration at build-time. TIP: If we want to configure a connection solely through the implicit environment variables `QUARKUS_ARTEMIS_...`, we should enable the configuration by setting `quarkus.artemis.enabled` / `quarkus.artemis."named-configuration".enabled` to *true*. For example, if we want to configure connection `quarkus.artemis."named-1"` through the implicit environment variables, we would set `quarkus.artemis."named-1".enabled=true` and then configure the connection through environment variables `QUARKUS_ARTEMIS\__NAMED_1__...`. +Table <> gives an overview when a property is visible at build time, and when it is not. + +.Visibility of configuration values +[[table-visibility]] +[cols=3*,options=header] +|=== +| Description +| Example +| Visible? +a| +configuration property belonging to a specific profile +a| +* `%dev.quarkus.artemis.url=tcp://localhost:61616` +* `%test.quarkus.artemis.password=${ARTEMIS_PASSWORD:artemis}` +a| +❌ +a| +configuration property bound to constant value +a| +* `quarkus.artemis.url=tcp://localhost:61616` +* `quarkus.artemis.username=artems` +a| +✔️ +a| +configuration property bound to environment variable +a| +* `quarkus.artemis."named".url=${ARTEMIS_NAMED_URL}` +* `quarkus.artemis.password=${ARTEMIS_PASSWORD}` +a| +❌ +a| +configuration property bound to environment variable with default value +a| +* `quarkus.artemis."named".url=${ARTEMIS_NAMED_URL:tcp://localhost:61616}` +* `quarkus.artemis.password=${ARTEMIS_PASSWORD:artemis}` +a| +✔️ +|=== + Please do not try to configure a configuration purely through environment variables, without having any indication of its present in the application's configuration file. We specifically rely on the present of some configuration fragment at build-time to detect configurations. == XA Transactions @@ -228,7 +272,7 @@ XA Transactions must be activated on a per-configuration basis, they are not en To activate XA transactions, we can set `quarkus.artemis.xa-enabled` / `quarkus.artemis."named-configuration".xa-enabled` to *true*. == URL as optional configuration -The `url` configuration property is optional. But in general, without a `url` property, we cannot create a connection. In case of tests with embedded resources or devservices, the corresponding annotation/service injects a url. But if the application starts up and no `url` property is found, the creation of the bean will throw a `RuntimeException` with a corresponding error message. Notice that this will happen when the bean is created. If the bean is never used (and thus never created), the exception will not occur. +The `url` configuration property is optional. But in general, without a `url` property, we cannot create a connection. In case of tests with embedded resources or devservices, the corresponding annotation/service injects an url. But if the application starts up and no `url` property is found, the creation of the bean will throw a `RuntimeException` with a corresponding error message. Notice that this will happen when the bean is created. If the bean is never used (and thus never created), the exception will not occur. == Health checks [[health_checks]] By default, all configurations are added to the health check endpoint when extension `quarkus-smallrye-health` is loaded. @@ -239,7 +283,7 @@ We can disable health checks for individual configurations by setting `quarkus.a IMPORTANT: Note that we can only enable health checks through the above configuration if `quarkus.artemis.health.enabled` is *true*. Otherwise, setting `quarkus.artemis.health-exclude` / `quarkus.artemis."named-connection".health-exclude` has no effect. -If we create `ServerLocator`- (extension `quarkus-artemis-core`) or `ConnectionFactory`- (extension `quarkus-artemis-jms`) beans within our application (i.e. outside of this extension), we can include them in the health check by using the link:https://javadoc.io/doc/io.smallrye.common/smallrye-common-annotation/latest/io/smallrye/common/annotation/Identifier.html[`Identifier` annotation], e.g.: +If we create `ServerLocator`- (extension `quarkus-artemis-core`) or `ConnectionFactory`- (extension `quarkus-artemis-jms`) beans within our application (i.e. outside of this extension), we can include them in the health check by using the link:https://javadoc.io/doc/io.smallrye.common/smallrye-common-annotation/latest/io/smallrye/common/annotation/Identifier.html[`@Identifier` annotation], e.g.: .Defining a `ServerLocator`-bean that is picked up automatically by health checks [source,java,subs=attributes+] @@ -273,6 +317,36 @@ If we do not want that beans created within our application is picked up by the IMPORTANT: Note that `ServerLocator` s / `ConnectionFactory` s are only picked up when `quarkus.artemis.health.enabled` is *true*. +== Camel support +All connection factories that are configured through `quarkus-artemis-jms` are automatically registered in the camel context, if the program uses camel. This allows us to reference the connection factories by name, e.g.: + +.Referencing `ConnectionFactory` s in a camel route by their bean name +[source,java,subs=attributes+] +---- +from(jms("queue:in").connectionFactory("")) + .to(jms("queue:out").connectionFactory("named")); +---- + +As with <>, connection factories that are defined outside this extension, but are annotated with link:https://github.com/smallrye/smallrye-common/blob/main/annotation/src/main/java/io/smallrye/common/annotation/Identifier.java[`@Identifier`] are treated the same way. So if we define a `ConnectionFactory`-bean in our code, e.g. through a method annotated with link:https://jakarta.ee/specifications/cdi/4.0/apidocs/jakarta.cdi/jakarta/enterprise/inject/produces[`@Produces`] and, for example, `@Identifier("externally-defined")`, we can use this `ConnectionFactory` as follows: + +.Referencing an externally defined `ConnectionFactory`-bean by its name +[source,java,subs=attributes+] +---- +from(jms("queue:in").connectionFactory("externally-defined")) + .to(jms("queue:out").connectionFactory("externally-defined")); +---- + +Finally, if only a single `ConnectionFactory` is defined through `quarkus-artemis-jms`, this `ConnectionFactory` is always registered as link:https://jakarta.ee/specifications/cdi/2.0/apidocs/javax/enterprise/inject/default[`@Default`] bean (see Section <>). This allows us to use this `ConnectionFactory` implicitly in a camel route, without setting it explicitly: + +.Implicitly use the only `ConnectionFactory`-bean defined in the application +[source,java,subs=attributes+] +---- +from(jms("queue:in")) + .to(jms("queue:out")); +---- + +This also works for an externally defined `ConnectionFactory`, as long as it is defined as `@Default`. This mechanism stops working as soon as more than one `ConnectionFactory` bean is defined in the application. + == Artemis DevServices Artemis DevServices are automatically enabled unless `quarkus.artemis.url` / `quarkus.artemis."named-configuration".url` is set or `quarkus.artemis.devservices.enabled` / `quarkus.artemis."named-configuration".enabled` is *false* explicitly. And if you still want to use `ArtemisTestResource` in the test, you need to disable artemis devservices. @@ -298,7 +372,7 @@ This instance can be configured by placing a `broker-named-1.xml` in `src/test/r For an in-depth explanation of what can be configured in a `broker.xml`, please see the link:https://activemq.apache.org/components/artemis/documentation/latest/configuration-index.html:[official Artemis documentation]. == Examples -Examples can be found in the `integration-tests` module, e.g +Examples can be found in the `integration-tests` module, e.g. https://github.com/quarkiverse/quarkus-artemis/tree/2.0.0/integration-tests/core/with-default[The Apache ActiveMQ Artemis Core integration with default configuration tests module] [[extension-configuration-reference]] diff --git a/integration-tests/camel-jms/pom.xml b/integration-tests/camel-jms/pom.xml new file mode 100644 index 00000000..2879b2b8 --- /dev/null +++ b/integration-tests/camel-jms/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + io.quarkiverse.artemis + quarkus-artemis-integration-tests-parent + 999-SNAPSHOT + + + quarkus-integration-test-artemis-camel-jms-parent + Quarkus - Artemis - Integration Tests - Camel JMS Parent + The Apache ActiveMQ Artemis Camel JMS integration tests parent module + + pom + + with-default + with-default-and-named + with-external + with-named + with-named-and-external + + + + + + + + + + io.quarkiverse.artemis + quarkus-artemis-jms + + + + + org.apache.camel.quarkus + camel-quarkus-jms + + + \ No newline at end of file diff --git a/integration-tests/camel-jms/with-default-and-named/pom.xml b/integration-tests/camel-jms/with-default-and-named/pom.xml new file mode 100644 index 00000000..90aba5f2 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + io.quarkiverse.artemis + quarkus-integration-test-artemis-camel-jms-parent + 999-SNAPSHOT + + + quarkus-integration-test-artemis-camel-jms-with-default-and-named + Quarkus - Artemis - Integration Tests - Camel JMS - With default and named configuration + The Apache ActiveMQ Artemis Camel JMS integration tests with default and named configuration module + diff --git a/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisConsumerManager.java b/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisConsumerManager.java new file mode 100644 index 00000000..f2799384 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisConsumerManager.java @@ -0,0 +1,39 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSConsumer; +import javax.jms.JMSContext; +import javax.jms.JMSException; + +import io.smallrye.common.annotation.Identifier; + +public class ArtemisConsumerManager { + static class Producer { + @Produces + @ApplicationScoped + @Identifier("named") + ArtemisConsumerManager namedConsumerManager( + @SuppressWarnings("CdiInjectionPointsInspection") @Identifier("named") ConnectionFactory connectionFactory) { + return new ArtemisConsumerManager(connectionFactory, "out"); + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + public ArtemisConsumerManager(ConnectionFactory connectionFactory, String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + public String receive() { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE); + JMSConsumer consumer = context.createConsumer(context.createQueue(queueName))) { + return consumer.receive(1000L).getBody(String.class); + } catch (JMSException e) { + throw new RuntimeException("Could not receive message", e); + } + } +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisEndpoint.java b/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisEndpoint.java new file mode 100644 index 00000000..aed93853 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisEndpoint.java @@ -0,0 +1,30 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import io.smallrye.common.annotation.Identifier; + +@Path("send-and-receive") +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class ArtemisEndpoint { + private final ArtemisProducerManager defaultProducerManager; + private final ArtemisConsumerManager namedConsumerManager; + + public ArtemisEndpoint( + ArtemisProducerManager defaultProducerManager, + @Identifier("named") ArtemisConsumerManager namedConsumerManager) { + this.defaultProducerManager = defaultProducerManager; + this.namedConsumerManager = namedConsumerManager; + } + + @POST + public String sendAndReceive(String message) { + defaultProducerManager.send(message); + return namedConsumerManager.receive(); + } +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisProducerManager.java b/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisProducerManager.java new file mode 100644 index 00000000..db9adfa5 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisProducerManager.java @@ -0,0 +1,42 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSContext; +import javax.jms.JMSProducer; + +public class ArtemisProducerManager { + static class Producer { + @Produces + @ApplicationScoped + ArtemisProducerManager defaultProducerManager( + @SuppressWarnings("CdiInjectionPointsInspection") ConnectionFactory defaultConnectionFactory) { + return new ArtemisProducerManager(defaultConnectionFactory, "in"); + } + + Producer() { + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + private ArtemisProducerManager( + ConnectionFactory connectionFactory, + String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + private void send(JMSContext context, String body) { + JMSProducer producer = context.createProducer(); + producer.send(context.createQueue(queueName), body); + } + + public void send(String body) { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE)) { + send(context, body); + } + } +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/TransferRoute.java b/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/TransferRoute.java new file mode 100644 index 00000000..f8df7838 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/main/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/TransferRoute.java @@ -0,0 +1,15 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed; + +import static org.apache.camel.builder.endpoint.StaticEndpointBuilders.jms; + +import org.apache.camel.builder.RouteConfigurationBuilder; + +@SuppressWarnings("unused") +public class TransferRoute extends RouteConfigurationBuilder { + + @Override + public void configuration() { + from(jms("queue:in").connectionFactory("")) + .to(jms("queue:out").connectionFactory("named")); + } +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/main/resources/application.properties b/integration-tests/camel-jms/with-default-and-named/src/main/resources/application.properties new file mode 100644 index 00000000..24631638 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/main/resources/application.properties @@ -0,0 +1,2 @@ +quarkus.artemis.devservices.enabled=false +quarkus.artemis."named".devservices.enabled=false \ No newline at end of file diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisHealthCheckHelper.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisHealthCheckHelper.java new file mode 100644 index 00000000..99a896d5 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/ArtemisHealthCheckHelper.java @@ -0,0 +1,37 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.jupiter.api.Assertions; + +import io.restassured.RestAssured; +import io.restassured.common.mapper.TypeRef; +import io.restassured.response.Response; + +public abstract class ArtemisHealthCheckHelper { + + public static void test(String endpoint, Set expectedConfigurations) { + Response response = RestAssured.with().get(endpoint); + Assertions.assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.statusCode()); + + Map body = response.as(new TypeRef<>() { + }); + Assertions.assertEquals("UP", body.get("status")); + + @SuppressWarnings("unchecked") + List> checks = (List>) body.get("checks"); + Assertions.assertEquals(1, checks.size()); + Map check = checks.get(0); + Assertions.assertEquals("Artemis JMS health check", check.get("name")); + + @SuppressWarnings("unchecked") + Map data = (Map) check.get("data"); + Assertions.assertEquals(expectedConfigurations.size(), data.size()); + Assertions.assertEquals(expectedConfigurations, data.keySet()); + for (String namedConfiguration : expectedConfigurations) { + Assertions.assertEquals("UP", data.get(namedConfiguration)); + } + } +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/BaseSendAndReceiveTest.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/BaseSendAndReceiveTest.java new file mode 100644 index 00000000..ba438fba --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/BaseSendAndReceiveTest.java @@ -0,0 +1,27 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +import javax.ws.rs.core.Response; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.common.http.TestHTTPEndpoint; + +@TestHTTPEndpoint(ArtemisEndpoint.class) +public abstract class BaseSendAndReceiveTest { + @Test + + void test() { + String body = "body"; + + given() + .body(body) + .when() + .post() + .then() + .statusCode(is(Response.Status.OK.getStatusCode())) + .body(is(body)); + } +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/devservices/DevServicesHealthCheckTest.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/devservices/DevServicesHealthCheckTest.java new file mode 100644 index 00000000..805eb522 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/devservices/DevServicesHealthCheckTest.java @@ -0,0 +1,23 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed.devservices; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import io.quarkus.it.artemis.camel.jms.withdefaultandnamed.ArtemisHealthCheckHelper; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; + +@QuarkusTest +@TestProfile(DevservicesArtemisEnabled.class) +class DevServicesHealthCheckTest extends ArtemisHealthCheckHelper { + @Test + void testHealth() { + ArtemisHealthCheckHelper.test("/q/health", Set.of("", "named")); + } + + @Test + void testReady() { + ArtemisHealthCheckHelper.test("/q/health/ready", Set.of("", "named")); + } +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/devservices/DevServicesSendAndReceiveTest.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/devservices/DevServicesSendAndReceiveTest.java new file mode 100644 index 00000000..48b74476 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/devservices/DevServicesSendAndReceiveTest.java @@ -0,0 +1,10 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed.devservices; + +import io.quarkus.it.artemis.camel.jms.withdefaultandnamed.BaseSendAndReceiveTest; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; + +@QuarkusTest +@TestProfile(DevservicesArtemisEnabled.class) +class DevServicesSendAndReceiveTest extends BaseSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/devservices/DevservicesArtemisEnabled.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/devservices/DevservicesArtemisEnabled.java new file mode 100644 index 00000000..e5b5784d --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/devservices/DevservicesArtemisEnabled.java @@ -0,0 +1,24 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed.devservices; + +import java.util.HashMap; +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTestProfile; + +public class DevservicesArtemisEnabled implements QuarkusTestProfile { + public DevservicesArtemisEnabled() { + } + + @Override + public Map getConfigOverrides() { + Map props = new HashMap<>(); + props.put("quarkus.artemis.devservices.enabled", "true"); + props.put("quarkus.artemis.\"named\".devservices.enabled", "true"); + return props; + } + + @Override + public boolean disableGlobalTestResources() { + return true; + } +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedHealthCheckITCase.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedHealthCheckITCase.java new file mode 100644 index 00000000..562acafa --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedHealthCheckITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedHealthCheckITCase extends EmbeddedHealthCheckTest { +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedHealthCheckTest.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedHealthCheckTest.java new file mode 100644 index 00000000..d5a993d9 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedHealthCheckTest.java @@ -0,0 +1,25 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed.embedded; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import io.quarkus.artemis.test.ArtemisTestResource; +import io.quarkus.it.artemis.camel.jms.withdefaultandnamed.ArtemisHealthCheckHelper; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(ArtemisTestResource.class) +@QuarkusTestResource(NamedArtemisTestResource.class) +class EmbeddedHealthCheckTest extends ArtemisHealthCheckHelper { + @Test + void testHealth() { + ArtemisHealthCheckHelper.test("/q/health", Set.of("", "named")); + } + + @Test + void testReady() { + ArtemisHealthCheckHelper.test("/q/health/ready", Set.of("", "named")); + } +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedSendAndReceiveITCase.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedSendAndReceiveITCase.java new file mode 100644 index 00000000..0416f95c --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedSendAndReceiveITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedSendAndReceiveITCase extends EmbeddedSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedSendAndReceiveTest.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedSendAndReceiveTest.java new file mode 100644 index 00000000..e762348b --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/EmbeddedSendAndReceiveTest.java @@ -0,0 +1,12 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed.embedded; + +import io.quarkus.artemis.test.ArtemisTestResource; +import io.quarkus.it.artemis.camel.jms.withdefaultandnamed.BaseSendAndReceiveTest; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(ArtemisTestResource.class) +@QuarkusTestResource(NamedArtemisTestResource.class) +class EmbeddedSendAndReceiveTest extends BaseSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/NamedArtemisTestResource.java b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/NamedArtemisTestResource.java new file mode 100644 index 00000000..96a4e2dd --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/java/io/quarkus/it/artemis/camel/jms/withdefaultandnamed/embedded/NamedArtemisTestResource.java @@ -0,0 +1,9 @@ +package io.quarkus.it.artemis.camel.jms.withdefaultandnamed.embedded; + +import io.quarkus.artemis.test.ArtemisTestResource; + +public class NamedArtemisTestResource extends ArtemisTestResource { + public NamedArtemisTestResource() { + super("named"); + } +} \ No newline at end of file diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/resources/broker-named.xml b/integration-tests/camel-jms/with-default-and-named/src/test/resources/broker-named.xml new file mode 100644 index 00000000..0ac0b9a8 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/resources/broker-named.xml @@ -0,0 +1,26 @@ + + + ./target/artemis/named/paging + ./target/artemis/named/bindings + ./target/artemis/named/journal + ./target/artemis/named/large-messages + + + tcp://localhost:61617 + + + tcp://localhost:61617 + + + -1 + false + + +
+ + + +
+
+
+
diff --git a/integration-tests/camel-jms/with-default-and-named/src/test/resources/broker.xml b/integration-tests/camel-jms/with-default-and-named/src/test/resources/broker.xml new file mode 100644 index 00000000..1e9a9e65 --- /dev/null +++ b/integration-tests/camel-jms/with-default-and-named/src/test/resources/broker.xml @@ -0,0 +1,26 @@ + + + ./target/artemis/default/paging + ./target/artemis/default/bindings + ./target/artemis/default/journal + ./target/artemis/default/large-messages + + + tcp://localhost:61616 + + + tcp://localhost:61616 + + + -1 + false + + +
+ + + +
+
+
+
diff --git a/integration-tests/camel-jms/with-default/pom.xml b/integration-tests/camel-jms/with-default/pom.xml new file mode 100644 index 00000000..87abff86 --- /dev/null +++ b/integration-tests/camel-jms/with-default/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + io.quarkiverse.artemis + quarkus-integration-test-artemis-camel-jms-parent + 999-SNAPSHOT + + + quarkus-integration-test-artemis-camel-jms-with-default + Quarkus - Artemis - Integration Tests - Camel JMS - With default configuration + The Apache ActiveMQ Artemis Camel JMS integration tests with default configuration module + \ No newline at end of file diff --git a/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisConsumerManager.java b/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisConsumerManager.java new file mode 100644 index 00000000..d9adb6f6 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisConsumerManager.java @@ -0,0 +1,36 @@ +package io.quarkus.it.artemis.camel.jms.withdefault; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSConsumer; +import javax.jms.JMSContext; +import javax.jms.JMSException; + +public class ArtemisConsumerManager { + static class Producer { + @Produces + @ApplicationScoped + ArtemisConsumerManager defaultConsumerManager( + @SuppressWarnings("CdiInjectionPointsInspection") ConnectionFactory connectionFactory) { + return new ArtemisConsumerManager(connectionFactory, "out"); + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + public ArtemisConsumerManager(ConnectionFactory connectionFactory, String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + public String receive() { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE); + JMSConsumer consumer = context.createConsumer(context.createQueue(queueName))) { + return consumer.receive(1000L).getBody(String.class); + } catch (JMSException e) { + throw new RuntimeException("Could not receive message", e); + } + } +} diff --git a/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisEndpoint.java b/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisEndpoint.java new file mode 100644 index 00000000..f6a3245a --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisEndpoint.java @@ -0,0 +1,28 @@ +package io.quarkus.it.artemis.camel.jms.withdefault; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("send-and-receive") +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class ArtemisEndpoint { + private final ArtemisConsumerManager consumerManager; + private final ArtemisProducerManager producerManager; + + public ArtemisEndpoint( + ArtemisConsumerManager consumerManager, + ArtemisProducerManager producerManager) { + this.consumerManager = consumerManager; + this.producerManager = producerManager; + } + + @POST + public String sendAndReceive(String message) { + producerManager.send(message); + return consumerManager.receive(); + } +} diff --git a/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisProducerManager.java b/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisProducerManager.java new file mode 100644 index 00000000..b09b0541 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisProducerManager.java @@ -0,0 +1,42 @@ +package io.quarkus.it.artemis.camel.jms.withdefault; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSContext; +import javax.jms.JMSProducer; + +public class ArtemisProducerManager { + static class Producer { + @Produces + @ApplicationScoped + ArtemisProducerManager defaultProducer( + @SuppressWarnings("CdiInjectionPointsInspection") ConnectionFactory defaultConnectionFactory) { + return new ArtemisProducerManager(defaultConnectionFactory, "in"); + } + + Producer() { + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + private ArtemisProducerManager( + ConnectionFactory connectionFactory, + String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + private void send(JMSContext context, String body) { + JMSProducer producer = context.createProducer(); + producer.send(context.createQueue(queueName), body); + } + + public void send(String body) { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE)) { + send(context, body); + } + } +} \ No newline at end of file diff --git a/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/TransferRoute.java b/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/TransferRoute.java new file mode 100644 index 00000000..0197b5ac --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/main/java/io/quarkus/it/artemis/camel/jms/withdefault/TransferRoute.java @@ -0,0 +1,14 @@ +package io.quarkus.it.artemis.camel.jms.withdefault; + +import static org.apache.camel.builder.endpoint.StaticEndpointBuilders.jms; + +import org.apache.camel.builder.RouteConfigurationBuilder; + +@SuppressWarnings("unused") +public class TransferRoute extends RouteConfigurationBuilder { + @Override + public void configuration() { + from(jms("queue:in")) + .to(jms("queue:out")); + } +} diff --git a/integration-tests/camel-jms/with-default/src/main/resources/application.properties b/integration-tests/camel-jms/with-default/src/main/resources/application.properties new file mode 100644 index 00000000..e7984bd9 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/main/resources/application.properties @@ -0,0 +1 @@ +quarkus.artemis.devservices.enabled=false \ No newline at end of file diff --git a/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisHealthCheckHelper.java b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisHealthCheckHelper.java new file mode 100644 index 00000000..4a9a66fc --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/ArtemisHealthCheckHelper.java @@ -0,0 +1,37 @@ +package io.quarkus.it.artemis.camel.jms.withdefault; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.jupiter.api.Assertions; + +import io.restassured.RestAssured; +import io.restassured.common.mapper.TypeRef; +import io.restassured.response.Response; + +public abstract class ArtemisHealthCheckHelper { + + public static void test(String endpoint, Set expectedConfigurations) { + Response response = RestAssured.with().get(endpoint); + Assertions.assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.statusCode()); + + Map body = response.as(new TypeRef<>() { + }); + Assertions.assertEquals("UP", body.get("status")); + + @SuppressWarnings("unchecked") + List> checks = (List>) body.get("checks"); + Assertions.assertEquals(1, checks.size()); + Map check = checks.get(0); + Assertions.assertEquals("Artemis JMS health check", check.get("name")); + + @SuppressWarnings("unchecked") + Map data = (Map) check.get("data"); + Assertions.assertEquals(expectedConfigurations.size(), data.size()); + Assertions.assertEquals(expectedConfigurations, data.keySet()); + for (String namedConfiguration : expectedConfigurations) { + Assertions.assertEquals("UP", data.get(namedConfiguration)); + } + } +} diff --git a/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/BaseSendAndReceiveTest.java b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/BaseSendAndReceiveTest.java new file mode 100644 index 00000000..e15db553 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/BaseSendAndReceiveTest.java @@ -0,0 +1,27 @@ +package io.quarkus.it.artemis.camel.jms.withdefault; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +import javax.ws.rs.core.Response; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.common.http.TestHTTPEndpoint; + +@TestHTTPEndpoint(ArtemisEndpoint.class) +public abstract class BaseSendAndReceiveTest { + @Test + + void test() { + String body = "body"; + + given() + .body(body) + .when() + .post() + .then() + .statusCode(is(Response.Status.OK.getStatusCode())) + .body(is(body)); + } +} diff --git a/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/devservices/DevServicesHealthCheckTest.java b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/devservices/DevServicesHealthCheckTest.java new file mode 100644 index 00000000..5e9fe517 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/devservices/DevServicesHealthCheckTest.java @@ -0,0 +1,23 @@ +package io.quarkus.it.artemis.camel.jms.withdefault.devservices; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import io.quarkus.it.artemis.camel.jms.withdefault.ArtemisHealthCheckHelper; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; + +@QuarkusTest +@TestProfile(DevservicesArtemisEnabled.class) +class DevServicesHealthCheckTest extends ArtemisHealthCheckHelper { + @Test + void testHealth() { + ArtemisHealthCheckHelper.test("/q/health", Set.of("")); + } + + @Test + void testReady() { + ArtemisHealthCheckHelper.test("/q/health/ready", Set.of("")); + } +} diff --git a/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/devservices/DevServicesSendAndReceiveTest.java b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/devservices/DevServicesSendAndReceiveTest.java new file mode 100644 index 00000000..1865c381 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/devservices/DevServicesSendAndReceiveTest.java @@ -0,0 +1,10 @@ +package io.quarkus.it.artemis.camel.jms.withdefault.devservices; + +import io.quarkus.it.artemis.camel.jms.withdefault.BaseSendAndReceiveTest; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; + +@QuarkusTest +@TestProfile(DevservicesArtemisEnabled.class) +class DevServicesSendAndReceiveTest extends BaseSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/devservices/DevservicesArtemisEnabled.java b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/devservices/DevservicesArtemisEnabled.java new file mode 100644 index 00000000..a576d41a --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/devservices/DevservicesArtemisEnabled.java @@ -0,0 +1,23 @@ +package io.quarkus.it.artemis.camel.jms.withdefault.devservices; + +import java.util.HashMap; +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTestProfile; + +public class DevservicesArtemisEnabled implements QuarkusTestProfile { + public DevservicesArtemisEnabled() { + } + + @Override + public Map getConfigOverrides() { + Map props = new HashMap<>(); + props.put("quarkus.artemis.devservices.enabled", "true"); + return props; + } + + @Override + public boolean disableGlobalTestResources() { + return true; + } +} diff --git a/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedHealthCheckITCase.java b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedHealthCheckITCase.java new file mode 100644 index 00000000..b1e87ef0 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedHealthCheckITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withdefault.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedHealthCheckITCase extends EmbeddedHealthCheckTest { +} diff --git a/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedHealthCheckTest.java b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedHealthCheckTest.java new file mode 100644 index 00000000..cea98a55 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedHealthCheckTest.java @@ -0,0 +1,24 @@ +package io.quarkus.it.artemis.camel.jms.withdefault.embedded; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import io.quarkus.artemis.test.ArtemisTestResource; +import io.quarkus.it.artemis.camel.jms.withdefault.ArtemisHealthCheckHelper; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(ArtemisTestResource.class) +class EmbeddedHealthCheckTest extends ArtemisHealthCheckHelper { + @Test + void testHealth() { + ArtemisHealthCheckHelper.test("/q/health", Set.of("")); + } + + @Test + void testReady() { + ArtemisHealthCheckHelper.test("/q/health/ready", Set.of("")); + } +} diff --git a/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedSendAndReceiveITCase.java b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedSendAndReceiveITCase.java new file mode 100644 index 00000000..183d4d95 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedSendAndReceiveITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withdefault.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedSendAndReceiveITCase extends EmbeddedSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedSendAndReceiveTest.java b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedSendAndReceiveTest.java new file mode 100644 index 00000000..ec8c6639 --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/java/io/quarkus/it/artemis/camel/jms/withdefault/embedded/EmbeddedSendAndReceiveTest.java @@ -0,0 +1,11 @@ +package io.quarkus.it.artemis.camel.jms.withdefault.embedded; + +import io.quarkus.artemis.test.ArtemisTestResource; +import io.quarkus.it.artemis.camel.jms.withdefault.BaseSendAndReceiveTest; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(ArtemisTestResource.class) +class EmbeddedSendAndReceiveTest extends BaseSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-default/src/test/resources/broker.xml b/integration-tests/camel-jms/with-default/src/test/resources/broker.xml new file mode 100644 index 00000000..7090be3d --- /dev/null +++ b/integration-tests/camel-jms/with-default/src/test/resources/broker.xml @@ -0,0 +1,31 @@ + + + ./target/artemis/default/paging + ./target/artemis/default/bindings + ./target/artemis/default/journal + ./target/artemis/default/large-messages + + + tcp://localhost:61616 + + + tcp://localhost:61616 + + + -1 + false + + +
+ + + +
+
+ + + +
+
+
+
diff --git a/integration-tests/camel-jms/with-external/pom.xml b/integration-tests/camel-jms/with-external/pom.xml new file mode 100644 index 00000000..7a3b2c68 --- /dev/null +++ b/integration-tests/camel-jms/with-external/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + io.quarkiverse.artemis + quarkus-integration-test-artemis-camel-jms-parent + 999-SNAPSHOT + + + quarkus-integration-test-artemis-camel-jms-with-external + Quarkus - Artemis - Integration Tests - Camel JMS - With external configuration + The Apache ActiveMQ Artemis Camel JMS integration tests with external configuration module + diff --git a/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisConsumerManager.java b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisConsumerManager.java new file mode 100644 index 00000000..54bb0920 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisConsumerManager.java @@ -0,0 +1,36 @@ +package io.quarkus.it.artemis.camel.jms.withexternal; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSConsumer; +import javax.jms.JMSContext; +import javax.jms.JMSException; + +public class ArtemisConsumerManager { + static class Producer { + @Produces + @ApplicationScoped + ArtemisConsumerManager externalConsumerManager( + @SuppressWarnings("CdiInjectionPointsInspection") ConnectionFactory connectionFactory) { + return new ArtemisConsumerManager(connectionFactory, "out"); + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + public ArtemisConsumerManager(ConnectionFactory connectionFactory, String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + public String receive() { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE); + JMSConsumer consumer = context.createConsumer(context.createQueue(queueName))) { + return consumer.receive(1000L).getBody(String.class); + } catch (JMSException e) { + throw new RuntimeException("Could not receive message", e); + } + } +} diff --git a/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisEndpoint.java b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisEndpoint.java new file mode 100644 index 00000000..310fe4b8 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisEndpoint.java @@ -0,0 +1,28 @@ +package io.quarkus.it.artemis.camel.jms.withexternal; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("send-and-receive") +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class ArtemisEndpoint { + private final ArtemisProducerManager namedProducerManager; + private final ArtemisConsumerManager externalConsumerManager; + + public ArtemisEndpoint( + ArtemisProducerManager namedProducerManager, + ArtemisConsumerManager externalConsumerManager) { + this.namedProducerManager = namedProducerManager; + this.externalConsumerManager = externalConsumerManager; + } + + @POST + public String sendAndReceive(String message) { + namedProducerManager.send(message); + return externalConsumerManager.receive(); + } +} diff --git a/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisProducerManager.java b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisProducerManager.java new file mode 100644 index 00000000..2e44392c --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisProducerManager.java @@ -0,0 +1,42 @@ +package io.quarkus.it.artemis.camel.jms.withexternal; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSContext; +import javax.jms.JMSProducer; + +public class ArtemisProducerManager { + static class Producer { + @Produces + @ApplicationScoped + ArtemisProducerManager namedProducerManager( + @SuppressWarnings("CdiInjectionPointsInspection") ConnectionFactory defaultConnectionFactory) { + return new ArtemisProducerManager(defaultConnectionFactory, "in"); + } + + Producer() { + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + private ArtemisProducerManager( + ConnectionFactory connectionFactory, + String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + private void send(JMSContext context, String body) { + JMSProducer producer = context.createProducer(); + producer.send(context.createQueue(queueName), body); + } + + public void send(String body) { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE)) { + send(context, body); + } + } +} diff --git a/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ConnectionFactoryProducer.java b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ConnectionFactoryProducer.java new file mode 100644 index 00000000..2ee16f80 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/ConnectionFactoryProducer.java @@ -0,0 +1,24 @@ +package io.quarkus.it.artemis.camel.jms.withexternal; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Default; +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.Typed; +import javax.jms.ConnectionFactory; + +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +import io.smallrye.common.annotation.Identifier; + +public class ConnectionFactoryProducer { + @Produces + @Typed({ ConnectionFactory.class }) + @ApplicationScoped + @Default + @Identifier("externally-defined") + ActiveMQConnectionFactory externallyDefinedConnectionFactory( + @ConfigProperty(name = "artemis.externally-defined.url") String externallyDefinedUrl) { + return new ActiveMQConnectionFactory(externallyDefinedUrl, null, null); + } +} diff --git a/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/TransferRoute.java b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/TransferRoute.java new file mode 100644 index 00000000..28bc8f54 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/main/java/io/quarkus/it/artemis/camel/jms/withexternal/TransferRoute.java @@ -0,0 +1,15 @@ +package io.quarkus.it.artemis.camel.jms.withexternal; + +import static org.apache.camel.builder.endpoint.StaticEndpointBuilders.jms; + +import org.apache.camel.builder.RouteConfigurationBuilder; + +@SuppressWarnings("unused") +public class TransferRoute extends RouteConfigurationBuilder { + + @Override + public void configuration() { + from(jms("queue:in")) + .to(jms("queue:out")); + } +} diff --git a/integration-tests/camel-jms/with-external/src/main/resources/application.properties b/integration-tests/camel-jms/with-external/src/main/resources/application.properties new file mode 100644 index 00000000..0afe9ae7 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/main/resources/application.properties @@ -0,0 +1 @@ +artemis.externally-defined.url=tcp://dummy \ No newline at end of file diff --git a/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisHealthCheckHelper.java b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisHealthCheckHelper.java new file mode 100644 index 00000000..658c9a22 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/ArtemisHealthCheckHelper.java @@ -0,0 +1,37 @@ +package io.quarkus.it.artemis.camel.jms.withexternal; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.jupiter.api.Assertions; + +import io.restassured.RestAssured; +import io.restassured.common.mapper.TypeRef; +import io.restassured.response.Response; + +public abstract class ArtemisHealthCheckHelper { + + public static void test(String endpoint, Set expectedConfigurations) { + Response response = RestAssured.with().get(endpoint); + Assertions.assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.statusCode()); + + Map body = response.as(new TypeRef<>() { + }); + Assertions.assertEquals("UP", body.get("status")); + + @SuppressWarnings("unchecked") + List> checks = (List>) body.get("checks"); + Assertions.assertEquals(1, checks.size()); + Map check = checks.get(0); + Assertions.assertEquals("Artemis JMS health check", check.get("name")); + + @SuppressWarnings("unchecked") + Map data = (Map) check.get("data"); + Assertions.assertEquals(expectedConfigurations.size(), data.size()); + Assertions.assertEquals(expectedConfigurations, data.keySet()); + for (String namedConfiguration : expectedConfigurations) { + Assertions.assertEquals("UP", data.get(namedConfiguration)); + } + } +} diff --git a/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/BaseSendAndReceiveTest.java b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/BaseSendAndReceiveTest.java new file mode 100644 index 00000000..28a6c832 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/BaseSendAndReceiveTest.java @@ -0,0 +1,27 @@ +package io.quarkus.it.artemis.camel.jms.withexternal; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +import javax.ws.rs.core.Response; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.common.http.TestHTTPEndpoint; + +@TestHTTPEndpoint(ArtemisEndpoint.class) +public abstract class BaseSendAndReceiveTest { + @Test + + void test() { + String body = "body"; + + given() + .body(body) + .when() + .post() + .then() + .statusCode(is(Response.Status.OK.getStatusCode())) + .body(is(body)); + } +} diff --git a/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedHealthCheckITCase.java b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedHealthCheckITCase.java new file mode 100644 index 00000000..cf40e673 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedHealthCheckITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withexternal.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedHealthCheckITCase extends EmbeddedHealthCheckTest { +} diff --git a/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedHealthCheckTest.java b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedHealthCheckTest.java new file mode 100644 index 00000000..fc16b2ac --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedHealthCheckTest.java @@ -0,0 +1,23 @@ +package io.quarkus.it.artemis.camel.jms.withexternal.embedded; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import io.quarkus.it.artemis.camel.jms.withexternal.ArtemisHealthCheckHelper; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(ExternallyDefinedArtemisTestResource.class) +class EmbeddedHealthCheckTest extends ArtemisHealthCheckHelper { + @Test + void testHealth() { + ArtemisHealthCheckHelper.test("/q/health", Set.of("externally-defined")); + } + + @Test + void testReady() { + ArtemisHealthCheckHelper.test("/q/health/ready", Set.of("externally-defined")); + } +} diff --git a/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedSendAndReceiveITCase.java b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedSendAndReceiveITCase.java new file mode 100644 index 00000000..04c19f16 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedSendAndReceiveITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withexternal.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedSendAndReceiveITCase extends EmbeddedSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedSendAndReceiveTest.java b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedSendAndReceiveTest.java new file mode 100644 index 00000000..89c5969a --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/EmbeddedSendAndReceiveTest.java @@ -0,0 +1,10 @@ +package io.quarkus.it.artemis.camel.jms.withexternal.embedded; + +import io.quarkus.it.artemis.camel.jms.withexternal.BaseSendAndReceiveTest; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(ExternallyDefinedArtemisTestResource.class) +class EmbeddedSendAndReceiveTest extends BaseSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/ExternallyDefinedArtemisTestResource.java b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/ExternallyDefinedArtemisTestResource.java new file mode 100644 index 00000000..a2b2fe86 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/test/java/io/quarkus/it/artemis/camel/jms/withexternal/embedded/ExternallyDefinedArtemisTestResource.java @@ -0,0 +1,9 @@ +package io.quarkus.it.artemis.camel.jms.withexternal.embedded; + +import io.quarkus.artemis.test.ArtemisTestResource; + +public class ExternallyDefinedArtemisTestResource extends ArtemisTestResource { + public ExternallyDefinedArtemisTestResource() { + super("artemis", "externally-defined"); + } +} \ No newline at end of file diff --git a/integration-tests/camel-jms/with-external/src/test/resources/broker-externally-defined.xml b/integration-tests/camel-jms/with-external/src/test/resources/broker-externally-defined.xml new file mode 100644 index 00000000..20ceaeb3 --- /dev/null +++ b/integration-tests/camel-jms/with-external/src/test/resources/broker-externally-defined.xml @@ -0,0 +1,31 @@ + + + ./target/artemis/external/paging + ./target/artemis/external/bindings + ./target/artemis/external/journal + ./target/artemis/external/large-messages + + + tcp://localhost:61618 + + + tcp://localhost:61618 + + + -1 + false + + +
+ + + +
+
+ + + +
+
+
+
diff --git a/integration-tests/camel-jms/with-named-and-external/pom.xml b/integration-tests/camel-jms/with-named-and-external/pom.xml new file mode 100644 index 00000000..60d71612 --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + io.quarkiverse.artemis + quarkus-integration-test-artemis-camel-jms-parent + 999-SNAPSHOT + + + quarkus-integration-test-artemis-camel-jms-with-named-and-external + Quarkus - Artemis - Integration Tests - Camel JMS - With named and external configuration + The Apache ActiveMQ Artemis Camel JMS integration tests with named and external configuration module + diff --git a/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisConsumerManager.java b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisConsumerManager.java new file mode 100644 index 00000000..875ae691 --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisConsumerManager.java @@ -0,0 +1,39 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSConsumer; +import javax.jms.JMSContext; +import javax.jms.JMSException; + +import io.smallrye.common.annotation.Identifier; + +public class ArtemisConsumerManager { + static class Producer { + @Produces + @ApplicationScoped + @Identifier("externally-defined") + ArtemisConsumerManager externalConsumerManager( + @Identifier("externally-defined") ConnectionFactory connectionFactory) { + return new ArtemisConsumerManager(connectionFactory, "out"); + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + public ArtemisConsumerManager(ConnectionFactory connectionFactory, String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + public String receive() { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE); + JMSConsumer consumer = context.createConsumer(context.createQueue(queueName))) { + return consumer.receive(1000L).getBody(String.class); + } catch (JMSException e) { + throw new RuntimeException("Could not receive message", e); + } + } +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisEndpoint.java b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisEndpoint.java new file mode 100644 index 00000000..130e8c3d --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisEndpoint.java @@ -0,0 +1,30 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import io.smallrye.common.annotation.Identifier; + +@Path("send-and-receive") +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class ArtemisEndpoint { + private final ArtemisProducerManager namedProducerManager; + private final ArtemisConsumerManager externalConsumerManager; + + public ArtemisEndpoint( + @Identifier("named") ArtemisProducerManager namedProducerManager, + @Identifier("externally-defined") ArtemisConsumerManager externalConsumerManager) { + this.namedProducerManager = namedProducerManager; + this.externalConsumerManager = externalConsumerManager; + } + + @POST + public String sendAndReceive(String message) { + namedProducerManager.send(message); + return externalConsumerManager.receive(); + } +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisProducerManager.java b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisProducerManager.java new file mode 100644 index 00000000..5161bae0 --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisProducerManager.java @@ -0,0 +1,45 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSContext; +import javax.jms.JMSProducer; + +import io.smallrye.common.annotation.Identifier; + +public class ArtemisProducerManager { + static class Producer { + @Produces + @ApplicationScoped + @Identifier("named") + ArtemisProducerManager namedProducerManager( + @SuppressWarnings("CdiInjectionPointsInspection") @Identifier("named") ConnectionFactory defaultConnectionFactory) { + return new ArtemisProducerManager(defaultConnectionFactory, "in"); + } + + Producer() { + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + private ArtemisProducerManager( + ConnectionFactory connectionFactory, + String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + private void send(JMSContext context, String body) { + JMSProducer producer = context.createProducer(); + producer.send(context.createQueue(queueName), body); + } + + public void send(String body) { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE)) { + send(context, body); + } + } +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ConnectionFactoryProducer.java b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ConnectionFactoryProducer.java new file mode 100644 index 00000000..7838c752 --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ConnectionFactoryProducer.java @@ -0,0 +1,22 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.Typed; +import javax.jms.ConnectionFactory; + +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +import io.smallrye.common.annotation.Identifier; + +public class ConnectionFactoryProducer { + @Produces + @Typed({ ConnectionFactory.class }) + @ApplicationScoped + @Identifier("externally-defined") + ActiveMQConnectionFactory externallyDefinedConnectionFactory( + @ConfigProperty(name = "artemis.externally-defined.url") String externallyDefinedUrl) { + return new ActiveMQConnectionFactory(externallyDefinedUrl, null, null); + } +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/TransferRoute.java b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/TransferRoute.java new file mode 100644 index 00000000..0076390a --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/main/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/TransferRoute.java @@ -0,0 +1,15 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal; + +import static org.apache.camel.builder.endpoint.StaticEndpointBuilders.jms; + +import org.apache.camel.builder.RouteConfigurationBuilder; + +@SuppressWarnings("unused") +public class TransferRoute extends RouteConfigurationBuilder { + + @Override + public void configuration() { + from(jms("queue:in").connectionFactory("named")) + .to(jms("queue:out").connectionFactory("externally-defined")); + } +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/main/resources/application.properties b/integration-tests/camel-jms/with-named-and-external/src/main/resources/application.properties new file mode 100644 index 00000000..fd40af91 --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/main/resources/application.properties @@ -0,0 +1,2 @@ +quarkus.artemis."named".devservices.enabled=false +artemis.externally-defined.url=tcp://dummy \ No newline at end of file diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisHealthCheckHelper.java b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisHealthCheckHelper.java new file mode 100644 index 00000000..9726cd48 --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/ArtemisHealthCheckHelper.java @@ -0,0 +1,37 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.jupiter.api.Assertions; + +import io.restassured.RestAssured; +import io.restassured.common.mapper.TypeRef; +import io.restassured.response.Response; + +public abstract class ArtemisHealthCheckHelper { + + public static void test(String endpoint, Set expectedConfigurations) { + Response response = RestAssured.with().get(endpoint); + Assertions.assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.statusCode()); + + Map body = response.as(new TypeRef<>() { + }); + Assertions.assertEquals("UP", body.get("status")); + + @SuppressWarnings("unchecked") + List> checks = (List>) body.get("checks"); + Assertions.assertEquals(1, checks.size()); + Map check = checks.get(0); + Assertions.assertEquals("Artemis JMS health check", check.get("name")); + + @SuppressWarnings("unchecked") + Map data = (Map) check.get("data"); + Assertions.assertEquals(expectedConfigurations.size(), data.size()); + Assertions.assertEquals(expectedConfigurations, data.keySet()); + for (String namedConfiguration : expectedConfigurations) { + Assertions.assertEquals("UP", data.get(namedConfiguration)); + } + } +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/BaseSendAndReceiveTest.java b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/BaseSendAndReceiveTest.java new file mode 100644 index 00000000..fb19f56d --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/BaseSendAndReceiveTest.java @@ -0,0 +1,27 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +import javax.ws.rs.core.Response; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.common.http.TestHTTPEndpoint; + +@TestHTTPEndpoint(ArtemisEndpoint.class) +public abstract class BaseSendAndReceiveTest { + @Test + + void test() { + String body = "body"; + + given() + .body(body) + .when() + .post() + .then() + .statusCode(is(Response.Status.OK.getStatusCode())) + .body(is(body)); + } +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedHealthCheckITCase.java b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedHealthCheckITCase.java new file mode 100644 index 00000000..2e36130b --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedHealthCheckITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedHealthCheckITCase extends EmbeddedHealthCheckTest { +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedHealthCheckTest.java b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedHealthCheckTest.java new file mode 100644 index 00000000..79b59617 --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedHealthCheckTest.java @@ -0,0 +1,24 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal.embedded; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import io.quarkus.it.artemis.camel.jms.withnamedandexternal.ArtemisHealthCheckHelper; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(NamedArtemisTestResource.class) +@QuarkusTestResource(ExternallyDefinedArtemisTestResource.class) +class EmbeddedHealthCheckTest extends ArtemisHealthCheckHelper { + @Test + void testHealth() { + ArtemisHealthCheckHelper.test("/q/health", Set.of("named", "externally-defined")); + } + + @Test + void testReady() { + ArtemisHealthCheckHelper.test("/q/health/ready", Set.of("named", "externally-defined")); + } +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedSendAndReceiveITCase.java b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedSendAndReceiveITCase.java new file mode 100644 index 00000000..398f14bc --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedSendAndReceiveITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedSendAndReceiveITCase extends EmbeddedSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedSendAndReceiveTest.java b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedSendAndReceiveTest.java new file mode 100644 index 00000000..d0ab89eb --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/EmbeddedSendAndReceiveTest.java @@ -0,0 +1,11 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal.embedded; + +import io.quarkus.it.artemis.camel.jms.withnamedandexternal.BaseSendAndReceiveTest; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(NamedArtemisTestResource.class) +@QuarkusTestResource(ExternallyDefinedArtemisTestResource.class) +class EmbeddedSendAndReceiveTest extends BaseSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/ExternallyDefinedArtemisTestResource.java b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/ExternallyDefinedArtemisTestResource.java new file mode 100644 index 00000000..0a708312 --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/ExternallyDefinedArtemisTestResource.java @@ -0,0 +1,9 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal.embedded; + +import io.quarkus.artemis.test.ArtemisTestResource; + +public class ExternallyDefinedArtemisTestResource extends ArtemisTestResource { + public ExternallyDefinedArtemisTestResource() { + super("artemis", "externally-defined"); + } +} \ No newline at end of file diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/NamedArtemisTestResource.java b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/NamedArtemisTestResource.java new file mode 100644 index 00000000..aeb2093d --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/java/io/quarkus/it/artemis/camel/jms/withnamedandexternal/embedded/NamedArtemisTestResource.java @@ -0,0 +1,9 @@ +package io.quarkus.it.artemis.camel.jms.withnamedandexternal.embedded; + +import io.quarkus.artemis.test.ArtemisTestResource; + +public class NamedArtemisTestResource extends ArtemisTestResource { + public NamedArtemisTestResource() { + super("named"); + } +} \ No newline at end of file diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/resources/broker-externally-defined.xml b/integration-tests/camel-jms/with-named-and-external/src/test/resources/broker-externally-defined.xml new file mode 100644 index 00000000..ce3e9c2f --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/resources/broker-externally-defined.xml @@ -0,0 +1,26 @@ + + + ./target/artemis/external/paging + ./target/artemis/external/bindings + ./target/artemis/external/journal + ./target/artemis/external/large-messages + + + tcp://localhost:61618 + + + tcp://localhost:61618 + + + -1 + false + + +
+ + + +
+
+
+
diff --git a/integration-tests/camel-jms/with-named-and-external/src/test/resources/broker-named.xml b/integration-tests/camel-jms/with-named-and-external/src/test/resources/broker-named.xml new file mode 100644 index 00000000..82689d79 --- /dev/null +++ b/integration-tests/camel-jms/with-named-and-external/src/test/resources/broker-named.xml @@ -0,0 +1,26 @@ + + + ./target/artemis/named/paging + ./target/artemis/named/bindings + ./target/artemis/named/journal + ./target/artemis/named/large-messages + + + tcp://localhost:61617 + + + tcp://localhost:61617 + + + -1 + false + + +
+ + + +
+
+
+
diff --git a/integration-tests/camel-jms/with-named/pom.xml b/integration-tests/camel-jms/with-named/pom.xml new file mode 100644 index 00000000..8c69cc6f --- /dev/null +++ b/integration-tests/camel-jms/with-named/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + io.quarkiverse.artemis + quarkus-integration-test-artemis-camel-jms-parent + 999-SNAPSHOT + + + quarkus-integration-test-artemis-camel-jms-with-named + Quarkus - Artemis - Integration Tests - Camel JMS - With named configuration + The Apache ActiveMQ Artemis Camel JMS integration tests with named configuration module + diff --git a/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisConsumerManager.java b/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisConsumerManager.java new file mode 100644 index 00000000..3edab7f8 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisConsumerManager.java @@ -0,0 +1,36 @@ +package io.quarkus.it.artemis.camel.jms.withnamed; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSConsumer; +import javax.jms.JMSContext; +import javax.jms.JMSException; + +public class ArtemisConsumerManager { + static class Producer { + @Produces + @ApplicationScoped + ArtemisConsumerManager namedConsumerManager( + @SuppressWarnings("CdiInjectionPointsInspection") ConnectionFactory connectionFactory) { + return new ArtemisConsumerManager(connectionFactory, "out"); + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + public ArtemisConsumerManager(ConnectionFactory connectionFactory, String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + public String receive() { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE); + JMSConsumer consumer = context.createConsumer(context.createQueue(queueName))) { + return consumer.receive(1000L).getBody(String.class); + } catch (JMSException e) { + throw new RuntimeException("Could not receive message", e); + } + } +} diff --git a/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisEndpoint.java b/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisEndpoint.java new file mode 100644 index 00000000..1f4c5399 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisEndpoint.java @@ -0,0 +1,28 @@ +package io.quarkus.it.artemis.camel.jms.withnamed; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("send-and-receive") +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class ArtemisEndpoint { + private final ArtemisProducerManager defaultProducerManager; + private final ArtemisConsumerManager namedConsumerManager; + + public ArtemisEndpoint( + ArtemisProducerManager defaultProducerManager, + ArtemisConsumerManager namedConsumerManager) { + this.defaultProducerManager = defaultProducerManager; + this.namedConsumerManager = namedConsumerManager; + } + + @POST + public String sendAndReceive(String message) { + defaultProducerManager.send(message); + return namedConsumerManager.receive(); + } +} diff --git a/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisProducerManager.java b/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisProducerManager.java new file mode 100644 index 00000000..430f5436 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisProducerManager.java @@ -0,0 +1,42 @@ +package io.quarkus.it.artemis.camel.jms.withnamed; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.jms.ConnectionFactory; +import javax.jms.JMSContext; +import javax.jms.JMSProducer; + +public class ArtemisProducerManager { + static class Producer { + @Produces + @ApplicationScoped + ArtemisProducerManager defaultProducerManager( + @SuppressWarnings("CdiInjectionPointsInspection") ConnectionFactory defaultConnectionFactory) { + return new ArtemisProducerManager(defaultConnectionFactory, "in"); + } + + Producer() { + } + } + + private final ConnectionFactory connectionFactory; + private final String queueName; + + private ArtemisProducerManager( + ConnectionFactory connectionFactory, + String queueName) { + this.connectionFactory = connectionFactory; + this.queueName = queueName; + } + + private void send(JMSContext context, String body) { + JMSProducer producer = context.createProducer(); + producer.send(context.createQueue(queueName), body); + } + + public void send(String body) { + try (JMSContext context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE)) { + send(context, body); + } + } +} diff --git a/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/TransferRoute.java b/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/TransferRoute.java new file mode 100644 index 00000000..85272c71 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/main/java/io/quarkus/it/artemis/camel/jms/withnamed/TransferRoute.java @@ -0,0 +1,15 @@ +package io.quarkus.it.artemis.camel.jms.withnamed; + +import static org.apache.camel.builder.endpoint.StaticEndpointBuilders.jms; + +import org.apache.camel.builder.RouteConfigurationBuilder; + +@SuppressWarnings("unused") +public class TransferRoute extends RouteConfigurationBuilder { + + @Override + public void configuration() { + from(jms("queue:in")) + .to(jms("queue:out")); + } +} diff --git a/integration-tests/camel-jms/with-named/src/main/resources/application.properties b/integration-tests/camel-jms/with-named/src/main/resources/application.properties new file mode 100644 index 00000000..0bd36a68 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/main/resources/application.properties @@ -0,0 +1 @@ +quarkus.artemis."named".devservices.enabled=false \ No newline at end of file diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisHealthCheckHelper.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisHealthCheckHelper.java new file mode 100644 index 00000000..2802b18e --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/ArtemisHealthCheckHelper.java @@ -0,0 +1,37 @@ +package io.quarkus.it.artemis.camel.jms.withnamed; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.jupiter.api.Assertions; + +import io.restassured.RestAssured; +import io.restassured.common.mapper.TypeRef; +import io.restassured.response.Response; + +public abstract class ArtemisHealthCheckHelper { + + public static void test(String endpoint, Set expectedConfigurations) { + Response response = RestAssured.with().get(endpoint); + Assertions.assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.statusCode()); + + Map body = response.as(new TypeRef<>() { + }); + Assertions.assertEquals("UP", body.get("status")); + + @SuppressWarnings("unchecked") + List> checks = (List>) body.get("checks"); + Assertions.assertEquals(1, checks.size()); + Map check = checks.get(0); + Assertions.assertEquals("Artemis JMS health check", check.get("name")); + + @SuppressWarnings("unchecked") + Map data = (Map) check.get("data"); + Assertions.assertEquals(expectedConfigurations.size(), data.size()); + Assertions.assertEquals(expectedConfigurations, data.keySet()); + for (String namedConfiguration : expectedConfigurations) { + Assertions.assertEquals("UP", data.get(namedConfiguration)); + } + } +} diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/BaseSendAndReceiveTest.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/BaseSendAndReceiveTest.java new file mode 100644 index 00000000..bffd2a4b --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/BaseSendAndReceiveTest.java @@ -0,0 +1,27 @@ +package io.quarkus.it.artemis.camel.jms.withnamed; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +import javax.ws.rs.core.Response; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.common.http.TestHTTPEndpoint; + +@TestHTTPEndpoint(ArtemisEndpoint.class) +public abstract class BaseSendAndReceiveTest { + @Test + + void test() { + String body = "body"; + + given() + .body(body) + .when() + .post() + .then() + .statusCode(is(Response.Status.OK.getStatusCode())) + .body(is(body)); + } +} diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/devservices/DevServicesHealthCheckTest.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/devservices/DevServicesHealthCheckTest.java new file mode 100644 index 00000000..22a62c92 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/devservices/DevServicesHealthCheckTest.java @@ -0,0 +1,23 @@ +package io.quarkus.it.artemis.camel.jms.withnamed.devservices; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import io.quarkus.it.artemis.camel.jms.withnamed.ArtemisHealthCheckHelper; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; + +@QuarkusTest +@TestProfile(DevservicesArtemisEnabled.class) +class DevServicesHealthCheckTest extends ArtemisHealthCheckHelper { + @Test + void testHealth() { + ArtemisHealthCheckHelper.test("/q/health", Set.of("named")); + } + + @Test + void testReady() { + ArtemisHealthCheckHelper.test("/q/health/ready", Set.of("named")); + } +} diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/devservices/DevServicesSendAndReceiveTest.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/devservices/DevServicesSendAndReceiveTest.java new file mode 100644 index 00000000..15d054b7 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/devservices/DevServicesSendAndReceiveTest.java @@ -0,0 +1,10 @@ +package io.quarkus.it.artemis.camel.jms.withnamed.devservices; + +import io.quarkus.it.artemis.camel.jms.withnamed.BaseSendAndReceiveTest; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; + +@QuarkusTest +@TestProfile(DevservicesArtemisEnabled.class) +class DevServicesSendAndReceiveTest extends BaseSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/devservices/DevservicesArtemisEnabled.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/devservices/DevservicesArtemisEnabled.java new file mode 100644 index 00000000..3b3e75aa --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/devservices/DevservicesArtemisEnabled.java @@ -0,0 +1,23 @@ +package io.quarkus.it.artemis.camel.jms.withnamed.devservices; + +import java.util.HashMap; +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTestProfile; + +public class DevservicesArtemisEnabled implements QuarkusTestProfile { + public DevservicesArtemisEnabled() { + } + + @Override + public Map getConfigOverrides() { + Map props = new HashMap<>(); + props.put("quarkus.artemis.\"named\".devservices.enabled", "true"); + return props; + } + + @Override + public boolean disableGlobalTestResources() { + return true; + } +} diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedHealthCheckITCase.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedHealthCheckITCase.java new file mode 100644 index 00000000..db6ebc34 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedHealthCheckITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withnamed.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedHealthCheckITCase extends EmbeddedHealthCheckTest { +} diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedHealthCheckTest.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedHealthCheckTest.java new file mode 100644 index 00000000..1c37b4cc --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedHealthCheckTest.java @@ -0,0 +1,23 @@ +package io.quarkus.it.artemis.camel.jms.withnamed.embedded; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import io.quarkus.it.artemis.camel.jms.withnamed.ArtemisHealthCheckHelper; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(NamedArtemisTestResource.class) +class EmbeddedHealthCheckTest extends ArtemisHealthCheckHelper { + @Test + void testHealth() { + ArtemisHealthCheckHelper.test("/q/health", Set.of("named")); + } + + @Test + void testReady() { + ArtemisHealthCheckHelper.test("/q/health/ready", Set.of("named")); + } +} diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedSendAndReceiveITCase.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedSendAndReceiveITCase.java new file mode 100644 index 00000000..e32db86a --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedSendAndReceiveITCase.java @@ -0,0 +1,7 @@ +package io.quarkus.it.artemis.camel.jms.withnamed.embedded; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class EmbeddedSendAndReceiveITCase extends EmbeddedSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedSendAndReceiveTest.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedSendAndReceiveTest.java new file mode 100644 index 00000000..5a027230 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/EmbeddedSendAndReceiveTest.java @@ -0,0 +1,10 @@ +package io.quarkus.it.artemis.camel.jms.withnamed.embedded; + +import io.quarkus.it.artemis.camel.jms.withnamed.BaseSendAndReceiveTest; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(NamedArtemisTestResource.class) +class EmbeddedSendAndReceiveTest extends BaseSendAndReceiveTest { +} diff --git a/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/NamedArtemisTestResource.java b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/NamedArtemisTestResource.java new file mode 100644 index 00000000..47331774 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/java/io/quarkus/it/artemis/camel/jms/withnamed/embedded/NamedArtemisTestResource.java @@ -0,0 +1,9 @@ +package io.quarkus.it.artemis.camel.jms.withnamed.embedded; + +import io.quarkus.artemis.test.ArtemisTestResource; + +public class NamedArtemisTestResource extends ArtemisTestResource { + public NamedArtemisTestResource() { + super("named"); + } +} \ No newline at end of file diff --git a/integration-tests/camel-jms/with-named/src/test/resources/broker-named.xml b/integration-tests/camel-jms/with-named/src/test/resources/broker-named.xml new file mode 100644 index 00000000..0ac0b9a8 --- /dev/null +++ b/integration-tests/camel-jms/with-named/src/test/resources/broker-named.xml @@ -0,0 +1,26 @@ + + + ./target/artemis/named/paging + ./target/artemis/named/bindings + ./target/artemis/named/journal + ./target/artemis/named/large-messages + + + tcp://localhost:61617 + + + tcp://localhost:61617 + + + -1 + false + + +
+ + + +
+
+
+
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index e376a480..2a6c0834 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -13,6 +13,7 @@ pom + camel-jms core jms diff --git a/jms/deployment/pom.xml b/jms/deployment/pom.xml index 2e65d522..ab61c3dd 100644 --- a/jms/deployment/pom.xml +++ b/jms/deployment/pom.xml @@ -36,5 +36,10 @@ io.quarkiverse.artemis quarkus-artemis-jms + + org.apache.camel.quarkus + camel-quarkus-core-deployment + true +
diff --git a/jms/deployment/src/main/java/io/quarkus/artemis/jms/deployment/ArtemisJmsProcessor.java b/jms/deployment/src/main/java/io/quarkus/artemis/jms/deployment/ArtemisJmsProcessor.java index 45e90343..fad99684 100644 --- a/jms/deployment/src/main/java/io/quarkus/artemis/jms/deployment/ArtemisJmsProcessor.java +++ b/jms/deployment/src/main/java/io/quarkus/artemis/jms/deployment/ArtemisJmsProcessor.java @@ -53,17 +53,22 @@ ArtemisJmsConfiguredBuildItem configure( return null; } ArtemisJmsWrapper wrapper = getWrapper(recorder, wrapperItem); - final Set configurationNames = bootstrap.getConfigurationNames(); + Set configurationNames = bootstrap.getConfigurationNames(); + boolean isSoleConnectionFactory = configurationNames.size() == 1; for (String name : configurationNames) { - if (!shadowRunTimeConfigs.getNames().contains(name) - && buildTimeConfigs.getAllConfigs().getOrDefault(name, new ArtemisBuildTimeConfig()).isEmpty()) { + if (!shadowRunTimeConfigs.getNames().contains(name) && buildTimeConfigs.getAllConfigs().getOrDefault(name, + new ArtemisBuildTimeConfig()).isEmpty()) { continue; } - Supplier connectionFactorySupplier = recorder.getConnectionFactoryProducer(name, runtimeConfigs, - buildTimeConfigs, wrapper); - syntheticBeanProducer.produce(toSyntheticBeanBuildItem( + Supplier connectionFactorySupplier = recorder.getConnectionFactoryProducer( name, + runtimeConfigs, + buildTimeConfigs, + wrapper); + syntheticBeanProducer.produce(toSyntheticBeanBuildItem( connectionFactorySupplier, + name, + isSoleConnectionFactory, buildTimeConfigs.getAllConfigs().getOrDefault(name, new ArtemisBuildTimeConfig()).isXaEnabled())); } @@ -83,13 +88,14 @@ private static ArtemisJmsWrapper getWrapper( } private static SyntheticBeanBuildItem toSyntheticBeanBuildItem( - String name, Supplier connectionFactorySupplier, + String name, + boolean isSoleConnectionFactory, boolean isXaEnable) { SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator = initializeConfigurator(isXaEnable) .supplier(connectionFactorySupplier) .scope(ApplicationScoped.class); - return ArtemisCoreProcessor.addQualifiers(configurator, name) + return ArtemisCoreProcessor.addQualifiers(name, isSoleConnectionFactory, configurator) .setRuntimeInit() .done(); } diff --git a/jms/deployment/src/main/java/io/quarkus/artemis/jms/deployment/camel/CamelJmsRegistryEnhancerProcessor.java b/jms/deployment/src/main/java/io/quarkus/artemis/jms/deployment/camel/CamelJmsRegistryEnhancerProcessor.java new file mode 100644 index 00000000..beb2f77e --- /dev/null +++ b/jms/deployment/src/main/java/io/quarkus/artemis/jms/deployment/camel/CamelJmsRegistryEnhancerProcessor.java @@ -0,0 +1,19 @@ +package io.quarkus.artemis.jms.deployment.camel; + +import org.apache.camel.quarkus.core.CamelCapabilities; + +import io.quarkus.arc.deployment.AdditionalBeanBuildItem; +import io.quarkus.artemis.jms.runtime.camel.CamelContextEnhancer; +import io.quarkus.deployment.Capabilities; +import io.quarkus.deployment.annotations.BuildStep; + +public class CamelJmsRegistryEnhancerProcessor { + @SuppressWarnings("unused") + @BuildStep + AdditionalBeanBuildItem addCamelContextEnhancer(Capabilities capabilities) { + if (capabilities.isPresent(CamelCapabilities.CORE)) { + return AdditionalBeanBuildItem.unremovableOf(CamelContextEnhancer.class); + } + return null; + } +} diff --git a/jms/runtime/pom.xml b/jms/runtime/pom.xml index 1e603bfc..9c0dd3ae 100644 --- a/jms/runtime/pom.xml +++ b/jms/runtime/pom.xml @@ -49,5 +49,11 @@ org.apache.activemq artemis-jms-client + + + org.apache.camel.quarkus + camel-quarkus-core + true +
diff --git a/jms/runtime/src/main/java/io/quarkus/artemis/jms/runtime/camel/CamelContextEnhancer.java b/jms/runtime/src/main/java/io/quarkus/artemis/jms/runtime/camel/CamelContextEnhancer.java new file mode 100644 index 00000000..75e8c2c5 --- /dev/null +++ b/jms/runtime/src/main/java/io/quarkus/artemis/jms/runtime/camel/CamelContextEnhancer.java @@ -0,0 +1,23 @@ +package io.quarkus.artemis.jms.runtime.camel; + +import java.util.Collections; +import java.util.Map; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.jms.ConnectionFactory; + +import org.apache.camel.impl.event.CamelContextInitializingEvent; + +import io.quarkus.artemis.core.runtime.ArtemisUtil; + +@ApplicationScoped +public class CamelContextEnhancer { + void startUp(@Observes CamelContextInitializingEvent event) { + Map connectionFactoryNamesFromArc = ArtemisUtil + .extractIdentifiers(ConnectionFactory.class, Collections.emptySet()); + for (var entry : connectionFactoryNamesFromArc.entrySet()) { + event.getContext().getRegistry().bind(entry.getKey(), entry.getValue()); + } + } +} diff --git a/pom.xml b/pom.xml index ea5ece4c..42c71057 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,8 @@ 2.15.1.Final 2.26.0 + quarkus-camel-bom + 2.15.0.CR1