Spring JMS message redelivery is not working - jms

I am not sure what i am missing, when consumer is not able to process messsage it throws JMSException but i see failed messages are not getting redeliver otherwise below code is working fine , please help me what i am missing ?
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms-3.0.xsd">
<!-- Use Springs JNDI support to look up JMS Connection Factory and Queue definitions from the
container. This means that specific connection details are not embedded in the application
-->
<bean id="mqConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>vm://localhost:61616</value>
</property>
<property name="nonBlockingRedelivery" value="true"/>
<property name="redeliveryPolicy">
<bean class="org.apache.activemq.RedeliveryPolicy">
<property name="initialRedeliveryDelay" value="5000" />
<property name="backOffMultiplier" value="2" />
<property name="queue" value="*" />
<property name="useExponentialBackOff" value="true" />
<property name="redeliveryDelay" value="5000" />
<property name="maximumRedeliveries" value="20"/>
</bean>
</property>
</bean>
</property>
</bean>
<bean id="mqProducerConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>vm://localhost:61616</value>
</property>
</bean>
</property>
</bean>
<bean id="test_queue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="test_queue" />
</bean>
<bean id="testConsumer" class="com.test.jms.listener.TestConsumer">
</bean>
<bean id="poiMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref ="mqConnectionFactory" />
<property name="destination" ref ="test_queue"/>
<property name="messageListener" ref ="testConsumer"/>
<property name="concurrentConsumers" value="1" />
<property name="sessionTransacted" value="true"/>
</bean>
<bean id="testProducer" class="com.test.jms.producer.testProducer">
<property name="destination" ref="test_queue"/>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="mqProducerConnectionFactory" />
</bean>
<jms:listener-container
container-type="default"
connection-factory="mqConnectionFactory"
acknowledge="transacted">
<jms:listener destination="test_queue" ref="testConsumer" method="onMessage" />
</jms:listener-container>
</beans>
Above code is working fine but it does not work for message re-delivery

Related

JobRepositoryFactoryBean error spring batch

I started to learn spring batch and I have a problem that when i want to
persist the state of the job in a database using JobRepositoryFactoryBean.
compiler displays :
"Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in class path resource [springConfig.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/core/simple/ParameterizedRowMapper"
but not error when i use MapJobRepositoryFactoryBean
I'm using spring 5
springconfig.xml
<?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:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<context:component-scan base-package="springbatch" />
<context:annotation-config />
<bean id="personneReaderCSV" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" value="input/personnes.txt" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer">
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="delimiter" value="," />
<property name="names" value="id,nom,prenom,civilite" />
</bean>
</property>
<property name="fieldSetMapper">
<bean
class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<property name="targetType" value="springbatch.entities.Personne" />
</bean>
</property>
</bean>
</property>
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean name="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/spring_test" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>springbatch.entities.Personne</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<job id="importPersonnes" xmlns="http://www.springframework.org/schema/batch">
<step id="readWritePersonne">
<tasklet>
<chunk reader="personneReaderCSV"
processor="personProcessor"
writer="personWriter"
commit-interval="2" />
</tasklet>
</step>
</job>
<bean id="daoPersonne" class="springbatch.dao.PersonneDaoImp">
<property name="factory" ref="sessionFactory"></property>
</bean>
<bean id="personWriter" class="springbatch.batch.PersonneWriter">
<property name="dao" ref="daoPersonne"></property>
</bean>
<bean id="personProcessor" class="springbatch.batch.PersonneProcess">
</bean>
<bean id="batchLauncher" class="springbatch.MyBean">
</bean>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseType" value="Mysql" />
</bean>
<task:scheduled-tasks>
<task:scheduled ref="batchLauncher" method="message"
cron=" 59 * * * * * " />
</task:scheduled-tasks>
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="org/springframework/batch/core/schema-drop-mysql.sql" />
<jdbc:script location="org/springframework/batch/core/schema-mysql.sql" />
</jdbc:initialize-database>
</beans>
but not error when i use :
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
You are using Spring Batch v2.2 with Spring Framework 5. That's not going to work properly as ParameterizedRowMapper has been removed in Spring Framework 4.2+ (hence the exception).
I recommend that you use Spring Batch v4.1 (since v2.x is not maintained anymore) and your issue should be fixed.
The best way to manage Spring dependencies is to let Spring Boot do it for you either by generating a project from start.spring.io or by using the Spring Boot BOM. With both ways, you will have the correct Spring projects dependencies that are known to work well together.

How declare 2 different rabbitMQ in one Spring application context

I have two different instances of RabbitMQ at localhost:5672 and localhost:5676.
Also I configured it in my application context:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation=
"http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
xmlns:cache="http://www.springframework.org/schema/cache">
<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<property name="username" value="${rabbit.username}"/>
<property name="password" value="${rabbit.password}"/>
<property name="host" value="${rabbit.host}"/>
<property name="port" value="${rabbit.port}"/>
</bean>
<bean id="amqpTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<property name="connectionFactory" ref="rabbitConnectionFactory"/>
<property name="exchange" value="${rabbit.exchange}"/>
<property name="routingKey" value="${rabbit.routing-key}"/>
<property name="queue" value="${rabbit.queue}"/>
</bean>
<bean id="admin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
<constructor-arg ref="rabbitConnectionFactory" />
</bean>
<bean id="rabbitTxManager"
class="org.springframework.amqp.rabbit.transaction.RabbitTransactionManager">
<property name="connectionFactory" ref="rabbitConnectionFactory"/>
</bean>
<bean id="messageListenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
<property name="channelTransacted" value="true"/>
<property name="transactionManager" ref="rabbitTxManager"/>
<property name="prefetchCount" value="${rabbit.prefetchCount}"/>
<property name="txSize" value="${rabbit.txSize}"/>
<property name="connectionFactory" ref="rabbitConnectionFactory"/>
<property name="messageListener" ref="handler"/>
<property name="queueNames" value="${rabbit.queue}"/>
<property name="concurrentConsumers" value="${rabbit.concurrentConsumers}"/>
<property name="errorHandler" ref="errorHandler"/>
</bean>
<bean id="handler" class="com.pb.pav.timingbus.amqp.MessageHandler" >
<constructor-arg index="0" ref="gson"/>
<constructor-arg index="1" ref="sender"/>
</bean>
<bean id="errorHandler" class="com.pb.pav.timingbus.amqp.ExceptionHandler"/>
<bean id="gson" factory-bean="formattedBuilder" factory-method="create" />
<bean id="gsonBuilder" class="com.google.gson.GsonBuilder" />
<bean id="formattedBuilder" factory-bean="gsonBuilder" factory-method="setDateFormat">
<constructor-arg index="0" value="yyyy-MM-dd HH:mm:ss.SSS"/>
</bean>
<bean id="sender" class="com.pb.timing.client.TimingWSClient">
<constructor-arg index="0" value="${timing.url}"/>
</bean>
<bean id="busService" class="com.pb.pav.timingbus.BusService" />
<bean id="answerConnFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<property name="username" value="guest"/>
<property name="password" value="guest"/>
<property name="host" value="localhost"/>
<property name="port" value="5676"/>
<property name="channelCacheSize" value="2"/>
</bean>
<bean id="rabbitAnswer" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<property name="connectionFactory" ref="answerConnFactory"/>
<property name="exchange" value="timinganswers"/>
<property name="routingKey" value="temp"/>
<property name="queue" value="temp"/>
</bean>
<bean id="answerAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
<constructor-arg ref="answerConnFactory" />
</bean>
<bean id="mesSender" class="com.pb.pav.timingbus.amqp.MessageSender" >
<constructor-arg index="0" ref="gson"/>
<constructor-arg index="1" ref="rabbitAnswer"/>
</bean>
My spring web application produce messages to rabbit(localhost:5672, id="amqpTemplate") and then consume from queue and save to DB.
After saving to DB application produce answers (ok or errors) and I need publish answers to the second rabbitMQ(localhost:5676, id="rabbitAnswer").
When I try publish answers to second rabbit(localhost:5676, id="rabbitAnswer") they published to first rabbit, and I dont understand why??? I am logging port for connection before send messages and it right - 5676, but application send messages to 5672.
I suspect that problem is in channels, because at the second rabbit I didn't see any opened channels. So, how I can declare different channels to my second rabbit and send messages in the right way?

java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader Hibernate

I am working on a project with Hibernate JPA /spring.
It throws the following exception. After doing some reading I removed all the xml-apis from dependencies but it throws the same error. Any ideas ??
java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:199)
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:150)
at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)
at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
at org.dom4j.io.SAXReader.setFeature(SAXReader.java:218)
at org.hibernate.internal.util.xml.MappingReader.setValidationFor(MappingReader.java:114)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:77)
at org.hibernate.cfg.Configuration.add(Configuration.java:478)
at org.hibernate.cfg.Configuration.add(Configuration.java:474)
at org.hibernate.cfg.Configuration.add(Configuration.java:647)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:685)
at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1248)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1048)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:693)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
while I am trying to initialise the web context in jetty web server it throw the above exception.[Spring (3.0.6.Release) & hibernate (4.1.10.final) ]
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<import resource="classpath*:/META-INF/spring-orchestra-init.xml"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceUnitName="persistenceUnit">
<property name="dataSource" ref="dataSource"/>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="false"/>
</bean>
</property>
<property name="loadTimeWeaver">
<bean class="org.faces.controller.jpa.JpaLoadTimeWeaver"/>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="conversation.access">
<bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
<property name="advices">
<list>
<ref bean="persistentContextConversationInterceptor" />
</list>
</property>
</bean>
</entry>
</map>
</property>
</bean>
<bean id="jpaPersistentContextFactory" class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="persistentContextConversationInterceptor" class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">
<property name="persistenceContextFactory" ref="jpaPersistentContextFactory" />
</bean>
<bean name="org.apache.myfaces.orchestra.conversation.AccessScopeManagerConfiguration"
class="org.apache.myfaces.orchestra.conversation.AccessScopeManagerConfiguration"
scope="singleton" lazy-init="true">
<property name="ignoreViewIds">
<set>
<value>/__ADFv__.xhtml</value>
</set>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#rum:1541:CHEZTST" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
After removing the loadtimeweaver property it worked fine.
<property name="loadTimeWeaver">
<bean class="org.faces.controller.jpa.JpaLoadTimeWeaver"/>
</property>
this is the link that shows that, although it is quite old it works
https://jira.springsource.org/browse/SPR-2596

JMS queue with spring

My springcontext-notification XML:
<?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:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
<bean
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="notificationJmsConnectionFactory" />
<property name="destinationName" value="${bpm.task.queue}" />
<property name="messageListener" ref="taskMessageReceiver" />
<property name="sessionTransacted" value="true" />
<property name="clientId" value="BPMTaskMessageLisetners" />
<property name="transactionManager" ref="transactionManager" />
<property name="maxConcurrentConsumers" value="${bpm.task.queue.listener.concurrency}" />
</bean>
<bean id="taskMessageReceiver"
class="com.sterling.ag.jms.impl.TaskMessageListenerImpl">
</bean>
<bean id="notificationJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="notificationJmsConnectionFactory" />
<property name="sessionTransacted" value="true" />
</bean>
<jee:jndi-lookup id="notificationJmsConnectionFactory"
jndi-name="java:/JmsXA">
<!--
<jee:environment>java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory</jee:environment>
-->
</jee:jndi-lookup>
<alias name="notificationJmsTemplate" alias="auditJmsTemplate" />
<alias name="notificationJmsTemplate" alias="historyExchangeJmsTemplate" />
</beans>
I have added another queue. How should i configure it in the above XML??
You need to create a separate container and listener
<bean
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="notificationJmsConnectionFactory" />
<property name="destinationName" value="${bpm.task.queue2}" />
<property name="messageListener" ref="taskMessageReceiver2" />
<property name="sessionTransacted" value="true" />
<property name="clientId" value="BPMTaskMessageLisetners" />
<property name="transactionManager" ref="transactionManager" />
<property name="maxConcurrentConsumers" value="${bpm.task.queue.listener.concurrency2}" />
</bean>
<bean id="taskMessageReceiver2"
class="com.sterling.ag.jms.impl.TaskMessageListenerImpl2">
</bean>

Unable to consume messages from activeMQ

I have been trying to write consumer client for active MQ. But I have not been able to consume messages. Even though I have set up wrong userID and password, still I am not getting any exception. Can someone please check my configuration:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>nio://localhost:61616</value>
</property>
<property name="userName"><value>saffsd</value></property>
<property name="password"><value>asdfa</value></property>
</bean>
<bean id="pooledJmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
<property name="connectionFactory">
<ref local="jmsFactory"/>
</property>
</bean>
<bean id="LV_TOPIC" class="org.apache.activemq.command.ActiveMQTopic" autowire="constructor">
<constructor-arg value="TOPIC.LV_REPORTING" />
</bean>
<bean id="LV_QUEUE" class="org.apache.activemq.command.ActiveMQQueue" autowire="constructor">
<constructor-arg value="QUEUE.LV_REPORTING" />
</bean>
<bean id="portfolioListener" class="com.oneinterface.enterprise.tradinggateway.listeners.Listener">
</bean>
<bean id="javaConsumer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="pooledJmsFactory"/>
<property name="destination" ref="LV_TOPIC" />
<property name="messageListener" ref="portfolioListener" />
</bean>
<bean id="ionaConsumer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="pooledJmsFactory"/>
<property name="destination" ref="LV_QUEUE" />
<property name="messageListener" ref="portfolioListener" />
</bean>
</beans>
My java code is:
public static void main(String[] args) {
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("config/LVConsumer.xml");
DefaultMessageListenerContainer defaultListen = (DefaultMessageListenerContainer) context.getBean("javaConsumer");
defaultListen.start();
System.err.println("Consuming message from Topic >>" + defaultListen.getDestination().toString());
DefaultMessageListenerContainer queueListen = (DefaultMessageListenerContainer) context.getBean("ionaConsumer");
queueListen.start();
System.err.println("Consuming message from Queue >>" + queueListen.getDestination().toString());
}
Thanks you :)
Try wrapping your jmsFactory within org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter like this
<bean id="userCredentialsConnectionFactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory">
<ref bean="jmsFactory" />
</property>
<property name="username">
<value>user</value>
</property>
<property name="password">
<value>password</value>
</property>
</bean>
And use userCredentialsConnectionFactory in place of jmsFactory

Resources