You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Oli Kessler <ok...@ncode.ch> on 2006/03/18 01:09:33 UTC
JMS Connection Factory / JNDI Naming
Hello,
I'm trying to write a GBean that depends on a JMS configuration
initialized with a resource group configuration plan as indicated in the
book by Aaron Mulder on chariotsolutions.com.
The file contains a connection factory object named
"MyConnectionFactory" indicated in the connectiondefition-instance and a
topic called "MyTopic" (message-destination-name). When deployed, those
2 objects can be seen and verified in the web console.
Now, my GBean needs to publish to the topic "MyTopic" using a connection
from the factory object. How would I get the factory object in my code
with JNDI? Opposed to a web-application or EJB, I can not count on
configured resource references in web.xml or similar, right?
I tried the simple
(..)
InitialContext context = new InitialContext();
Object obj = context.lookup("MyConnectionFactory);
(..)
but this did not work out. Is there any prefix I should use?
Cheers,
Oli Kessler
--
ncode solutions gmbh
http://www.ncode.ch
tel +41 43 817 01 88
fax +41 43 817 02 88
Zurich / Switzerland
Re: JMS Connection Factory / JNDI Naming
Posted by Oli Kessler <ok...@ncode.ch>.
>
> At this point I look in var/log/geronimo.log and try to find the actual
> name the managed connection factory is deployed under.
>
> I suspect the problem is that you need
> <module>ncodeTopicConnectionFactory</module> in your reference, but I'm
> not entirely sure.
>
> hope this gets you farther :-)
> david jencks
Great stuff, David!
Using <module>ncodeTopicConnectionFactory</module>, I got the reference
right and the GBean aquires a TopicConnectionFactory through the
managedConnectionFactoryWrapper.
Thank you very much.
-ok
Re: JMS Connection Factory / JNDI Naming
Posted by David Jencks <da...@yahoo.com>.
On Mar 20, 2006, at 2:29 PM, Oli Kessler wrote:
>>
>
>> Jndi won't work within a gbean, you should use a gbean reference.
>> Here's an example from the system datasource plan, and the gbean
>> referenced can show you how to code it. The reference to emulate
>> here is ManagedConnectionFactoryWrapper
>>
>> <gbean name="NonTransactionalThreadPooledTimer"
>> class="org.apache.geronimo.timer.jdbc.JDBCStoreThreadPooledNonTransac
>> tio
>> nalTimer"> <reference
>> name="TransactionContextManager"><moduleType>J2EEModule</
>> moduleType><module>geronimo/j2ee-server/${pom.currentVersion}/car</
>> module><name>TransactionContextManager</name></reference> <reference
>> name="ManagedConnectionFactoryWrapper"><moduleType>JCAResource</
>> moduleType><name>SystemDatasource</name></reference> <reference
>> name="ThreadPool"><moduleType>J2EEModule</
>> moduleType><module>geronimo/j2ee-server/${pom.currentVersion}/car</
>> module><name>DefaultThreadPool</name></reference> <!--TODO remove
>> moduleType when gbeans get the moduleType of the plan they are in -->
>> <reference name="DerbySystem"><moduleType>J2EEModule</
>> moduleType><name>DerbySystem</name></reference> </gbean>
>>
>> thanks david jencks
>
> Thanks for your help, david. However I'm apparently still missing
> something..
>
> My connector information is:
>
> <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/
> connector-1.0"
> configId="ncodeTopicConnectionFactory"
> parentId="geronimo/activemq-broker/1.0/car">
> <resourceadapter>
> <resourceadapter-instance>
> <resourceadapter-name>ncodeJMS</resourceadapter-name>
> <config-property-setting name="ServerUrl">
> vm://localhost
> </config-property-setting>
> <config-property-setting name="UserName">not needed
> </config-property-setting>
> <config-property-setting name="Password">not needed
> </config-property-setting>
> <workmanager>
> <gbean-link>DefaultWorkManager</gbean-link>
> </workmanager>
> </resourceadapter-instance>
> <!-- defines a ConnectionFactory -->
> <outbound-resourceadapter>
> <connection-definition>
> <connectionfactory-interface>
> javax.jms.TopicConnectionFactory
> </connectionfactory-interface>
> <connectiondefinition-instance>
> <name>ncodeTopicConnectionFactory</name>
> <connectionmanager>
> <xa-transaction> <transaction-
> caching />
> </xa-transaction>
> <single-pool>
> <max-size>10</max-size> <min-size>0</min-
> size>
>
> <blocking-timeout-milliseconds>5000
> </blocking-timeout-milliseconds>
> <idle-timeout-minutes>0</idle-timeout-minutes>
> <match-one />
> </single-pool>
> </connectionmanager>
> </connectiondefinition-instance>
> </connection-definition>
> </outbound-resourceadapter>
> </resourceadapter>
>
> <!-- defines a Topic -->
> <adminobject>
> <adminobject-interface>javax.jms.Topic</adminobject-interface>
> <adminobject-class>
> org.activemq.message.ActiveMQTopic
> </adminobject-class>
> <adminobject-instance>
> <message-destination-name>
> jms/ncodeInputTopic</message-destination-name>
> <config-property-setting
> name="PhysicalName">
> jms/ncodeInputTopic
> </config-property-setting>
> </adminobject-instance>
> </adminobject>
> </connector>
>
>
> I deploy it with:
>
> java -jar bin/deployer.jar redeploy PATH_TO_THIS/jms-connector.xml
> repository/activemq/rars/activemq-ra-3.2.1.rar
>
> This works as the console shows under "Services" -> "JMS"
>
>
> My GBean is deployed with the following plan:
>
> <configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://geronimo.apache.org/xml/ns/deployment-1.0"
> configId="ncode/Syslog"
> parentId="ncodeTopicConnectionFactory">
>
> <dependency>
> <uri>ncode/Syslog-GBean/0.0.1/jar</uri>
> </dependency>
> <dependency>
> <uri>commons-lang/commons-lang/2.0/jar</uri>
> </dependency>
>
> <gbean name="ncode.SyslogServer"
> class="ch.ncode.logquest.syslog.SyslogGBean">
>
> <!-- reference the JMS here -->
> <reference name="managedConnectionFactoryWrapper">
> <moduleType>JCAResource</moduleType>
>
> <!-- will this work ?? -->
> <name>ncodeTopicConnectionFactory</name>
> </reference>
>
> <!-- attributes for this GBean -->
> <attribute name="port">5144</attribute>
>
> </gbean>
> </configuration>
>
>
> However, when deploying, the server can not find the reference:
>
> 23:05:23,724 DEBUG [GBeanSingleReference] Waiting to start
> geronimo.server:name=ncode.SyslogServer,J2EEServer=geronimo,J2EEApplic
> ation=null,j2eeType=GBean,J2EEModule=ncode/Syslog
> because no targets are running for reference
> managedConnectionFactoryWrapper matching the patterns
> geronimo.server:J2EEApplication=null,J2EEServer=geronimo,JCAResource=n
> code/
> Syslog,j2eeType=JCAManagedConnectionFactory,name=ncodeTopicConnectionF
> actory
At this point I look in var/log/geronimo.log and try to find the
actual name the managed connection factory is deployed under.
I suspect the problem is that you need
<module>ncodeTopicConnectionFactory</module> in your reference, but
I'm not entirely sure.
hope this gets you farther :-)
david jencks
>
>
> Thanks for your help!
> oli kessler
>
>
>
>
>
>
>
>
>
>
Re: JMS Connection Factory / JNDI Naming
Posted by Oli Kessler <ok...@ncode.ch>.
>
> Jndi won't work within a gbean, you should use a gbean reference.
> Here's an example from the system datasource plan, and the gbean
> referenced can show you how to code it. The reference to emulate
> here is ManagedConnectionFactoryWrapper
>
> <gbean name="NonTransactionalThreadPooledTimer"
> class="org.apache.geronimo.timer.jdbc.JDBCStoreThreadPooledNonTransactio
> nalTimer"> <reference
> name="TransactionContextManager"><moduleType>J2EEModule</
> moduleType><module>geronimo/j2ee-server/${pom.currentVersion}/car</
> module><name>TransactionContextManager</name></reference> <reference
> name="ManagedConnectionFactoryWrapper"><moduleType>JCAResource</
> moduleType><name>SystemDatasource</name></reference> <reference
> name="ThreadPool"><moduleType>J2EEModule</
> moduleType><module>geronimo/j2ee-server/${pom.currentVersion}/car</
> module><name>DefaultThreadPool</name></reference> <!--TODO remove
> moduleType when gbeans get the moduleType of the plan they are in -->
> <reference name="DerbySystem"><moduleType>J2EEModule</
> moduleType><name>DerbySystem</name></reference> </gbean>
>
> thanks david jencks
Thanks for your help, david. However I'm apparently still missing
something..
My connector information is:
<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.0"
configId="ncodeTopicConnectionFactory"
parentId="geronimo/activemq-broker/1.0/car">
<resourceadapter>
<resourceadapter-instance>
<resourceadapter-name>ncodeJMS</resourceadapter-name>
<config-property-setting name="ServerUrl">
vm://localhost
</config-property-setting>
<config-property-setting name="UserName">not needed
</config-property-setting>
<config-property-setting name="Password">not needed
</config-property-setting>
<workmanager>
<gbean-link>DefaultWorkManager</gbean-link>
</workmanager>
</resourceadapter-instance>
<!-- defines a ConnectionFactory -->
<outbound-resourceadapter>
<connection-definition>
<connectionfactory-interface>
javax.jms.TopicConnectionFactory
</connectionfactory-interface>
<connectiondefinition-instance>
<name>ncodeTopicConnectionFactory</name>
<connectionmanager>
<xa-transaction> <transaction-caching />
</xa-transaction>
<single-pool>
<max-size>10</max-size> <min-size>0</min-size>
<blocking-timeout-milliseconds>5000
</blocking-timeout-milliseconds>
<idle-timeout-minutes>0</idle-timeout-minutes>
<match-one />
</single-pool>
</connectionmanager>
</connectiondefinition-instance>
</connection-definition>
</outbound-resourceadapter>
</resourceadapter>
<!-- defines a Topic -->
<adminobject>
<adminobject-interface>javax.jms.Topic</adminobject-interface>
<adminobject-class>
org.activemq.message.ActiveMQTopic
</adminobject-class>
<adminobject-instance>
<message-destination-name>
jms/ncodeInputTopic</message-destination-name>
<config-property-setting
name="PhysicalName">
jms/ncodeInputTopic
</config-property-setting>
</adminobject-instance>
</adminobject>
</connector>
I deploy it with:
java -jar bin/deployer.jar redeploy PATH_TO_THIS/jms-connector.xml
repository/activemq/rars/activemq-ra-3.2.1.rar
This works as the console shows under "Services" -> "JMS"
My GBean is deployed with the following plan:
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://geronimo.apache.org/xml/ns/deployment-1.0"
configId="ncode/Syslog"
parentId="ncodeTopicConnectionFactory">
<dependency>
<uri>ncode/Syslog-GBean/0.0.1/jar</uri>
</dependency>
<dependency>
<uri>commons-lang/commons-lang/2.0/jar</uri>
</dependency>
<gbean name="ncode.SyslogServer"
class="ch.ncode.logquest.syslog.SyslogGBean">
<!-- reference the JMS here -->
<reference name="managedConnectionFactoryWrapper">
<moduleType>JCAResource</moduleType>
<!-- will this work ?? -->
<name>ncodeTopicConnectionFactory</name>
</reference>
<!-- attributes for this GBean -->
<attribute name="port">5144</attribute>
</gbean>
</configuration>
However, when deploying, the server can not find the reference:
23:05:23,724 DEBUG [GBeanSingleReference] Waiting to start
geronimo.server:name=ncode.SyslogServer,J2EEServer=geronimo,J2EEApplication=null,j2eeType=GBean,J2EEModule=ncode/Syslog
because no targets are running for reference
managedConnectionFactoryWrapper matching the patterns
geronimo.server:J2EEApplication=null,J2EEServer=geronimo,JCAResource=ncode/Syslog,j2eeType=JCAManagedConnectionFactory,name=ncodeTopicConnectionFactory
Thanks for your help!
oli kessler
Re: JMS Connection Factory / JNDI Naming
Posted by David Jencks <da...@yahoo.com>.
On Mar 17, 2006, at 4:09 PM, Oli Kessler wrote:
> Hello,
>
> I'm trying to write a GBean that depends on a JMS configuration
> initialized with a resource group configuration plan as indicated
> in the
> book by Aaron Mulder on chariotsolutions.com.
>
> The file contains a connection factory object named
> "MyConnectionFactory" indicated in the connectiondefition-instance
> and a
> topic called "MyTopic" (message-destination-name). When deployed,
> those
> 2 objects can be seen and verified in the web console.
>
> Now, my GBean needs to publish to the topic "MyTopic" using a
> connection
> from the factory object. How would I get the factory object in my code
> with JNDI? Opposed to a web-application or EJB, I can not count on
> configured resource references in web.xml or similar, right?
>
> I tried the simple
>
> (..)
> InitialContext context = new InitialContext();
> Object obj = context.lookup("MyConnectionFactory);
> (..)
>
> but this did not work out. Is there any prefix I should use?
Jndi won't work within a gbean, you should use a gbean reference.
Here's an example from the system datasource plan, and the gbean
referenced can show you how to code it. The reference to emulate
here is ManagedConnectionFactoryWrapper
<gbean name="NonTransactionalThreadPooledTimer"
class="org.apache.geronimo.timer.jdbc.JDBCStoreThreadPooledNonTransactio
nalTimer">
<reference
name="TransactionContextManager"><moduleType>J2EEModule</
moduleType><module>geronimo/j2ee-server/${pom.currentVersion}/car</
module><name>TransactionContextManager</name></reference>
<reference
name="ManagedConnectionFactoryWrapper"><moduleType>JCAResource</
moduleType><name>SystemDatasource</name></reference>
<reference name="ThreadPool"><moduleType>J2EEModule</
moduleType><module>geronimo/j2ee-server/${pom.currentVersion}/car</
module><name>DefaultThreadPool</name></reference>
<!--TODO remove moduleType when gbeans get the moduleType of
the plan they are in -->
<reference name="DerbySystem"><moduleType>J2EEModule</
moduleType><name>DerbySystem</name></reference>
</gbean>
thanks
david jencks
>
>
> Cheers,
> Oli Kessler
>
> --
> ncode solutions gmbh
> http://www.ncode.ch
>
> tel +41 43 817 01 88
> fax +41 43 817 02 88
> Zurich / Switzerland