3

I am facing an issue, while trying to create a javax.jms.ConnectionFactory resource in TomEE server. i am using tomee.xml file to do write the resource entries.

I am able to create javax.jms.Queue and Topic but not this. Getting an error while TomEE startup, when i try to create a JMS ConnectionFactory resource.

Giving below my tomee.xml file. I referred the Apache TomEE documentation for this. As per documentation i should be able to create this resource.

<?xml version="1.0" encoding="UTF-8"?>
<tomee>
  <!-- see http://tomee.apache.org/containers-and-resources.html -->

  <!-- activate next line to be able to deploy applications in apps -->
  <!-- <Deployments dir="apps" /> -->
  <Resource id="Foo" type="javax.jms.ConnectionFactory">
    ResourceAdapter = Default JMS Resource Adapter
    TransactionSupport = xa
    PoolMaxSize = 10
    PoolMinSize = 0
    ConnectionMaxWaitTime = 5 seconds
    ConnectionMaxIdleTime = 15 Minutes
 </Resource>

</tomee>
e, provider-id=Tomcat Security Service)
10-May-2019 11:15:36.532 INFO [main] org.apache.openejb.config.ConfigurationFactory.configureService Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
10-May-2019 11:15:36.536 INFO [main] org.apache.openejb.config.ConfigurationFactory.configureService Configuring Service(id=Foo, type=Resource, provider-id=Default JMS Connection Factory)
10-May-2019 11:15:36.544 INFO [main] org.apache.openejb.util.OptionsLog.info Using 'openejb.deployments.classpath=false'
10-May-2019 11:15:36.600 INFO [main] org.apache.openejb.assembler.classic.Assembler.createRecipe Creating TransactionManager(id=Default Transaction Manager)
10-May-2019 11:15:36.864 INFO [main] org.apache.openejb.assembler.classic.Assembler.createRecipe Creating SecurityService(id=Tomcat Security Service)
10-May-2019 11:15:37.484 INFO [main] org.apache.openejb.assembler.classic.Assembler.createRecipe Creating Resource(id=Foo)
10-May-2019 11:15:37.520 SEVERE [main] org.apache.openejb.OpenEJB$Instance.<init> OpenEJB has encountered a fatal error and cannot be started: Assembler failed to build the container system.
 org.apache.openejb.OpenEJBException: No existing resource adapter defined with id 'Default JMS Resource Adapter'.
        at org.apache.openejb.assembler.classic.Assembler.replaceResourceAdapterProperty(Assembler.java:2942)
        at org.apache.openejb.assembler.classic.Assembler.doCreateResource(Assembler.java:3108)
        at org.apache.openejb.assembler.classic.Assembler.createResource(Assembler.java:2966)
        at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:586)
        at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:487)
        at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:150)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:307)
        at org.apache.tomee.catalina.TomcatLoader.initialize(TomcatLoader.java:247)
        at org.apache.tomee.catalina.ServerListener.lifecycleEvent(ServerListener.java:168)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
        at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:395)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:108)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:632)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:655)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:309)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)

10-May-2019 11:15:37.524 SEVERE [main] org.apache.tomee.catalina.ServerListener.lifecycleEvent TomEE Listener can't start OpenEJB
 org.apache.openejb.OpenEJBException: No existing resource adapter defined with id 'Default JMS Resource Adapter'.
        at org.apache.openejb.assembler.classic.Assembler.replaceResourceAdapterProperty(Assembler.java:2942)
        at org.apache.openejb.assembler.classic.Assembler.doCreateResource(Assembler.java:3108)
        at org.apache.openejb.assembler.classic.Assembler.createResource(Assembler.java:2966)
        at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:586)
        at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:487)
        at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:150)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:307)
        at org.apache.tomee.catalina.TomcatLoader.initialize(TomcatLoader.java:247)
        at org.apache.tomee.catalina.ServerListener.lifecycleEvent(ServerListener.java:168)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
        at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:395)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:108)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:632)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:655)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:309)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)

10-May-2019 11:15:37.576 INFO [main] jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke Initialization processed in 8796 ms
10-May-2019 11:15:37.788 INFO [main] jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke Starting service [Catalina]
10-May-2019 11:15:37.788 INFO [main] jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke Starting Servlet Engine: Apache Tomcat/8.5.32
10-May-2019 11:15:37.816 INFO [localhost-startStop-1] jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke Deploying web application directory [D:\servers_\apache-tomee-7.1.0-plus\apache-tomee-plus-7.1.0\webapps\docs]
10-May-2019 11:15:37.848 INFO [localhost-startStop-1] org.apache.tomee.catalina.TomcatWebAppBuilder.init ------------------------- localhost -> /docs
WARNING: An illegal reflective access operation has occurred

I really appreciate any help related to this. I am stuck! Thanks in advance.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
Jishnu S
  • 71
  • 7

2 Answers2

4

The configuration you are using (as given in your question)

ConnectionMaxWaitTime = 5 seconds
ConnectionMaxIdleTime = 15 Minutes

is invalid not clearly documented.

According to the documentation under subsection Resources/javax.jms.ConnectionFactory those two parameters should read as follows:

ConnectionMaxWaitMilliseconds = 5000
ConnectionMaxIdleMinutes = 15

Note the different property names and the values (without units). Try to adjust it in your tomee.xml and restart your setup.

EDIT

The pre-final TomEE 8 documentation suggests that your setup might be valid for newer versions. Yet, it seems that this is either "misleading", a bug in the example, or this syntax only works for TomEE releases >= 8.x (e.g., 8.0.0-M2). You might want to test/verify the previous form which I refer to in the original part of the answer and report whether this works as expected.

EDIT-2

I got it working for the following configuration in tomee.xml in TomEE 7.1.0 and TomEE-8.0.0-M2:

<Resource id="myCustomizedJmsConnectionFactory" type="javax.jms.ConnectionFactory">
    connectionMaxWaitMilliseconds = 5000
    connectionMaxIdleMinutes = 15
    poolMaxSize = 10
    poolMinSize = 0
    resourceAdapter = Default JMS Resource Adapter
    transactionSupport = xa
</Resource>

<Resource id="Default JMS Resource Adapter" type="ActiveMQResourceAdapter">
    BrokerXmlConfig = broker:(tcp://localhost:61616)?persistent=true
    ServerUrl = tcp://localhost:61616
    DataSource = MyDataSource
</Resource>

In which you would have to change MyDataSource into your local data source (name).

Sadly, the current documentation is not entirely clear about the fact that you have to specify

<Resource id="Default JMS Resource Adapter" type="ActiveMQResourceAdapter">... 

for yourself. For reference and for more (configuration) details, I'd like to point you to this post as well.

Hope it helps.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
  • Thank you for your answer. The example you given above worked for me too. But that starts an activemq embedded broker. I do not want that. I just want to bring up the javax.jms.ConnectionFactory resource and consume it. This is possible with weblogic. Also i can give it a try with the props you mentioned. Not sure of that helps. – Jishnu S May 19 '19 at 19:48
  • Also, one more thing i noticed with tomee is that, i brought up a DataSource resource and i am trying to consume it remotely. But the initialcontext.lookup() gives an exception at the client program. Error is : **java.lang.ClassCastException: apache.openejb.client.ThrowableArtifact cannot be cast to java.lang.Error** i believe this is a bug. Tomee is disappointing. I am planing to post this also as a qstn. Since both the questions are related just asking it here kn case anyone knows the solution. – Jishnu S May 19 '19 at 19:57
  • If it helped you, you might consider an upvote for my answer. If you think you found a bug, you could also open a bug within the TomEE Jira (issue tracker) so it gets fixed within the next release(s). – MWiesner May 19 '19 at 21:53
  • it was helpful, but like i said, this doesnt fit my requirement, i do not want embedded ActiveMQ. only jms.ConnectionFactory i need to consume. – Jishnu S May 20 '19 at 18:01
  • I know, you explained that. But: what can I do if the current TomEE isn‘t capable of handling this situation without a defined *Default JMS Resource Adapter*? You can redefine the example to whatever you like it to be. The above snippet is just an example config on how I got things started. – MWiesner May 20 '19 at 18:07
  • okay. i will try something out, with this information. thank you for your help. also I could not up vote because i am beginner in stackoverflow. i am not yet eligible i suppose. – Jishnu S May 20 '19 at 18:19
  • Now you should be able to do so. – MWiesner May 20 '19 at 18:26
0

You should integrate tomee with activemq. There are two work forms: 1) with activemq embedded or 2) with independent activemq

Example: With activemq embedded (file tomee.xml)

 <?xml version="1.0" encoding="UTF-8"?>
<tomee>
  <!-- see http://tomee.apache.org/containers-and-resources.html -->

  <!-- activate next line to be able to deploy applications in apps -->
  <!-- <Deployments dir="apps" /> -->
  

    <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        BrokerXmlConfig  =broker:(tcp://localhost:61616)
        ServerUrl = tcp://localhost:61616
    </Resource>

    <Resource id="MyJmsConnectionFactory" type="javax.jms.ConnectionFactory">
        ResourceAdapter = MyJmsResourceAdapter
    </Resource>

    <Container id="MyJmsMdbContainer" ctype="MESSAGE">
        ResourceAdapter = MyJmsResourceAdapter
    </Container>

    <Resource id="MyQueue" type="javax.jms.Queue"/>

</tomee>

with independent activemq

<?xml version="1.0" encoding="UTF-8"?>
    <tomee>
      <!-- see http://tomee.apache.org/containers-and-resources.html -->
    
      <!-- activate next line to be able to deploy applications in apps -->
      <!-- <Deployments dir="apps" /> -->
      
    
        <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
            # Do not start the embedded ActiveMQ broker
            BrokerXmlConfig  =
            ServerUrl = tcp://localhost:61616
        </Resource>
    
        <Resource id="MyJmsConnectionFactory" type="javax.jms.ConnectionFactory">
            ResourceAdapter = MyJmsResourceAdapter
        </Resource>
    
        <Container id="MyJmsMdbContainer" ctype="MESSAGE">
            ResourceAdapter = MyJmsResourceAdapter
        </Container>
    
        <Resource id="MyQueue" type="javax.jms.Queue"/>
    
    </tomee>