PDA

View Full Version : How to use TopicConnectionFactory



whereur
Dec 29th, 2005, 08:21 PM
I'm new to Spring JMS and i m using it for a IBM MQ. I was given a jndi object of TopicConnectionFactory and follow the example from ibm-developworkers to config like this:


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

<!-- Application Context -->
<beans>
<!-- JNDI Environment Template -->
<bean id="jndiTemplate"
class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">
com.ibm.mq.jms.context.WMQInitialContextFactory
</prop>
<prop key="java.naming.provider.url">
192.168.1.21:9827/SYSTEM.DEF.SVRCONN
</prop>
<prop key="java.naming.security.authentication">
simple
</prop>
<prop key="java.naming.security.principal">
cn=xx,ou=users,ou=handler,dc=eca,dc=com
</prop>
<prop key="java.naming.security.credentials">
hallo
</prop>
<prop key="java.naming.referral">throw</prop>
</props>
</property>
</bean>

<!-- JMS Queue Connection Factory -->
<bean id="internalJmsQueueConnectionFactory"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>TCF.COMMON</value>
</property>
</bean>

<!-- Spring JMS Queue Connection Factory -->
<bean id="jmsQueueConnectionFactory"
class="org.springframework.jms.connection.SingleConnectio nFactory">
<property name="targetConnectionFactory">
<ref bean="internalJmsQueueConnectionFactory" />
</property>
</bean>

<!-- JMS Destination Resolver -->
<bean id="jmsDestinationResolver"
class="org.springframework.jms.support.destination.JndiDe stinationResolver">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="cache">
<value>true</value>
</property>
</bean>

<!-- JMS Queue Template -->
<bean id="jmsQueueTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="internalJmsQueueConnectionFactory" />
</property>
<!-- for topic is true -->
<property name="pubSubDomain">
<value>true</value>
</property>
<property name="destinationResolver">
<ref bean="jmsDestinationResolver" />
</property>
<property name="defaultDestinationName" value="topic_core" />
<property name="receiveTimeout">
<value>20000</value>
</property>
</bean>


<bean id="jmsSender" class="JMSSender">
<property name="jmsTemplate">
<ref bean="jmsQueueTemplate" />
</property>

</bean>

<bean id="jmsReceiver" class="JMSReceiver">
<property name="jmsTemplate">
<ref bean="jmsQueueTemplate" />
</property>
</bean>
</beans>

after configed, in my JMSReceiver, i use JMSTemplate in this way:

public void sendMessage(final String text){
jmsTemplate.send(new MessageCreator(){
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(text);
}});
}

and it throws a Error:

java.lang.AbstractMethodError: com.ibm.mq.jms.MQTopicConnectionFactory.createConn ection()Ljavax/jms/Connection;

i dont know if the AbstractMethodError is the default behavior of TopicConnectionFactory,or just for MQTopicConnectionFactory?
And could someone give me some advise of how to config a TopicConnectionFactory by Spring JMS? Thanks so much~ :)

jstrachan
Dec 30th, 2005, 04:45 AM
This is a common JMS gotcha...

http://activemq.org/java.lang.NoSuchMethodError

It could be due to you not having JMS 1.1 on your classpath. Try using JmsTemplate102 instead

whereur
Dec 30th, 2005, 11:59 PM
:confused: it doesnt effect....... i use the jms.jar from spring 2.0 m1,it should be a
* j2ee/jms.jar
- Java Message Service API 1.1 (java.sun.com/products/jms)

and jar from IBM MQ,also from eclipse to view ConnectionFactory,i saw the method of createConnection(). So it shouldnt be a problem of NoSuchMethod. I guess if it is the MQTopicConnectionFactory, itself will throw a AbstractMethodError when we call createConnection() and will work fine when we call createTopicConnection()

but i'm not sure about that and got no javadoc for MQTopicConnectionFactory.......

jstrachan
Jan 3rd, 2006, 10:05 AM
Are you sure that the MQ jar you have does implement JMS 1.1?

whereur
Jan 4th, 2006, 12:12 AM
maybe u r right,i will consult out MQ admin in a day or two,and first make out the JMS version MQ implemented.