Skip to content

Commit

Permalink
Merge pull request quarkusio#14351 from gwenneg/issue-14333-artemis-j…
Browse files Browse the repository at this point in the history
…ms-npe

Produce Artemis JMS connection factory as a synthetic bean
  • Loading branch information
gsmet authored Jan 18, 2021
2 parents 80f7c55 + 1101835 commit 7bc0ae0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.quarkus.artemis.jms.deployment;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import javax.enterprise.context.ApplicationScoped;
import javax.jms.ConnectionFactory;

import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.artemis.core.deployment.ArtemisBuildTimeConfig;
import io.quarkus.artemis.core.deployment.ArtemisJmsBuildItem;
import io.quarkus.artemis.core.runtime.ArtemisRuntimeConfig;
import io.quarkus.artemis.jms.runtime.ArtemisJmsProducer;
import io.quarkus.artemis.jms.runtime.ArtemisJmsRecorder;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
Expand All @@ -18,12 +19,10 @@
public class ArtemisJmsProcessor {

@BuildStep
void load(BuildProducer<AdditionalBeanBuildItem> additionalBean, BuildProducer<FeatureBuildItem> feature,
BuildProducer<ArtemisJmsBuildItem> artemisJms) {
void load(BuildProducer<FeatureBuildItem> feature, BuildProducer<ArtemisJmsBuildItem> artemisJms) {

artemisJms.produce(new ArtemisJmsBuildItem());
feature.produce(new FeatureBuildItem(Feature.ARTEMIS_JMS));
additionalBean.produce(AdditionalBeanBuildItem.unremovableOf(ArtemisJmsProducer.class));
}

@BuildStep
Expand All @@ -36,9 +35,17 @@ HealthBuildItem health(ArtemisBuildTimeConfig buildConfig) {
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
ArtemisJmsConfiguredBuildItem configure(ArtemisJmsRecorder recorder, ArtemisRuntimeConfig runtimeConfig,
BeanContainerBuildItem beanContainer) {
BuildProducer<SyntheticBeanBuildItem> syntheticBeanProducer) {

SyntheticBeanBuildItem connectionFactory = SyntheticBeanBuildItem.configure(ConnectionFactory.class)
.supplier(recorder.getConnectionFactorySupplier(runtimeConfig))
.scope(ApplicationScoped.class)
.defaultBean()
.unremovable()
.setRuntimeInit()
.done();
syntheticBeanProducer.produce(connectionFactory);

recorder.setConfig(runtimeConfig, beanContainer.getValue());
return new ArtemisJmsConfiguredBuildItem();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package io.quarkus.artemis.jms.runtime;

import io.quarkus.arc.runtime.BeanContainer;
import java.util.function.Supplier;

import javax.jms.ConnectionFactory;

import org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory;

import io.quarkus.artemis.core.runtime.ArtemisRuntimeConfig;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class ArtemisJmsRecorder {

public void setConfig(ArtemisRuntimeConfig config, BeanContainer container) {
container.instance(ArtemisJmsProducer.class).setConfig(config);
public Supplier<ConnectionFactory> getConnectionFactorySupplier(ArtemisRuntimeConfig config) {
return new Supplier<ConnectionFactory>() {
@Override
public ConnectionFactory get() {
return new ActiveMQJMSConnectionFactory(config.url, config.username.orElse(null), config.password.orElse(null));
}
};
}
}

0 comments on commit 7bc0ae0

Please sign in to comment.