Resource adapter - Connection - Pooling parameters

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Resource adapter - Connection - Pooling parameters

jeankst
This post was updated on .
Hi all,

We moving from Weblogic to TomEE and deploying a RAR within an EAR.
Here is what I got to work:

In ra.xml:

  <resourceadapter id="MyResourceAdapter"> 
    <resourceadapter-class>foo.bar.MyResourceAdapter</resourceadapter-class> 
    <outbound-resourceadapter> 
      <connection-definition id="MyConnectionFactory1"> 
       
<managedconnectionfactory-class>foo.bar.ManagedConnectionFactory</managedconnectionfactory-class> 
        <config-property> 
          <config-property-name>ServerName</config-property-name> 
          <config-property-type>java.lang.String</config-property-type> 
          <config-property-value>server001</config-property-value> 
        </config-property> 
        ...
      </connection-definition> 
      <connection-definition id="MyConnectionFactory2"> 
       
<managedconnectionfactory-class>foo.bar.ManagedConnectionFactory</managedconnectionfactory-class> 
        <config-property> 
          <config-property-name>ServerName</config-property-name> 
          <config-property-type>java.lang.String</config-property-type> 
          <config-property-value>server002</config-property-value> 
        </config-property> 
        ...
      </connection-definition> 
      ...        
    </outbound-resourceadapter> 
  </resourceadapter> 

On TomEE startup, in the logs, I can see:

  INFO [main]
org.apache.openejb.config.ConfigurationFactory.configureService Configuring
Service(id=MyResourceAdapter, type=Resource, provider-id=MyResourceAdapter)
  INFO [main]
org.apache.openejb.config.ConfigurationFactory.configureService Configuring
Service(id=MyConnectionFactory1, type=Resource,
provider-id=MyConnectionFactory1)
  INFO [main]
org.apache.openejb.config.ConfigurationFactory.configureService Configuring
Service(id=MyConnectionFactory2, type=Resource,
provider-id=MyConnectionFactory2)
 
So in a container managed bean, I use:

  @Resource(name = "MyConnectionFactory1", authenticationType =
Resource.AuthenticationType.APPLICATION, shareable = true)
  private ConnectionFactory myFirstConnectionFactory;

  @Resource(name = "MyConnectionFactory2", authenticationType =
Resource.AuthenticationType.APPLICATION, shareable = true)
  private ConnectionFactory mySecondConnectionFactory;

In /conf/system.properties, I set pooling parameters as:

  MyResourceAdapter.threadPoolSize=7

  MyConnectionFactory1.pooling=true
  MyConnectionFactory1.poolMinSize=0
  MyConnectionFactory1.poolMaxSize=3
  MyConnectionFactory1.connectionMaxWaitTime=3 seconds
  MyConnectionFactory1.connectionMaxIdleTime=1 minutes

  MyConnectionFactory2.pooling=true
  MyConnectionFactory2.poolMinSize=1
  MyConnectionFactory2.poolMaxSize=2
  MyConnectionFactory2.connectionMaxWaitTime=5 seconds
  MyConnectionFactory2.connectionMaxIdleTime=10 seconds

So what I understood so far:

  - For Weblogic only a connection-definition is in ra.xml and
connection-instance(s) are in weblogic-ra.xml with the actual parameters and
pooling settings
  - For TomEE all connections (and their parameters) are defined in the sole
ra.xml; pooling (pooling=true by default) is however set in
system.properties

Questions:

  Is there a way do have those parameters embedded in the application EAR?
(instead of having to change the system.properties of the TomEE instance)
  Is this possible using a resources.xml file? if so, what would be the
syntax to use according to the sample above?

Thanks,
Jean.




--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Reply | Threaded
Open this post in threaded view
|

Re: Resource adapter - Connection - Pooling parameters

jgallimore
If you're deploying a rar in an EAR file, then I believe you need to use
system.properties to provide these settings, as TomEE will create the
resources based on what is in the Rar's ra.xml.

Another option is to include the jars from the rar directly in the ear
file, and then you can define the resources for the connection factory etc
in resources.xml.

I'll dig out an example in about an hour's time.

It would be a cool feature enhancement to be able to configure these
resources defined in the rar from resources.xml. I'll see if I can provide
that enhancement. I won't be able to do it straight away as my schedule is
a bit full - possibly next week. Alternatively, I'm happy to give some
pointers if someone else wants to have a go.

I'm not sure if you can specify system properties within your app - I'll
check.

Jon

On 9 Mar 2018 18:40, "jeankst" <[hidden email]> wrote:

> Hi all,
>
> We moving from Weblogic to TomEE and deploying with a RAR within an EAR.
> Here is what I got to work:
>
> In ra.xml:
>
>   <resourceadapter id="MyResourceAdapter">
>     <resourceadapter-class>foo.bar.MyResourceAdapter</
> resourceadapter-class>
>     <outbound-resourceadapter>
>       <connection-definition id="MyConnectionFactory1">
>
> <managedconnectionfactory-class>foo.bar.ManagedConnectionFactory</
> managedconnectionfactory-class>
>         <config-property>
>           <config-property-name>ServerName</config-property-name>
>           <config-property-type>java.lang.String</config-property-type>
>           <config-property-value>server001</config-property-value>
>         </config-property>
>         ...
>       </connection-definition>
>       <connection-definition id="MyConnectionFactory2">
>
> <managedconnectionfactory-class>foo.bar.ManagedConnectionFactory</
> managedconnectionfactory-class>
>         <config-property>
>           <config-property-name>ServerName</config-property-name>
>           <config-property-type>java.lang.String</config-property-type>
>           <config-property-value>server002</config-property-value>
>         </config-property>
>         ...
>       </connection-definition>
>       ...
>     </outbound-resourceadapter>
>   </resourceadapter>
>
> On TomEE startup, in the logs, I can see:
>
>   INFO [main]
> org.apache.openejb.config.ConfigurationFactory.configureService
> Configuring
> Service(id=MyResourceAdapter, type=Resource, provider-id=MyResourceAdapter)
>   INFO [main]
> org.apache.openejb.config.ConfigurationFactory.configureService
> Configuring
> Service(id=MyConnectionFactory1, type=Resource,
> provider-id=MyConnectionFactory1)
>   INFO [main]
> org.apache.openejb.config.ConfigurationFactory.configureService
> Configuring
> Service(id=MyConnectionFactory2, type=Resource,
> provider-id=MyConnectionFactory2)
>
> So in a container managed bean, I use:
>
>   @Resource(name = "MyConnectionFactory1", authenticationType =
> Resource.AuthenticationType.APPLICATION, shareable = true)
>   private ConnectionFactory myFirstConnectionFactory;
>
>   @Resource(name = "MyConnectionFactory2", authenticationType =
> Resource.AuthenticationType.APPLICATION, shareable = true)
>   private ConnectionFactory mySecondConnectionFactory;
>
> In /conf/system.properties, I set pooling parameters as:
>
>   MyResourceAdapter.threadPoolSize=7
>
>   MyConnectionFactory1.pooling=true
>   MyConnectionFactory1.poolMinSize=0
>   MyConnectionFactory1.poolMaxSize=3
>   MyConnectionFactory1.connectionMaxWaitTime=3 seconds
>   MyConnectionFactory1.connectionMaxIdleTime=1 minutes
>
>   MyConnectionFactory2.pooling=true
>   MyConnectionFactory2.poolMinSize=1
>   MyConnectionFactory2.poolMaxSize=2
>   MyConnectionFactory2.connectionMaxWaitTime=5 seconds
>   MyConnectionFactory2.connectionMaxIdleTime=10 seconds
>
> So what I understood so far:
>
>   - For Weblogic only a connection-definition is in ra.xml and
> connection-instance(s) are in weblogic-ra.xml with the actual parameters
> and
> pooling settings
>   - For TomEE all connections (and their parameters) are defined in the
> sole
> ra.xml; pooling (pooling=true by default) is however set in
> system.properties
>
> Questions:
>
>   Is there a way do have those parameters embedded in the application EAR?
> (instead of having to change the system.properties of the TomEE instance)
>   Is this possible using a resources.xml file? if so, what would be the
> syntax to use according to the sample above?
>
> Thanks,
> Jean.
>
>
>
>
> --
> Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-
> f979441.html
>
Reply | Threaded
Open this post in threaded view
|

Re: Resource adapter - Connection - Pooling parameters

jgallimore
As promised, here's a sample of a config in resources.xml for Websphere MQ.
When configuring the resources in this way, don't deploy the .rar in the
.ear file, just include the .jars from the .rar in the ear lib.

You can find the appropriate class names and attributes by looking at the
ra.xml file for your resource adapter. Note that you need
the ResourceAdapter=<Your Resource Adapter ID> attribute for MDB containers
and connection factories.

<resources>
    <Resource id="WMQResourceAdapter"
class-name="com.ibm.mq.connector.ResourceAdapterImpl">
        connectionConcurrency=1
        maxConnections=500
....
    </Resource>

    <Container id="WMQMDBContainer" ctype="MESSAGE">
        ResourceAdapter=WMQResourceAdapter
        ActivationSpecClass=com.ibm.mq.connector.inbound.ActivationSpecImpl
        pool = true
        StrictPooling=true
        MinSize=0
        MaxSize=20
        MessageListenerInterface=javax.jms.MessageListener
        activation.hostName=localhost
        activation.port=14141
....
    </Container>

    <Resource id="WMQConnectionFactory" type="javax.jms.ConnectionFactory"
class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl">
        TransactionSupport=xa
        ResourceAdapter=WMQResourceAdapter
        maxConnections=500
        hostName=localhost
        port=14141
....
    </Resource>

    <Resource id="wmqReceiver" type="javax.jms.Queue"
class-name="com.ibm.mq.connector.outbound.MQQueueProxy"
constructor="queueName">
        SkipImplicitAttributes=true
        queueName=wmqReceiver
        putAsyncAllowed=DISABLED
        XMSC_CONNECTION_TYPE_NAME=com.ibm.msg.client.wmq
    </Resource>
</resources>

Hope that helps, but shout if you have any questions.

Jon

On Fri, Mar 9, 2018 at 7:05 PM, Jonathan Gallimore <
[hidden email]> wrote:

> If you're deploying a rar in an EAR file, then I believe you need to use
> system.properties to provide these settings, as TomEE will create the
> resources based on what is in the Rar's ra.xml.
>
> Another option is to include the jars from the rar directly in the ear
> file, and then you can define the resources for the connection factory etc
> in resources.xml.
>
> I'll dig out an example in about an hour's time.
>
> It would be a cool feature enhancement to be able to configure these
> resources defined in the rar from resources.xml. I'll see if I can provide
> that enhancement. I won't be able to do it straight away as my schedule is
> a bit full - possibly next week. Alternatively, I'm happy to give some
> pointers if someone else wants to have a go.
>
> I'm not sure if you can specify system properties within your app - I'll
> check.
>
> Jon
>
> On 9 Mar 2018 18:40, "jeankst" <[hidden email]> wrote:
>
>> Hi all,
>>
>> We moving from Weblogic to TomEE and deploying with a RAR within an EAR.
>> Here is what I got to work:
>>
>> In ra.xml:
>>
>>   <resourceadapter id="MyResourceAdapter">
>>     <resourceadapter-class>foo.bar.MyResourceAdapter</resourcead
>> apter-class>
>>     <outbound-resourceadapter>
>>       <connection-definition id="MyConnectionFactory1">
>>
>> <managedconnectionfactory-class>foo.bar.ManagedConnectionFac
>> tory</managedconnectionfactory-class>
>>         <config-property>
>>           <config-property-name>ServerName</config-property-name>
>>           <config-property-type>java.lang.String</config-property-type>
>>           <config-property-value>server001</config-property-value>
>>         </config-property>
>>         ...
>>       </connection-definition>
>>       <connection-definition id="MyConnectionFactory2">
>>
>> <managedconnectionfactory-class>foo.bar.ManagedConnectionFac
>> tory</managedconnectionfactory-class>
>>         <config-property>
>>           <config-property-name>ServerName</config-property-name>
>>           <config-property-type>java.lang.String</config-property-type>
>>           <config-property-value>server002</config-property-value>
>>         </config-property>
>>         ...
>>       </connection-definition>
>>       ...
>>     </outbound-resourceadapter>
>>   </resourceadapter>
>>
>> On TomEE startup, in the logs, I can see:
>>
>>   INFO [main]
>> org.apache.openejb.config.ConfigurationFactory.configureService
>> Configuring
>> Service(id=MyResourceAdapter, type=Resource,
>> provider-id=MyResourceAdapter)
>>   INFO [main]
>> org.apache.openejb.config.ConfigurationFactory.configureService
>> Configuring
>> Service(id=MyConnectionFactory1, type=Resource,
>> provider-id=MyConnectionFactory1)
>>   INFO [main]
>> org.apache.openejb.config.ConfigurationFactory.configureService
>> Configuring
>> Service(id=MyConnectionFactory2, type=Resource,
>> provider-id=MyConnectionFactory2)
>>
>> So in a container managed bean, I use:
>>
>>   @Resource(name = "MyConnectionFactory1", authenticationType =
>> Resource.AuthenticationType.APPLICATION, shareable = true)
>>   private ConnectionFactory myFirstConnectionFactory;
>>
>>   @Resource(name = "MyConnectionFactory2", authenticationType =
>> Resource.AuthenticationType.APPLICATION, shareable = true)
>>   private ConnectionFactory mySecondConnectionFactory;
>>
>> In /conf/system.properties, I set pooling parameters as:
>>
>>   MyResourceAdapter.threadPoolSize=7
>>
>>   MyConnectionFactory1.pooling=true
>>   MyConnectionFactory1.poolMinSize=0
>>   MyConnectionFactory1.poolMaxSize=3
>>   MyConnectionFactory1.connectionMaxWaitTime=3 seconds
>>   MyConnectionFactory1.connectionMaxIdleTime=1 minutes
>>
>>   MyConnectionFactory2.pooling=true
>>   MyConnectionFactory2.poolMinSize=1
>>   MyConnectionFactory2.poolMaxSize=2
>>   MyConnectionFactory2.connectionMaxWaitTime=5 seconds
>>   MyConnectionFactory2.connectionMaxIdleTime=10 seconds
>>
>> So what I understood so far:
>>
>>   - For Weblogic only a connection-definition is in ra.xml and
>> connection-instance(s) are in weblogic-ra.xml with the actual parameters
>> and
>> pooling settings
>>   - For TomEE all connections (and their parameters) are defined in the
>> sole
>> ra.xml; pooling (pooling=true by default) is however set in
>> system.properties
>>
>> Questions:
>>
>>   Is there a way do have those parameters embedded in the application EAR?
>> (instead of having to change the system.properties of the TomEE instance)
>>   Is this possible using a resources.xml file? if so, what would be the
>> syntax to use according to the sample above?
>>
>> Thanks,
>> Jean.
>>
>>
>>
>>
>> --
>> Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f97944
>> 1.html
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Resource adapter - Connection - Pooling parameters

jeankst
Hi Jon,

I understand this is not a standard RA deployment anymore but rather a TomEE
specific way.
Anyway, I had a try and it works like a charm! Now, I can have this nice and
clean resources.xml embedded in my EAR:

    <resources>
      <Resource id="MyResourceAdapter"
class-name="foo.bar.MyResourceAdapter">
        threadPoolSize=7
      </Resource>
      <Resource id="MyConnectionFactory1"
type="javax.resource.cci.ConnectionFactory"
class-name="foo.bar.ManagedConnectionFactory">
        resourceAdapter=MyResourceAdapter
        transactionSupport=none
        serverName=server001
        pooling=true
        poolMaxSize=3
        poolMinSize=0
        connectionMaxWaitTime=3 seconds
        connectionMaxIdleTime=5 seconds
      </Resource>
      <Resource id="MyConnectionFactory2"
type="javax.resource.cci.ConnectionFactory"
class-name="foo.bar.ManagedConnectionFactory">
        resourceAdapter=MyResourceAdapter
        transactionSupport=none
        serverName=server002
        pooling=true
        poolMaxSize=2
        poolMinSize=1
        connectionMaxWaitTime=5 seconds
        connectionMaxIdleTime=10 seconds
      </Resource>
    </resources>

No more "hack" in system.properties!
As you said, it would be a cool feature to have this resources.xml support
for RARs.
Thanks for your help!

Regards,
Jean.



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html