• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Example for JMS sender - receiver

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is the program I have written for a JMS Sender and receiver using Spring and JBoss Server.



package com.syntel.spring.jms;

import org.springframework.jms.core.*;
import org.springframework.jms.core.MessageCreator;
import javax.jms.*;
public class JmsSender {

private JmsTemplate102 jmsTemplate102;

public JmsTemplate102 getJmsTemplate102() {
return jmsTemplate102;
}

public void setJmsTemplate102(JmsTemplate102 jmsTemplate102) {
this.jmsTemplate102 = jmsTemplate102;
}

public void sendMesage(){
jmsTemplate102.send("JMS_RequestResponseQueue",
new MessageCreator() {
public Message createMessage(Session session)
throws JMSException {
return session.createTextMessage("This is a sample message");
}
});


}
}



package com.syntel.spring.jms;

import org.springframework.jms.core.*;
import javax.jms.*;
public class JmsReceiver {

private JmsTemplate102 jmsTemplate102;

public JmsTemplate102 getJmsTemplate102() {
return jmsTemplate102;
}

public void setJmsTemplate102(JmsTemplate102 jmsTemplate102) {
this.jmsTemplate102 = jmsTemplate102;
}

public void processMessage(){
Message msg = jmsTemplate102.receive("JMS_RequestResponseQueue");
try{
TextMessage textMessage = (TextMessage) msg;
if( msg!=null){
System.out.println(" Message Received -->" +
textMessage.getText());
}


}catch(Exception e){
e.printStackTrace();
}


}
}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<bean id="jmsQueueTemplate"
class="org.springframework.jms.core.JmsTemplate102">
<property name="connectionFactory">
<ref bean="jmsQueueConnectionFactory"/>
</property>
<property name="destinationResolver">
<ref bean="jmsDestinationResolver"/>
</property>
<property name="pubSubDomain">
<value>false</value>
</property>
<property name="receiveTimeout">
<value>20000</value>
</property>
</bean>

<bean id="jmsQueueConnectionFactory"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName">
<value>MQ_JMS_MANAGER</value>
</property>
</bean>

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">
com.sun.jndi.fscontext.RefFSContextFactory
</prop>
<prop key="java.naming.provider.url">
file:/C:/JNDI-Directory
</prop>
</props>
</property>
</bean>

<bean id="jmsSender"
class="com.syntel.spring.jms.JmsSender">
<property name="jmsTemplate102">
<ref bean="jmsQueueTemplate"/>
</property>

</bean>

<bean id="jmsReceiver"
class="com.syntel.spring.jms.JmsReceiver">
<property name="jmsTemplate102">
<ref bean="jmsQueueTemplate"/>
</property>

</bean>



</beans>


package com.syntel.spring.jms;


import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.ApplicationContext;
public class SenderToQueue
{
public static void main(String[] args) {



ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Jms.xml");
JmsSender jmsSender = (JmsSender)context.getBean("jmsSender");

//get the Spring JMSTemplate (here we use the JMS 102 template

}
}


I am getting the following errors

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsQueueTemplate' defined in class path resource [Spring-Jms.xml]: Cannot resolve reference to bean 'jmsQueueConnectionFactory' while setting bean property 'connectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsQueueConnectionFactory' defined in class path resource [Spring-Jms.xml]: Invocation of init method failed; nested exception is javax.naming.NotContextException; remaining name 'C:\JNDI-Directory'
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.syntel.spring.jms.SenderToQueue.main(SenderToQueue.java:12)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsQueueConnectionFactory' defined in class path resource [Spring-Jms.xml]: Invocation of init method failed; nested exception is javax.naming.NotContextException; remaining name 'C:\JNDI-Directory'
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1337)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 18 more
Caused by: javax.naming.NotContextException; remaining name 'C:\JNDI-Directory'
at com.sun.jndi.fscontext.FSContext.checkIsDirectory(FSContext.java:885)
at com.sun.jndi.fscontext.FSContext.<init>(FSContext.java:108)
at com.sun.jndi.fscontext.FSContext.<init>(FSContext.java:81)
at com.sun.jndi.fscontext.RefFSContext.<init>(RefFSContext.java:97)
at com.sun.jndi.fscontext.RefFSContextFactory.createContext(RefFSContextFactory.java:42)
at com.sun.jndi.fscontext.RefFSContextFactory.createContextAux(RefFSContextFactory.java:47)
at com.sun.jndi.fscontext.FSContextFactory.getInitialContext(FSContextFactory.java:49)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:137)
at org.springframework.jndi.JndiTemplate.getContext(JndiTemplate.java:104)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:86)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
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:200)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:186)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
... 28 more


What changes should I make in this

Thanks and regards

Vidhu VS
Syntel Ltd
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Vidhu V S", you have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Be aware that accounts with invalid display names are disabled.

bear
JavaRanch Sheriff
 
Your mind is under my control .... your will is now mine .... read this tiny ad
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!