How to set user/password with JMS pooling

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to set user/password with JMS pooling

Karl Cassaigne
Hi,

I'm building an application base on Tomcat 5.5 + Spring 2.0 + MySQL 4.1 + SwiftMQ 7.0 and I'm facing the following issue : I found no way to set the user/password info in order to have correctly setup connexion in the JMS connection pool.

Here's my spring config (for the JMS part) :

        <bean id="jmsDataSource" class="bitronix.tm.resource.jms.PoolingConnectionFactory" init-method="init" destroy-method="close">
                <property name="className" value="bitronix.tm.resource.jms.JndiXAConnectionFactory" />
                <property name="uniqueName" value="swiftmq" />
                <property name="minPoolSize" value="1" />
                <property name="maxPoolSize" value="${jms.pool.size}" />
                <property name="allowLocalTransactions" value="true" />
                <property name="driverProperties">
                        <props>
                                <prop key="name">plainsocket@router_mcto_dev</prop>
                                <prop key="initialContextFactory">com.swiftmq.jndi.InitialContextFactoryImpl</prop>
                                <prop key="providerUrl">smqp://mcto:afs@localhost:4001/timeout=30000</prop>
                        </props>
                </property>
        </bean>       

As you can see I tried passing these info on the URL with no success. Is there another way to do that ?

As a side note, I migrated from Atomikos to BTM with great success mainly for the following advantages :
- complete JMS & JDBC connection pooling (no more killed MySQL connection to bother with)
- full spring configuration compliant
- log4j logging support

This is a very good product !
Thanks,
Karl
Reply | Threaded
Open this post in threaded view
|

Re: How to set user/password with JMS pooling

Ludovic Orban
Administrator
Hi Karl,

If you have configured a login/password for SwiftMQ connections, according to their documentation (http://www.swiftmq.com/products/router/swiftlets/sys_jndi/introduction/index.html) encoding them in the URL should work.

If you need a username/password to access SwiftMQ's JNDI implementation, check the JndiXAConnectionFactory javadoc: http://btm.codehaus.org/api/bitronix/tm/resource/jms/JndiXAConnectionFactory.html

which basically would translate to something like this in your case:

<property name="driverProperties">
        <props>
                <prop key="name">plainsocket@router_mcto_dev</prop>
                <prop key="initialContextFactory">com.swiftmq.jndi.InitialContextFactoryImpl</prop>
                <prop key="providerUrl">smqp://mcto:afs@localhost:4001/timeout=30000</prop>
                <prop key="securityPrincipal">mcto</prop>
                <prop key="securityCredentials">asf</prop>
        </props>
</property>

I agree that's not very clear in the wiki, I'll add some more information about that.


Let me know if that helped. If not, please answer back and include a full stack trace of the exception you get.

Ludovic

Karl Cassaigne wrote
Hi,

I'm building an application base on Tomcat 5.5 + Spring 2.0 + MySQL 4.1 + SwiftMQ 7.0 and I'm facing the following issue : I found no way to set the user/password info in order to have correctly setup connexion in the JMS connection pool.

Here's my spring config (for the JMS part) :

        <bean id="jmsDataSource" class="bitronix.tm.resource.jms.PoolingConnectionFactory" init-method="init" destroy-method="close">
                <property name="className" value="bitronix.tm.resource.jms.JndiXAConnectionFactory" />
                <property name="uniqueName" value="swiftmq" />
                <property name="minPoolSize" value="1" />
                <property name="maxPoolSize" value="${jms.pool.size}" />
                <property name="allowLocalTransactions" value="true" />
                <property name="driverProperties">
                        <props>
                                <prop key="name">plainsocket@router_mcto_dev</prop>
                                <prop key="initialContextFactory">com.swiftmq.jndi.InitialContextFactoryImpl</prop>
                                <prop key="providerUrl">smqp://mcto:afs@localhost:4001/timeout=30000</prop>
                        </props>
                </property>
        </bean>       

As you can see I tried passing these info on the URL with no success. Is there another way to do that ?

As a side note, I migrated from Atomikos to BTM with great success mainly for the following advantages :
- complete JMS & JDBC connection pooling (no more killed MySQL connection to bother with)
- full spring configuration compliant
- log4j logging support

This is a very good product !
Thanks,
Karl
Reply | Threaded
Open this post in threaded view
|

Re: How to set user/password with JMS pooling

Karl Cassaigne
Hi Ludovic and thanks for the fast answer !

I need a login/password for SwiftMQ connections and I followed their documentation but unfortunately this does not seem to work (I will post a message about this on the SwiftMQ forum).

BTW, don't you think it could be useful to have optional login and password properties on the JndiXAConnectionFactory object of BTM to handle such case ? These info would then be passed to the CreateConnection() method before it is put into the pool by the PoolingConnectionFactory object.

Something else puzzled me while using BTM : at INFO log level, I only got a trace on startup and another one on shutdown while in DEBUG log level I obtain the full internal thing.

I would have expected more traces in INFO log level, at least the main transaction states (new, prepare, commit/rollback, ...) so that it could be possible to check for good transactionnal processing without having to digg inside hundreds of traces !

The current INFO log level traces are what I would have expected at WARN log level (with some sort of INFO prefix to differentiate those traces from true WARN traces) which is perfectly suited for production environnement.

Regards,
Karl

Ludovic Orban wrote
Hi Karl,

If you have configured a login/password for SwiftMQ connections, according to their documentation (http://www.swiftmq.com/products/router/swiftlets/sys_jndi/introduction/index.html) encoding them in the URL should work.

If you need a username/password to access SwiftMQ's JNDI implementation, check the JndiXAConnectionFactory javadoc: http://btm.codehaus.org/api/bitronix/tm/resource/jms/JndiXAConnectionFactory.html

which basically would translate to something like this in your case:

<property name="driverProperties">
        <props>
                <prop key="name">plainsocket@router_mcto_dev</prop>
                <prop key="initialContextFactory">com.swiftmq.jndi.InitialContextFactoryImpl</prop>
                <prop key="providerUrl">smqp://mcto:afs@localhost:4001/timeout=30000</prop>
                <prop key="securityPrincipal">mcto</prop>
                <prop key="securityCredentials">asf</prop>
        </props>
</property>

I agree that's not very clear in the wiki, I'll add some more information about that.


Let me know if that helped. If not, please answer back and include a full stack trace of the exception you get.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: How to set user/password with JMS pooling

Ludovic Orban
Administrator
Hi Karl,

About login/password: this is possible but requires a small change in BTM's PoolingConnectionFactory in method createPooledConnection() at line 202.

You just have to change this line:
  return new JmsPooledConnection(this, xaConnectionFactory.createXAConnection());

with that one:
  return new JmsPooledConnection(this, xaConnectionFactory.createXAConnection("user", "password"));

That will hardcode your credentials in BTM's code but if that works for you I will generalize the code and add it in version 1.2.


About logging: everybody seems to have his own view of what should be logged at which level. I personally tend to think that INFO should only log things that are always worth reading. This means keeping INFO statements to a strict minimum if I do not want administrators to be flooded and ignore those messages.

If you need to know how your transactions are  going, just set to DEBUG the bitronix.tm.twopc category. Unless you can propose me a better design that what's currently in place (and convince me) I won't change my mind on this.

Ludovic

Karl Cassaigne wrote
Hi Ludovic and thanks for the fast answer !

I need a login/password for SwiftMQ connections and I followed their documentation but unfortunately this does not seem to work (I will post a message about this on the SwiftMQ forum).

BTW, don't you think it could be useful to have optional login and password properties on the JndiXAConnectionFactory object of BTM to handle such case ? These info would then be passed to the CreateConnection() method before it is put into the pool by the PoolingConnectionFactory object.

Something else puzzled me while using BTM : at INFO log level, I only got a trace on startup and another one on shutdown while in DEBUG log level I obtain the full internal thing.

I would have expected more traces in INFO log level, at least the main transaction states (new, prepare, commit/rollback, ...) so that it could be possible to check for good transactionnal processing without having to digg inside hundreds of traces !

The current INFO log level traces are what I would have expected at WARN log level (with some sort of INFO prefix to differentiate those traces from true WARN traces) which is perfectly suited for production environnement.

Regards,
Karl

Ludovic Orban wrote
Hi Karl,

If you have configured a login/password for SwiftMQ connections, according to their documentation (http://www.swiftmq.com/products/router/swiftlets/sys_jndi/introduction/index.html) encoding them in the URL should work.

If you need a username/password to access SwiftMQ's JNDI implementation, check the JndiXAConnectionFactory javadoc: http://btm.codehaus.org/api/bitronix/tm/resource/jms/JndiXAConnectionFactory.html

which basically would translate to something like this in your case:

<property name="driverProperties">
        <props>
                <prop key="name">plainsocket@router_mcto_dev</prop>
                <prop key="initialContextFactory">com.swiftmq.jndi.InitialContextFactoryImpl</prop>
                <prop key="providerUrl">smqp://mcto:afs@localhost:4001/timeout=30000</prop>
                <prop key="securityPrincipal">mcto</prop>
                <prop key="securityCredentials">asf</prop>
        </props>
</property>

I agree that's not very clear in the wiki, I'll add some more information about that.


Let me know if that helped. If not, please answer back and include a full stack trace of the exception you get.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: How to set user/password with JMS pooling

Karl Cassaigne
Hi again,

I'll probably do the change into BTM's PoolingConnectionFactory code so that it can work for me; your proposal of including it in the next version is indeed welcome ;-)

I understand your point about logging; I'll try your DEBUG log settings.

Karl
Ludovic Orban wrote
Hi Karl,

About login/password: this is possible but requires a small change in BTM's PoolingConnectionFactory in method createPooledConnection() at line 202.

You just have to change this line:
  return new JmsPooledConnection(this, xaConnectionFactory.createXAConnection());

with that one:
  return new JmsPooledConnection(this, xaConnectionFactory.createXAConnection("user", "password"));

That will hardcode your credentials in BTM's code but if that works for you I will generalize the code and add it in version 1.2.


About logging: everybody seems to have his own view of what should be logged at which level. I personally tend to think that INFO should only log things that are always worth reading. This means keeping INFO statements to a strict minimum if I do not want administrators to be flooded and ignore those messages.

If you need to know how your transactions are  going, just set to DEBUG the bitronix.tm.twopc category. Unless you can propose me a better design that what's currently in place (and convince me) I won't change my mind on this.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: How to set user/password with JMS pooling

Karl Cassaigne
Hi Ludovic,

Just a little post to tell you I have tested the debug configuration you suggested and it's exactly what I wanted to see in the logs.

I also implemented the JMS login/password feature by adding a "userName" & "password" fields into the ResourceBean class and a call to xaConnectionFactory.createXAConnection(getUserName(), getPassword()) in the PoolingConnectionFactory class in case both fields are not null.

I would really appreciate if you would be kind enough to implement this feature the way that suits you most in the next version of BTM because, IMHO, this is a needed feature to handle JMS security as it already exists for the JDBC part.

Thanks,
Karl

Karl Cassaigne wrote
Hi again,

I'll probably do the change into BTM's PoolingConnectionFactory code so that it can work for me; your proposal of including it in the next version is indeed welcome ;-)

I understand your point about logging; I'll try your DEBUG log settings.

Karl
Ludovic Orban wrote
Hi Karl,

About login/password: this is possible but requires a small change in BTM's PoolingConnectionFactory in method createPooledConnection() at line 202.

You just have to change this line:
  return new JmsPooledConnection(this, xaConnectionFactory.createXAConnection());

with that one:
  return new JmsPooledConnection(this, xaConnectionFactory.createXAConnection("user", "password"));

That will hardcode your credentials in BTM's code but if that works for you I will generalize the code and add it in version 1.2.


About logging: everybody seems to have his own view of what should be logged at which level. I personally tend to think that INFO should only log things that are always worth reading. This means keeping INFO statements to a strict minimum if I do not want administrators to be flooded and ignore those messages.

If you need to know how your transactions are  going, just set to DEBUG the bitronix.tm.twopc category. Unless you can propose me a better design that what's currently in place (and convince me) I won't change my mind on this.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: How to set user/password with JMS pooling

Ludovic Orban
Administrator
Hi Karl,

This feature will make its way into the 1.2 release and I've added it to the release notes to make sure I won't forget:

 http://docs.codehaus.org/display/BTM/Roadmap

Thanks for the feedback.
Ludovic