Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: Classes that should be initialized at run time got initialized during image building #467

Closed
bframke opened this issue Nov 25, 2019 · 31 comments

Comments

@bframke
Copy link

bframke commented Nov 25, 2019

What we are trying to do is sending Messages between IBM MQ and ActiveMQ Artemis. Therefore we use an selfmade Quarkus IBM MQ Extension and a selfmade Camel-JMS Extension. When we started the project there was no JMS support for Camel-Quarkus.

We currently face a problem with our Camel Extension. We tried to update it to a newer version to Camel 0.4.0, Graal 19.3.0 and Quarkus 1.0.0.CR2. But we receive this error message upon building a native image:

 io.netty.buffer.PooledByteBufAllocator the class was requested to be initialized at build time (from the command line and Quarkus).  To see why io.netty.buffer.PooledByteBufAllocator got initialized use -H:+TraceClassInitialization
com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 io.netty.buffer.PooledByteBufAllocator the class was requested to be initialized at build time (from the command line and Quarkus).  To see why io.netty.buffer.PooledByteBufAllocator got initialized use -H:+TraceClassInitialization
        at com.oracle.svm.core.util.UserError.abort(UserError.java:65)
        at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:494)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:188)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$8(NativeImageGenerator.java:711)
        at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:711)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:526)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:444)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Image build request failed with exit status 1

I already tried to use the --initialize-at-run-time and --initialize-at-build-time parameters. The first throws the same message and the second this:

com.oracle.svm.core.util.UserError$UserException: Incompatible change of initialization policy for io.netty.buffer.PooledByteBufAllocator: trying to change BUILD_TIME from the command line to RUN_TIME from the command line
        at com.oracle.svm.core.util.UserError.abort(UserError.java:65)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationConfiguration.insertRec(ClassInitializationConfiguration.java:96)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationConfiguration.insertRec(ClassInitializationConfiguration.java:107)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationConfiguration.insertRec(ClassInitializationConfiguration.java:107)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationConfiguration.insertRec(ClassInitializationConfiguration.java:107)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationConfiguration.insertRec(ClassInitializationConfiguration.java:107)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationConfiguration.insert(ClassInitializationConfiguration.java:63)
        at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.initializeAtRunTime(ConfigurableClassInitialization.java:205)
        at com.oracle.svm.hosted.classinitialization.InitKind.lambda$stringConsumer$0(InitKind.java:69)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.processClassInitializationOptions(ClassInitializationFeature.java:146)
        at com.oracle.svm.hosted.HostedConfiguration.setDefaultIfEmpty(HostedConfiguration.java:71)
        at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:819)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:524)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:444)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Image build request failed with exit status 1

I also tried to add this class via rerun and the Extension-Loader from Quarkus which also runs into an error in this case. Is there anyway for Camel to help or is the netty hub better suited for that?

@lburgazzoli
Copy link
Contributor

lburgazzoli commented Nov 25, 2019

GraalVM 19.3.0 is not yet officially supported by quarkus so as first step I'd recommend to stick with 19.2.x.

I'd also recommend to use camel sjms if possible as it does not depend on spring and there is an extension available on master.

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Okay, the extension camel-quarkus-sjms is not released anywhere I looked. Tried it via maven search and some googleing only to end up in the readme which tells me, it does exist.

@lburgazzoli
Copy link
Contributor

It is not yet available in a release but you can use it from Apache Snapshots Repo or build it from source.

It will be available in the next Camel Quarkus release

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Ah okay, currently building it for our snapshot repo. I will test it out and let you know if the problem above still appears or not.

@lburgazzoli
Copy link
Contributor

There's a small integration test here which is far to be completed but can at least give you some hints about the dependencies and set-up

@bframke
Copy link
Author

bframke commented Nov 25, 2019

No changes here. Used SJMS and Graal 19.2.1

 io.netty.buffer.PooledByteBufAllocator the class was requested to be initialized at build time (from the command line and Quarkus).  To see why io.netty.buffer.PooledByteBufAllocator got initialized use -H:+TraceClassInitialization
com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 io.netty.buffer.PooledByteBufAllocator the class was requested to be initialized at build time (from the command line and Quarkus).  To see why io.netty.buffer.PooledByteBufAllocator got initialized use -H:+TraceClassInitialization
        at com.oracle.svm.core.util.UserError.abort(UserError.java:65)
        at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:494)
        at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:188)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$8(NativeImageGenerator.java:711)
        at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:711)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:526)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:444)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Image build request failed with exit status 1

@lburgazzoli
Copy link
Contributor

can you share the example or part of it ? netty substitutions should be provided by one of the extensions

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Not sure, what you exactly mean. But our project setup is just a "normal" java project with quarkus at its core and camel-quarkus plus camel-quarkus-sjms and quarkus-ibmmq.
ibmmqVersion=0.1 quarkusVersion=1.0.0.CR2 camelVersion=0.4.1-SNAPSHOT

dependencies {
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
    compile group: 'log4j', name: 'log4j', version: '1.2.17'
    compile group: 'xxx', name: 'quarkus-ibmmq', version: "${ibmmqVersion}"
    compile group: 'io.quarkus', name: 'quarkus-core-deployment', version: "${quarkusVersion}"
    compile group: 'io.quarkus', name: 'quarkus-jackson', version: "${quarkusVersion}"
    compile group: 'io.quarkus', name: 'quarkus-smallrye-metrics', version: "${quarkusVersion}"

    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.8'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.8'
    compile group: 'org.apache.activemq', name: 'artemis-jms-client', version: '2.9.0'
    compile group: 'org.apache.camel', name: 'camel-core-engine', version: '3.0.0-RC3'
    compile group: 'org.apache.camel', name: 'camel-sjms', version: '3.0.0-RC3'

    implementation group: 'org.apache.camel.quarkus', name: 'camel-quarkus-core', version: "0.4.0"
    implementation group: 'org.apache.camel.quarkus', name: 'camel-quarkus-core-xml', version: "0.4.0"
    implementation group: 'org.apache.camel.quarkus', name: 'camel-quarkus-sjms', version: "${camelVersion}"
    implementation group: 'org.apache.camel.quarkus', name: 'camel-quarkus-sjms-deployment', version: "${camelVersion}"
    implementation group: 'org.apache.camel.quarkus', name: 'camel-quarkus-sjms-parent', version: "${camelVersion}"
    implementation group: 'org.conscrypt', name: 'conscrypt-openjdk', version: '2.2.1'

    implementation enforcedPlatform('io.quarkus:quarkus-bom:'+"${quarkusVersion}")
    implementation("io.quarkus:quarkus-resteasy")

    testCompile group: 'org.junit.jupiter', name:'junit-jupiter-api', version:'5.3.1'
    testCompile 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
    testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
    testCompile group: 'org.mockito', name: 'mockito-core', version: '3.1.0'
    testCompile group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.1.0'
    testCompile "org.jboss.resteasy:resteasy-client:3.0.14.Final"
    testCompile "org.jboss.resteasy:resteasy-client-api:3.0.14.Final"
}

I could try to give you a variation of the project, but the quarkus-ibmmq extension is not shared for others in the internet.

@lburgazzoli
Copy link
Contributor

Thre's a quarkus-artemis-jms extension available, can you add it to your project ? it should alsoe bring netty substitutions

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Added the Extension and now it builds correctly. Also removed the artemis-jms-client.

thanks for the help

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Now when I try to start it I get this error: Cannot auto create component: jms

Which I normally only got, when there was no jms known to camel. Same happens to sjms.

1352 [main] ERROR org.apache.camel.quarkus.core.FastCamelContext - Error starting CamelContext (camel-1) due to exception thrown: Failed to create route bridge_TEST.AMQ.TO.IBM: Route(bridge_TEST.AMQ.TO.IBM)[From[jms://queue://TO_REMOTE?d... because of Failed to resolve endpoint: jms://queue://TO_REMOTE?acknowledgementModeName=CLIENT_ACKNOWLEDGE&connectionFactory=%23amqConnectionFactoryPlain&disableReplyTo=true due to: Cannot auto create component: jms
org.apache.camel.FailedToCreateRouteException: Failed to create route bridge_TEST.AMQ.TO.IBM: Route(bridge_TEST.AMQ.TO.IBM)[From[jms://queue://TO_REMOTE?d... because of Failed to resolve endpoint: jms://queue://TO_REMOTE?acknowledgementModeName=CLIENT_ACKNOWLEDGE&connectionFactory=%23amqConnectionFactoryPlain&disableReplyTo=true due to: Cannot auto create component: jms
        at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:114)
        at org.apache.camel.quarkus.core.FastModel.start(FastModel.java:65)
        at org.apache.camel.quarkus.core.BaseModel.startRoute(BaseModel.java:297)
        at org.apache.camel.quarkus.core.BaseModel.startRouteDefinitions(BaseModel.java:290)
        at org.apache.camel.quarkus.core.BaseModel.startRouteDefinitions(BaseModel.java:269)
        at org.apache.camel.quarkus.core.FastCamelContext.startRouteDefinitions(FastCamelContext.java:133)
        at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:2590)
        at org.apache.camel.impl.engine.AbstractCamelContext.lambda$doStart$2(AbstractCamelContext.java:2438)
        at org.apache.camel.impl.engine.AbstractCamelContext.doWithDefinedClassLoader(AbstractCamelContext.java:2455)
        at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2436)
        at org.apache.camel.support.service.ServiceSupport.start(ServiceSupport.java:99)
        at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2345)
        at org.apache.camel.quarkus.core.CamelMain.doStart(CamelMain.java:47)
        at org.apache.camel.support.service.ServiceSupport.start(ServiceSupport.java:99)
        at org.apache.camel.quarkus.core.CamelMainRecorder.start(CamelMainRecorder.java:79)
        at io.quarkus.deployment.steps.Main$start183.deploy_0(Main$start183.zig:97)
        at io.quarkus.deployment.steps.Main$start183.deploy(Main$start183.zig:36)
        at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:177)
        at io.quarkus.runtime.Application.start(Application.java:94)
        at io.quarkus.runtime.Application.run(Application.java:218)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:41)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jms://queue://TO_REMOTE?acknowledgementModeName=CLIENT_ACKNOWLEDGE&connectionFactory=%23amqConnectionFactoryPlain&disableReplyTo=true due to: Cannot auto create component: jms
        at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:801)
        at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:55)
        at org.apache.camel.impl.engine.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:120)
        at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:356)
        at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:108)
        ... 20 more
Caused by: org.apache.camel.RuntimeCamelException: Cannot auto create component: jms
        at org.apache.camel.impl.engine.AbstractCamelContext.getComponent(AbstractCamelContext.java:510)
        at org.apache.camel.impl.engine.AbstractCamelContext.getComponent(AbstractCamelContext.java:466)
        at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:743)
        ... 24 more
Caused by: org.apache.camel.RuntimeCamelException: Cannot auto create component: jms
        at org.apache.camel.impl.engine.AbstractCamelContext.initComponent(AbstractCamelContext.java:572)
        at org.apache.camel.impl.engine.AbstractCamelContext.access$000(AbstractCamelContext.java:165)
        at org.apache.camel.impl.engine.AbstractCamelContext$2.apply(AbstractCamelContext.java:494)
        at org.apache.camel.impl.engine.AbstractCamelContext$2.apply(AbstractCamelContext.java:490)
        at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
        at org.apache.camel.impl.engine.AbstractCamelContext.getComponent(AbstractCamelContext.java:490)
        ... 26 more
Caused by: org.apache.camel.PropertyBindingException: Error binding properties on bean: org.apache.camel.component.jms.JmsComponent@27068a50
        at org.apache.camel.support.PropertyBindingSupport.autowireSingletonPropertiesFromRegistry(PropertyBindingSupport.java:331)
        at org.apache.camel.main.BaseMainSupport$1.onComponentAdd(BaseMainSupport.java:938)
        at org.apache.camel.impl.engine.AbstractCamelContext.postInitComponent(AbstractCamelContext.java:453)
        at org.apache.camel.impl.engine.AbstractCamelContext.initComponent(AbstractCamelContext.java:569)
        ... 31 more
Caused by: java.lang.IllegalStateException: java.lang.RuntimeException: java.lang.NullPointerException
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:225)
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:262)
        at org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory.<init>(ActiveMQJMSConnectionFactory.java:42)
        at io.quarkus.artemis.jms.runtime.ArtemisJmsProducer.producesConnectionFactory(ArtemisJmsProducer.java:19)
        at io.quarkus.artemis.jms.runtime.ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.create(ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.zig:86)
        at io.quarkus.artemis.jms.runtime.ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.get(ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.zig:101)
        at io.quarkus.artemis.jms.runtime.ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.get(ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.zig:155)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:355)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:367)
        at io.quarkus.arc.impl.BeanManagerImpl.getReference(BeanManagerImpl.java:60)
        at org.apache.camel.quarkus.core.RuntimeBeanRepository.getReference(RuntimeBeanRepository.java:85)
        at org.apache.camel.quarkus.core.RuntimeBeanRepository.getReferencesByType(RuntimeBeanRepository.java:71)
        at org.apache.camel.quarkus.core.RuntimeBeanRepository.findByType(RuntimeBeanRepository.java:57)
        at org.apache.camel.support.DefaultRegistry.findByType(DefaultRegistry.java:199)
        at org.apache.camel.support.PropertyBindingSupport.doAutowireSingletonPropertiesFromRegistry(PropertyBindingSupport.java:365)
        at org.apache.camel.support.PropertyBindingSupport.doAutowireSingletonPropertiesFromRegistry(PropertyBindingSupport.java:400)
        at org.apache.camel.support.PropertyBindingSupport.autowireSingletonPropertiesFromRegistry(PropertyBindingSupport.java:328)
        ... 34 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.setBrokerURL(ActiveMQConnectionFactory.java:246)
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:223)
        ... 50 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.newLocator(ServerLocatorImpl.java:419)
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.setBrokerURL(ActiveMQConnectionFactory.java:243)
        ... 51 more
Caused by: java.lang.NullPointerException
        at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
        at org.apache.activemq.artemis.utils.uri.URIFactory.newObject(URIFactory.java:53)
        at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.newLocator(ServerLocatorImpl.java:417)
        ... 52 more
java.lang.RuntimeException: org.apache.camel.FailedToCreateRouteException: Failed to create route bridge_TEST.AMQ.TO.IBM: Route(bridge_TEST.AMQ.TO.IBM)[From[jms://queue://TO_REMOTE?d... because of Failed to resolve endpoint: jms://queue://TO_REMOTE?acknowledgementModeName=CLIENT_ACKNOWLEDGE&connectionFactory=%23amqConnectionFactoryPlain&disableReplyTo=true due to: Cannot auto create component: jms
        at org.apache.camel.quarkus.core.CamelMainRecorder.start(CamelMainRecorder.java:81)
        at io.quarkus.deployment.steps.Main$start183.deploy_0(Main$start183.zig:97)
        at io.quarkus.deployment.steps.Main$start183.deploy(Main$start183.zig:36)
        at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:177)
        at io.quarkus.runtime.Application.start(Application.java:94)
        at io.quarkus.runtime.Application.run(Application.java:218)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:41)
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route bridge_TEST.AMQ.TO.IBM: Route(bridge_TEST.AMQ.TO.IBM)[From[jms://queue://TO_REMOTE?d... because of Failed to resolve endpoint: jms://queue://TO_REMOTE?acknowledgementModeName=CLIENT_ACKNOWLEDGE&connectionFactory=%23amqConnectionFactoryPlain&disableReplyTo=true due to: Cannot auto create component: jms
        at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:114)
        at org.apache.camel.quarkus.core.FastModel.start(FastModel.java:65)
        at org.apache.camel.quarkus.core.BaseModel.startRoute(BaseModel.java:297)
        at org.apache.camel.quarkus.core.BaseModel.startRouteDefinitions(BaseModel.java:290)
        at org.apache.camel.quarkus.core.BaseModel.startRouteDefinitions(BaseModel.java:269)
        at org.apache.camel.quarkus.core.FastCamelContext.startRouteDefinitions(FastCamelContext.java:133)
        at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:2590)
        at org.apache.camel.impl.engine.AbstractCamelContext.lambda$doStart$2(AbstractCamelContext.java:2438)
        at org.apache.camel.impl.engine.AbstractCamelContext.doWithDefinedClassLoader(AbstractCamelContext.java:2455)
        at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2436)
        at org.apache.camel.support.service.ServiceSupport.start(ServiceSupport.java:99)
        at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2345)
        at org.apache.camel.quarkus.core.CamelMain.doStart(CamelMain.java:47)
        at org.apache.camel.support.service.ServiceSupport.start(ServiceSupport.java:99)
        at org.apache.camel.quarkus.core.CamelMainRecorder.start(CamelMainRecorder.java:79)
        ... 6 more
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jms://queue://TO_REMOTE?acknowledgementModeName=CLIENT_ACKNOWLEDGE&connectionFactory=%23amqConnectionFactoryPlain&disableReplyTo=true due to: Cannot auto create component: jms
        at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:801)
        at org.apache.camel.support.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:55)
        at org.apache.camel.impl.engine.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:120)
        at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:356)
        at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:108)
        ... 20 more
Caused by: org.apache.camel.RuntimeCamelException: Cannot auto create component: jms
        at org.apache.camel.impl.engine.AbstractCamelContext.getComponent(AbstractCamelContext.java:510)
        at org.apache.camel.impl.engine.AbstractCamelContext.getComponent(AbstractCamelContext.java:466)
        at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:743)
        ... 24 more
Caused by: org.apache.camel.RuntimeCamelException: Cannot auto create component: jms
        at org.apache.camel.impl.engine.AbstractCamelContext.initComponent(AbstractCamelContext.java:572)
        at org.apache.camel.impl.engine.AbstractCamelContext.access$000(AbstractCamelContext.java:165)
        at org.apache.camel.impl.engine.AbstractCamelContext$2.apply(AbstractCamelContext.java:494)
        at org.apache.camel.impl.engine.AbstractCamelContext$2.apply(AbstractCamelContext.java:490)
        at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
        at org.apache.camel.impl.engine.AbstractCamelContext.getComponent(AbstractCamelContext.java:490)
        ... 26 more
Caused by: org.apache.camel.PropertyBindingException: Error binding properties on bean: org.apache.camel.component.jms.JmsComponent@27068a50
        at org.apache.camel.support.PropertyBindingSupport.autowireSingletonPropertiesFromRegistry(PropertyBindingSupport.java:331)
        at org.apache.camel.main.BaseMainSupport$1.onComponentAdd(BaseMainSupport.java:938)
        at org.apache.camel.impl.engine.AbstractCamelContext.postInitComponent(AbstractCamelContext.java:453)
        at org.apache.camel.impl.engine.AbstractCamelContext.initComponent(AbstractCamelContext.java:569)
        ... 31 more
Caused by: java.lang.IllegalStateException: java.lang.RuntimeException: java.lang.NullPointerException
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:225)
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:262)
        at org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory.<init>(ActiveMQJMSConnectionFactory.java:42)
        at io.quarkus.artemis.jms.runtime.ArtemisJmsProducer.producesConnectionFactory(ArtemisJmsProducer.java:19)
        at io.quarkus.artemis.jms.runtime.ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.create(ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.zig:86)
        at io.quarkus.artemis.jms.runtime.ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.get(ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.zig:101)
        at io.quarkus.artemis.jms.runtime.ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.get(ArtemisJmsProducer_ProducerMethod_producesConnectionFactory_dfd3e4522e3960c5ee7cd44d7bd710976991a274_Bean.zig:155)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:355)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:367)
        at io.quarkus.arc.impl.BeanManagerImpl.getReference(BeanManagerImpl.java:60)
        at org.apache.camel.quarkus.core.RuntimeBeanRepository.getReference(RuntimeBeanRepository.java:85)
        at org.apache.camel.quarkus.core.RuntimeBeanRepository.getReferencesByType(RuntimeBeanRepository.java:71)
        at org.apache.camel.quarkus.core.RuntimeBeanRepository.findByType(RuntimeBeanRepository.java:57)
        at org.apache.camel.support.DefaultRegistry.findByType(DefaultReg

@lburgazzoli
Copy link
Contributor

Looks like the connection factory is misconfigured, but hard to guess why without a reproducer.
how did you configure the connection factory ?

@bframke
Copy link
Author

bframke commented Nov 25, 2019

They are configured via application.properties.

camel.activemq.connection.factories={ \
  "amqConnectionFactoryPlain" : { \
    "hostName" : "localhost", \
    "port" : 61616, \
    "ssl" : false \
  } \
}
camel.ibmmq.connection.factories={ \
  "ibmmqConnectionFactoryPlain" : { \
    "hostName" : "localhost", \
    "port" : 1414, \
    "ssl" : false, \
    "queueManager" : "QM1", \
    "channel" : "CAL" \
  }\
}

@lburgazzoli
Copy link
Contributor

This is how the it is set-up in our tests: https://github.com/apache/camel-quarkus/blob/master/integration-tests/sjms/src/main/resources/application.properties#L29

It is pretty simple but that is what the extension provides at the moment

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Also before the update to 0.4.0 we used CamelRuntime and now CamelMain to work with the ContextListener.

@lburgazzoli
Copy link
Contributor

I guess you are parsing the property and then you create the connection factory from that one right ?

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Yes and we configure it via the key:value map.

void registerActiveMqFactories() {
        Map<String, JmsConfig> activemqConnectionFactoriesConfig = getJmsConfigs(_activemqConfigsAsString);
        _logger.info("activemqConnectionFactoriesConfig : {}", activemqConnectionFactoriesConfig);
        if (activemqConnectionFactoriesConfig != null) {
            Registry registry = _camelMain.getCamelContext().getRegistry();
            activemqConnectionFactoriesConfig.forEach((name, config) -> {
                registry.bind(name, _activeMqConnectionFactoryProducer.getConnectionFactory(config));
            });
        }
    }

    void registerIbmMqFactories() {
        Map<String, JmsConfig> ibmmqConnectionFactoriesConfig = getJmsConfigs(_ibmmqConfigsAsString);
        _logger.info("ibmmqConnectionFactoriesConfig : {}", ibmmqConnectionFactoriesConfig);
        if (ibmmqConnectionFactoriesConfig != null) {
            Registry registry = _camelMain.getCamelContext().getRegistry();
            ibmmqConnectionFactoriesConfig.forEach((name, config) -> {
                registry.bind(name, _ibmMqConnectionFactoryProducer.getConnectionFactory(config));
            });
        }
    }

    private Map<String,JmsConfig> getJmsConfigs(String jsonValue) {
        try {
            return _jsonMapper.readValue(jsonValue,
                    TypeFactory.defaultInstance().constructMapLikeType(HashMap.class, String.class, JmsConfig.class));
        } catch (IOException e) {
            _logger.error("cannot convert config value '" + jsonValue +"'", e);
        }
        return null;
    }

The JMSConfig.class comes out of our IBM MQ Extension and worked for the Artemis and IBM ConnectionFactory so far.

@lburgazzoli
Copy link
Contributor

lburgazzoli commented Nov 25, 2019

I think the problem is in the aartemis-jms extension as it creates a connection factory even if the configurations are empty.

Can you try to add something like https://github.com/apache/camel-quarkus/blob/master/integration-tests/sjms/src/main/resources/application.properties#L29 in your application.properties ?
As alternative you can replace quarkus-artemis-jsm with quarkus-artemis-core

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Both changes have no effect. The part I showed a post back was just for the configuration. We initialize the Factories via Injection, could this be a problem?

ActiveMQ

@ApplicationScoped
public class ActiveMqConnectionFactoryProducer implements ConnectionFactoryProducer {

    private static final String PLAIN_CONNECTION_URL_FORMAT = "tcp://%s:%d";
    private static final String SSL_CONNECTION_URL_FORMAT = "tcp://%1$s:%2$d?sslEnabled=true&trustStorePath=%3$s&trustStorePassword=%4$s&keyStorePath=%5$s&keyStorePassword=%6$s";

    @Override
    public ConnectionFactory getConnectionFactory(JmsConfig config) {
        String connectionUrl;
        if (! config.isSsl()) {
            connectionUrl = String.format(PLAIN_CONNECTION_URL_FORMAT,
                    config.getHostName(),
                    config.getPort()
            );
        } else {
            connectionUrl = String.format(SSL_CONNECTION_URL_FORMAT,
                    config.getHostName(),
                    config.getPort(),
                    config.getTrustStorePath(),
                    config.getTrustStorePassword(),
                    config.getKeyStorePath(),
                    config.getKeyStorePassword()
            );
        }
        ActiveMQConnectionFactory factory = isEmpty(config.getUserName()) ?
                new ActiveMQConnectionFactory(connectionUrl) :
                new ActiveMQConnectionFactory(connectionUrl, config.getUserName(), config.getPassword());
        return factory;
    }

}

IBM MQ

@ApplicationScoped
@Unremovable
public class IbmMqConnectionFactoryProducer extends SslFactoryPreparer implements ConnectionFactoryProducer {
    private static final Logger _logger = LoggerFactory.getLogger(IbmMqConnectionFactoryProducer.class);
    private IbmMqConnectionFactory _factory;

    public IbmMqConnectionFactoryProducer() {
    }

    @Produces
    @Default
    public IbmMqConnectionFactory producesIbmMqConnectionFactory() {
        return this._factory;
    }

    public IbmMqConnectionFactory getFactory() {
        return this._factory;
    }

    public void setFactory(IbmMqConnectionFactory factory) {
        this._factory = factory;
    }

    public ConnectionFactory getConnectionFactory(JmsConfig config) {
        return this.createIbmMqConnectionFactory(config);
    }

    private ConnectionFactory createIbmMqConnectionFactory(JmsConfig config) {
        System.setProperty("com.ibm.mq.cfg.useIBMCipherMappings", "false");

        try {
            JmsFactoryFactory ff = JmsFactoryFactory.getInstance("com.ibm.msg.client.wmq");
            MQConnectionFactory ibmmqConnectionFactory = (MQConnectionFactory)ff.createConnectionFactory();
            ibmmqConnectionFactory.setStringProperty("XMSC_WMQ_HOST_NAME", config.hostName);
            ibmmqConnectionFactory.setIntProperty("XMSC_WMQ_PORT", config.port);
            ibmmqConnectionFactory.setStringProperty("XMSC_WMQ_CHANNEL", config.channel);
            ibmmqConnectionFactory.setIntProperty("XMSC_WMQ_CONNECTION_MODE", 1);
            ibmmqConnectionFactory.setStringProperty("XMSC_WMQ_QUEUE_MANAGER", config.queueManager);
            ibmmqConnectionFactory.setStringProperty("XMSC_WMQ_PROVIDER_VERSION", "unspecified");
            ibmmqConnectionFactory.setIntProperty("XMSC_WMQ_CLIENT_RECONNECT_OPTIONS", 33554432);
            ibmmqConnectionFactory.setIntProperty("XMSC_WMQ_CLIENT_RECONNECT_TIMEOUT", 500);
            if (config.ssl) {
                _logger.info("IBM lib determined cipherspec: {}, ciphersuite: {}", JmqiUtils.toCipherSpec(config.ciphersuite), JmqiUtils.toCipherSuite(config.ciphersuite));
                SslFactoryPreparer sslFactoryPreparer = new SslFactoryPreparer();
                ibmmqConnectionFactory.setBooleanProperty("XMSC_WMQ_SSL_FIPS_REQUIRED", false);
                ibmmqConnectionFactory.setStringProperty("XMSC_WMQ_SSL_CIPHER_SUITE", config.ciphersuite);
                ibmmqConnectionFactory.setObjectProperty("XMSC_WMQ_SSL_SOCKET_FACTORY", sslFactoryPreparer.getSslSocketFactory(config));
                if (StringUtils.isNotEmpty(config.sslPeerName)) {
                    ibmmqConnectionFactory.setStringProperty("XMSC_WMQ_SSL_PEER_NAME", config.sslPeerName);
                }
            }

            return new IbmMqConnectionFactory(ibmmqConnectionFactory);
        } catch (Exception var5) {
            _logger.error(var5.getMessage(), var5);
            return null;
        }
    }
}

@lburgazzoli
Copy link
Contributor

I need to digg into it more, can you share a reproducer ? without the ibm bits of course

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Just edited the two producers we use in the last comment, if it helps.

@lburgazzoli
Copy link
Contributor

can you create a sample reproducer and share it on github ? that would help a lot

@bframke
Copy link
Author

bframke commented Nov 25, 2019

Created an example without IBM MQ usage. quarkusBuild is the fastest way to directly do a first test, after importing the project.

https://github.com/bframke/quarkus-examples

dir: camel-producer

@lburgazzoli
Copy link
Contributor

I've cleaned it up and shrink-ed it to a bare minimum to reduce complexity: https://github.com/lburgazzoli/bframke-quarkus-examples/tree/cleanup/camel-producer

To create connection factories, the best is to use CDI instead of putting things directly to the camel registry which is possible but should be done before routes are started otherwise registry elements can't be found.

@bframke
Copy link
Author

bframke commented Nov 26, 2019

Okay, your example is just for one ConnectionFactory, we create several with this key:value map. Question here is, after reading through the CDI stuff, how to correctly implement it? We use the registry in the configure phase and add the routes in before start.

Just injecting the example from you is already enough in that case or is there more to be done?

@lburgazzoli
Copy link
Contributor

I made it simpler because the example was not working out of the box so I did try to check that things are working as expected.

In your code, the main problem is that CamelMainEvents.Configure happens after CamelMainEvents.BeforeStart so when routes are created they may not find the beans they are looking for (in this case the connection factories).

@bframke
Copy link
Author

bframke commented Nov 26, 2019

Ah, so the AfterStart would be the better case?

@lburgazzoli
Copy link
Contributor

You should do it in CamelMainEvents.BeforeStart

@bframke
Copy link
Author

bframke commented Nov 26, 2019

Ah...darn events, thanks. Now it works. Was a bit confusing after we had to change the used events in the newer version. Factories are now registered correctly and the same is for the routes.

Thanks for the help in this problem.

@lburgazzoli
Copy link
Contributor

can we close this ?

@bframke
Copy link
Author

bframke commented Nov 26, 2019

Yes.

@bframke bframke closed this as completed Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants