From: Peter A. <pr...@mi...> - 2001-06-24 21:07:57
|
On Thu, 21 Jun 2001, Jason Dillon wrote: > I found the problem, well I solved my problem is a better way to put it. > The session bean (stateful) which I was using to send messages from was > creating a session in the ejbCreate() method, then actually used in another. > > I was assuming that the container would "do the right thing" in this case, > but perhaps it is not supposed to do here. I updated the bean to create the > session in the method from which it was used and it is much happier now. > > I did run into some other problems along the way, like trying to start() or > close() connections. But at this point I have everything working again with > most of the JMS usage going through the JMS RA. There is one bit that needs > to be re-architected into a bean so it can also participate in the TX, but > that can wait. > > Thank you for the time you spent with the example below, this was exactly > what I was looking for. Great that it worked. Any feedback on the jms-ra stuff is wellcomed, since it is a non standard way of using the two standards (connector and JMS). Since you are not allowed to use asynchronous stuff with the connector I did not think that start was applyable, but we may have to rethink that. //Peter > > --jason > > > On Thu, 21 Jun 2001, Peter Antman wrote: > > > Hi again Jason, > > I did actually have some time to make a test, and it works fine for me. > > (This will be integreated into the new manual chapter I will be writing > > during the summer). > > > > Here is al my setups, with the remote machine beeing > > linutv1.annons.dn.se (its NOT accessable) > > > > in jboss.jcml: > > > > <!-- This must go into jboss.jcml to get remote version to work --> > > <mbean code="org.jboss.jms.jndi.JMSProviderLoader" name=":service=JMSProviderLoader,name=MyRemoteLoader"> > > <attribute name="ProviderName">MyRemoteProvider</attribute> > > <attribute name="ProviderUrl">linutv1.annons.dn.se:1099</attribute> > > <attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JBossMQProvider</attribute> > > </mbean> > > > > <!-- JMS XA Resource adapter, use this to get transacted JMS in beans --> > > <mbean code="org.jboss.resource.ConnectionFactoryLoader" > > name="JCA:service=ConnectionFactoryLoader,name=RemoteJmsXA"> > > <attribute name="FactoryName">RemoteJmsXA</attribute> > > <attribute name="RARDeployerName">JCA:service=RARDeployer</attribute> > > <attribute name="ResourceAdapterName">JMS Adapter</attribute> > > <attribute name="ConnectionManagerFactoryName">MinervaXACMFactory</attribute> > > <!-- See the documentation for the specific connection manager > > implementation you are using for the properties you can set --> > > <attribute name="ConnectionManagerProperties"> > > <attribute name="Properties"> > > JmsProviderAdapterJNDI=java:MyRemoteProvider > > </attribute> > > # Pool type - uncomment to force, otherwise it is the default > > #PoolConfiguration=per-factory > > > > # Connection pooling properties - see > > # org.opentools.minerva.pool.PoolParameters > > MinSize=0 > > MaxSize=10 > > Blocking=true > > GCEnabled=false > > IdleTimeoutEnabled=false > > InvalidateOnError=false > > TrackLastUsed=false > > GCIntervalMillis=120000 > > GCMinIdleMillis=1200000 > > IdleTimeoutMillis=1800000 > > MaxIdleTimeoutPercent=1.0 > > </attribute> > > > > <!-- Principal mapping configuration --> > > <attribute name="PrincipalMappingClass">org.jboss.resource.security.ManyToOnePrincipalMapping</attribute> > > <attribute name="PrincipalMappingProperties"> > > </attribute> > > </mbean> > > > > > > In jboss.xml: > > <?xml version="1.0" encoding="Cp1252"?> > > > > <jboss> > > <secure>false</secure> > > <resource-managers> > > <resource-manager> > > <res-name>topicfactoryref</res-name> > > <res-jndi-name>java:/RemoteJmsXA</res-jndi-name> > > </resource-manager> > > <resource-manager> > > <res-name>topicref</res-name> > > <res-jndi-name>jnp://linutv1.annons.dn.se:1099/topic/testTopic</res-jndi-name> > > </resource-manager> > > </resource-managers> > > > > <enterprise-beans> > > <session> > > <ejb-name>TopicHello</ejb-name> > > <jndi-name>TxTopicHello</jndi-name> > > <configuration-name>Standard Stateless SessionBean</configuration-name> > > <resource-ref> > > <res-ref-name>jms/MyTopicConnection</res-ref-name> > > <resource-name>topicfactoryref</resource-name> > > </resource-ref> > > <resource-ref> > > <res-ref-name>jms/TopicName</res-ref-name> > > <resource-name>topicref</resource-name> > > </resource-ref> > > </session> > > </enterprise-beans> > > </jboss> > > > > Observe the <res-jndi-name> here, not url. > > > > ejb-jar (actually nothing particular) > > <?xml version="1.0" encoding="Cp1252"?> > > > > <ejb-jar> > > <description>Queue Publisher</description> > > <display-name>PublisherBean</display-name> > > <enterprise-beans> > > <session> > > <display-name>TopicHello</display-name> > > <ejb-name>TopicHello</ejb-name> > > <home>org.jboss.docs.jms.ra.interfaces.HelloHome</home> > > <remote>org.jboss.docs.jms.ra.interfaces.Hello</remote> > > <ejb-class>org.jboss.docs.jms.ra.bean.TopicHelloBean</ejb-class> > > <session-type>Stateless</session-type> > > <transaction-type>Container</transaction-type> > > <resource-ref> > > <description>A Topic ConnectionFactory</description> > > <res-ref-name>jms/MyTopicConnection</res-ref-name> > > <res-type>javax.jms.TopicConnectionFactory</res-type> > > <res-auth>Container</res-auth> > > </resource-ref> > > <resource-ref> > > <description>A Topic </description> > > <res-ref-name>jms/TopicName</res-ref-name> > > <res-type>javax.jms.Topic</res-type> > > <res-auth>Container</res-auth> > > </resource-ref> > > </session> > > </enterprise-beans> > > <assembly-descriptor/> > > > > </ejb-jar> > > > > And the bean: > > > > package org.jboss.docs.jms.ra.bean; > > > > import java.rmi.RemoteException; > > import java.util.*; > > import javax.ejb.SessionBean; > > import javax.ejb.SessionContext; > > import javax.ejb.EJBException; > > import javax.naming.*; > > import javax.jms.*; > > > > import org.jboss.docs.jms.ra.interfaces.*; > > > > > > public class TopicHelloBean implements SessionBean { > > > > private static final String CONNECTION_JNDI = "java:comp/env/jms/MyTopicConnection"; > > private static final String TOPIC_JNDI = "java:comp/env/jms/TopicName"; > > > > private SessionContext ctx = null; > > private Topic topic = null; > > private TopicConnection topicConnection = null; > > > > public TopicHelloBean() { > > } > > > > public void setSessionContext(SessionContext ctx) { > > this.ctx = ctx; > > } > > > > public void ejbCreate() { > > try { > > Context context = new InitialContext(); > > topic = (Topic)context.lookup(TOPIC_JNDI); > > > > TopicConnectionFactory factory = (TopicConnectionFactory)context.lookup(CONNECTION_JNDI); > > topicConnection = factory.createTopicConnection(); > > > > } catch (Exception ex) { > > // JMSException or NamingException could be thrown > > ex.printStackTrace(); > > throw new EJBException(ex.toString()); > > } > > } > > > > /** > > * Send a message with a message nr in property MESSAGE_NR > > */ > > public void hello(String msg) { > > sendMessage(msg); > > } > > > > > > public void ejbRemove() throws RemoteException { > > if(topicConnection != null) { > > try { > > topicConnection.close(); > > } catch (Exception e) { > > e.printStackTrace(); > > } > > } > > } > > > > public void ejbActivate() {} > > public void ejbPassivate() {} > > > > private void sendMessage(String msg) { > > TopicSession topicSession = null; > > try { > > TopicPublisher topicPublisher = null; > > TextMessage message = null; > > > > topicSession = > > topicConnection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE); > > topicPublisher = topicSession.createPublisher(topic); > > > > message = topicSession.createTextMessage(); > > message.setText(msg); > > topicPublisher.publish(message); > > > > > > } catch (JMSException ex) { > > > > ex.printStackTrace(); > > ctx.setRollbackOnly(); > > throw new EJBException(ex.toString()); > > } finally { > > if (topicSession != null) { > > try { > > topicSession.close(); > > } catch (Exception e) { > > e.printStackTrace(); > > } > > } > > } > > } > > > > } > > > > > > This was done with a resonable new checkout from cvs (node) and 2.2.2 as > > a router (to follow your setup). > > > > Hope you will hace success with this setup. > > > > //Peter > > > > On 20 Jun, Jason Dillon wrote: > > > Hey, I have been trying to figure this out for a few days now and I keep > > > running into walls. I have a distributed system that uses JMS for > > > communication, using a centralized router (all running on JBoss with > > > JBossMQ). > > > > > > I was able to get everything working using an ExternalContext, to map in the > > > namespace of the remote router, but that is less than perfect. I started to > > > change over to the JmsXA adapter, but I am running into some odd problems. > > > > > > An overly simplified view of the system looks like this, showing three > > > seperate pyshical machines: web server, manager node and router. The > > > current architecture assumes a hub-spoke model for using JMS resources, so > > > that all machines that actually make use of the JMS resources are remote, > > > there are not MDB's running on the router. > > > > > > RMI > > > [ web server ] +-----------+ [ manager node ] > > > | | > > > (SessionBean) (MDB) > > > | | > > > JMS Queue Resource | > > > \ / > > > \ / > > > [ router ] > > > || > > > (real queues) > > > > > > I installed the resource adapter, which seems to like to be deployed rather > > > than having a mbean entry added in jboss.jcml, which I basically copied from > > > the main branch conf/default files. > > > > > > The manager has a JMSProviderLoader installed which is using a remote > > > <hostname>:<port> url to the router, and has the default session pool stuff. > > > I think that the MDB bits work fine. I do not *think* that I had to change > > > anything to get that to work, the problem I am running into is with JMS > > > resources. > > > > > > Per your change note, I changed the res-jndi-name to from the external > > > context path to java:JmsXA. But I also had to use url's to get the > > > destinations to work. So I ended up with something like this: > > > > > > <resource-managers> > > > <resource-manager> > > > <res-name>QueueConnectionFactory</res-name> > > > <res-jndi-name>java:/JmsXA</res-jndi-name> > > > </resource-manager> > > > > > > <resource-manager> > > > <res-name>WorkRequestQueue</res-name> > > > <res-url>jnp://router:5001/queue/WorkRequestQueue</res-url> > > > </resource-manager> > > > > > > <resource-manager> > > > <res-name>WorkResponseQueue</res-name> > > > <res-url>jnp://router:5001/queue/WorkResponseQueue</res-url> > > > </resource-manager> > > > </resource-managers> > > > > > > I started up the application again, and got: > > > > > > <snip> > > > javax.jms.JMSException: Invalid transaction id. > > > at > > > org.jbossmq.SpyXAResourceManager.addMessage(SpyXAResourceManager.java:80) > > > at org.jbossmq.SpySession.sendMessage(SpySession.java:381) > > > at org.jbossmq.SpyQueueSender.send(SpyQueueSender.java:103) > > > at org.jbossmq.SpyQueueSender.send(SpyQueueSender.java:62) > > > at > > > com.boldfish.does.job.workflow.internal.RequestSpoolerEJB.send(RequestSpoolerEJB.java:217) > > > at > > > com.boldfish.does.job.workflow.internal.RequestSpoolerEJB.sendNextRequest(RequestSpoolerEJB.java:249) > > > at > > > com.boldfish.does.job.workflow.internal.RequestSpoolerEJB.spool(RequestSpoolerEJB.java:273) > > > at java.lang.reflect.Method.invoke(Native Method) > > > at > > > org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(StatefulSessionContainer.java:650) > > > at > > > org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127) > > > at > > > org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSessionInstanceInterceptor.java:209) > > > at > > > org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:159) > > > at > > > org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:280) > > > at > > > org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:107) > > > at > > > org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195) > > > at > > > org.jboss.ejb.StatefulSessionContainer.invoke(StatefulSessionContainer.java:341) > > > at > > > org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:480) > > > at > > > org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(GenericProxy.java:339) > > > at > > > org.jboss.ejb.plugins.jrmp.interfaces.StatefulSessionProxy.invoke(StatefulSessionProxy.java:136) > > > at $Proxy25.spool(Unknown Source) > > > at > > > com.boldfish.does.job.service.JobController$Runner.run(JobController.java:216) > > > at java.lang.Thread.run(Thread.java:484) > > > </snip> > > > > > > So I thought that I should try a distributed TX manager, since that is what > > > i really want. I changed over to Tyrex on all nodes and I still got the > > > same results. I then tried to use a jnp:// url for the res-jndi-name, which > > > looks like it got a little further, but throw a different TX related > > > excepetion laiter. > > > > > > I have session beans that use JMS resources and I have MDB, all of which > > > work off of a remote provider. What is the supported deployment descriptor > > > syntax for JMS resources (both factories and desitations) and what needs to > > > be done to make the distributed TX work. > > > > > > A while back someone (could be you) said that using res-url was a hack > > > around the lack of support for JMS resources, is that still true? If not > > > what is the correct way to reference a remote connection and destination > > > inside of the descriptor? > > > > > > If you need more detail I can provide that for you, or really anyone who > > > might have a clue as to why this is not working correctly. > > > > > > Thanks, > > > > > > --jason > > > > > > > > > _______________________________________________ > > > JBoss-user mailing list > > > JBo...@li... > > > http://lists.sourceforge.net/lists/listinfo/jboss-user > > > > > > > _______________________________________________ > JBoss-user mailing list > JBo...@li... > http://lists.sourceforge.net/lists/listinfo/jboss-user > Jobba hos oss: http://www.tim.se/weblab ------------------------------------------------------------ Peter Antman Technology in Media, Box 34105 100 26 Stockholm Systems Architect WWW: http://www.tim.se Email: pr...@ti... WWW: http://www.backsource.org Phone: +46-(0)8-506 381 11 Mobile: 070-675 3942 ------------------------------------------------------------ |