activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From czy11421 <czy11...@gmail.com>
Subject Re: Spring JMS : can't receive message ?
Date Mon, 21 Sep 2009 18:22:46 GMT
Hi, Rafal,
Thanks for your reply. The bug is in the spring bean configuration file.

<bean id="defaultDestination" class="org.apache.activemq.command.ActiveMQQueue">

should be 

<bean id="defaultDestination" class="org.apache.activemq.command.ActiveMQTopic">


Sorry for this low-level mistakes. 

Regards.
Edward




Rafal Rusin wrote:
> Do you have broker running at tcp://localhost:61616? I don't see an
> entry for it in your spring config.
> If not, consider adding something like this:
>       <amq:broker id="brokerLocal" brokerName="localBroker">
>          <amq:persistenceAdapter>
>             <amq:amqPersistenceAdapter directory="file:./data/amq-local"/>
>          </amq:persistenceAdapter>
>           <amq:transportConnectors>
>           <amq:transportConnector uri="tcp://localhost:61616" />
>           </amq:transportConnectors>
>          <amq:networkConnectors>
>          </amq:networkConnectors>
>         </amq:broker>
>
> Regards,
>
> 2009/9/21 czy11421 <czy11421@gmail.com>:
>   
>> Hi, All,
>>
>> I have tried to write a JMS with Spring, but failed. no compiler error, no
>> runtime error, just wait infinitely, can't receive message, but I am sure
>> the ActiveMQ is publishing data in 'STOCKS.SUNW' topic.
>>
>> Anybody has some clues ? Thanks.
>>
>> ///////////////////////// MessageReceiver.java /////////////////////////
>> import javax.jms.JMSException;
>> import javax.jms.Message;
>> import javax.jms.TextMessage;
>>
>> import org.springframework.jms.core.JmsTemplate;
>>
>> public class MessageReceiver {
>>   private JmsTemplate jmsTemplate;
>>   public MessageReceiver() {
>>   }
>>
>>   public void setJmsTemplate(JmsTemplate jmsTemplate) {
>>       this.jmsTemplate = jmsTemplate;
>>   }       public void receiveMessage() {
>> System.out.println("receiving");
>>             Message message = jmsTemplate.receive(); // wait infinitely
>>       System.out.println("Message="+message); // never reach here
>>       TextMessage textMessage = null;
>>       if (message instanceof TextMessage) {
>>           textMessage = (TextMessage) message;
>>           //....
>>       }
>>   }
>> }
>>
>> /////////////////////////////////
>>
>> //////////////////////// spring beans xml /////////////////////
>> <?xml version="1.0"?>
>>
>> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
>> "http://www.springframework.org/dtd/spring-beans.dtd">
>>
>> <beans>
>>   <bean id="activeMQConnectionFactory"
>> class="org.apache.activemq.ActiveMQConnectionFactory">
>>       <property name="brokerURL" value="tcp://localhost:61616" />
>>   </bean>
>>
>>   <bean id="sampleJmsTemplate"
>> class="org.springframework.jms.core.JmsTemplate">
>>       <property name="connectionFactory" ref="activeMQConnectionFactory" />
>>       <property name="defaultDestination">
>>           <ref bean="defaultDestination" />
>>       </property>
>>             <property name="receiveTimeout">
>>     <value>3000000</value>
>>   </property>
>>         </bean>
>>
>>   <bean id="messageReceiver" class="com.MessageReceiver">
>>       <property name="jmsTemplate" ref="sampleJmsTemplate" />
>>   </bean>
>>     <bean id="defaultDestination"
>> class="org.apache.activemq.command.ActiveMQQueue">
>>       <constructor-arg value="STOCKS.SUNW" />
>>   </bean>
>> </beans>
>>
>> /////////////////////////// main class /////////////////////////
>>
>> import org.springframework.context.ApplicationContext;
>> import org.springframework.context.support.ClassPathXmlApplicationContext;
>>
>> public class Test {
>>
>>   public static void main(String[] args) throws Exception {
>>       ApplicationContext ctx = new
>> ClassPathXmlApplicationContext("appContext.xml");
>>
>>       MessageReceiver receiver = (MessageReceiver)
>> ctx.getBean("messageReceiver");
>>
>>       receiver.receiveMessage();
>>
>>   }
>>
>> }
>>
>>     
>
>
>
>   


Mime
View raw message