intermittent failures doing a spring way of topic lookup
tosaravananm Apr 29, 2013 4:47 AMHi,
We are migrating an application from AS5.1.0 to 7.x and JMS topics are created in a programmatic way, we also do an spring way of jndi lookup to create message consumers. Intermittently the lookup failed with naming exception. I am sure the topic creation and lookup are single thread and the order is always create -> jndi lookup.
Code creating topic
JMSServerControl server = MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(), new ObjectName("org.hornetq:module=JMS,type=Server"), JMSServerControl.class, false); jmsServer.createTopic("topic/myTopic", "java:/topic/myTopic");
in spring descriptor file
<jee:jndi-lookup id="destination" jndi-name="topic/myTopic">
Surprisingly programmatic way of lookup succeeds
try { String name = "topic/" + getDestination()); JndiObjectFactoryBean bean = new JndiObjectFactoryBean(); bean.setJndiName(name); bean.setLookupOnStartup(true); bean.afterPropertiesSet(); bean.getObject(); m_log.info(getDestination() +" created successfully!"); } catch(Exception e) { }
And here is the exception
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'destination': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Error looking up topic/myTopic, service service jboss.naming.context.java.topic.filterEvent is not started
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com............
... 11 more
Caused by: javax.naming.NameNotFoundException: Error looking up topic/myTopic, service service jboss.naming.context.java.topic.myTopic is not started
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:126)
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:74)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_06-ea]
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 24 more