I m struggling with simple task with last two days.I have configured jms Message queue in Jboss6.x. I have configured jndi,jms MQ in spring using jmstemplate in applicationcontext.xml File,
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="messageListener" class="com.test.QueuereceiverDB" />
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">localhost:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
</props>
</property>
</bean>
<bean id="queueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>ConnectionFactory</value>
</property>
</bean>
<bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="cache">
<value>true</value>
</property>
</bean>
<bean id="QueueTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="queueConnectionFactory" />
</property>
<property name="destinationResolver">
<ref bean="jmsDestinationResolver" />
</property>
</bean>
<bean id="jmsSender" class="com.test.MessageSender">
<property name="jmsTemplate"> <ref bean="QueueTemplate" />
</property>
</bean>
<bean id="Queue" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate"> <ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>queue/MyQueue</value>
</property>
</bean>
<bean id="jmscontainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="concurrentConsumers" value="5" />
<property name="connectionFactory" ref="queueConnectionFactory" />
<property name="destination" ref="Queue" />
<property name="messageListener" ref="messageListener" />
</bean>
Below is Message sender
package com.test;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
public class MessageSender {
private JmsTemplate jmsTemplate;
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
public void sendMesage() {
MessageCreator messageCreator=new MessageCreator() {
public Message createMessage(Session session) throws
JMSException {
return session.createTextMessage("I am sending Invoice message");}
};
jmsTemplate.send("queue/MyQueue", messageCreator);
}
}
Finally Message receiver class
public class QueuereceiverDB implements MessageListener {
/**
* Default constructor.
*/
public QueuereceiverDB() {
// TODO Auto-generated constructor stub
}
/**
* @see MessageListener#onMessage(Message)
*/
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
System.out.println("Queue: I received a TextMessage at "
+ new Date());
TextMessage msg = (TextMessage) message;
System.out.println("Message is : " + msg.getText());
} else {
System.out.println("Not valid message for this Queue MDB");
}
} catch (JMSException e) {
e.printStackTrace();
}
}
I have loaded applicationcontext.xml file in web.xml file. After that deploy the war file in jboss there was no error and also message not received.I dont know why the message was not received.Can someone help me.
After adding resourc-ref tag it shows following error
Caused by: java.lang.RuntimeException: Neither any mapped-name/lookup/jndi-name specified nor any ResourceProvider could process resource-ref named env/ConnectionFactory of type javax.jms.QueueConnectionFactory
at org.jboss.switchboard.mc.resource.provider.ResourceRefResourceProviderDelegator.provide(ResourceRefResourceProviderDelegator.java:125) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.resource.provider.ResourceRefResourceProviderDelegator.provide(ResourceRefResourceProviderDelegator.java:44) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.JndiEnvironmentProcessor.process(JndiEnvironmentProcessor.java:68) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.deployer.AbstractSwitchBoardDeployer.process(AbstractSwitchBoardDeployer.java:119) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.deployer.WebEnvironmentSwitchBoardDeployer.internalDeploy(WebEnvironmentSwitchBoardDeployer.java:66) [:1.0.0-alpha-15]
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55) [:2.2.0.GA]
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179) [:2.2.0.GA]
The following contains queue name details and deployed in jboss/server/default/deploy mdb-hornetq.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:hornetq"
xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd" >
<queue name="MyQueue2" >
<entry name="/queue/MyQueue" />
</queue>
</configuration>