按照老师的视频,在使用queue模式时正常;但是改成topic时 报了错;
我在这个过程中修改了一下几处:
1.在common.xml中增加了这个个
<!--主题 订阅模式--> <bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTempTopic"> <constructor-arg value="imooc-topic"/> </bean>
2.在conmesur.xml里将queueDestination 换成topicDestination
<!--配置消息容器--> <bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="connectionFactory"/> <!--<property name="destination" ref="queueDestination"/>--> <property name="destination" ref="topicDestination"/> <property name="messageListener" ref="consumerMessageListener"/> </bean>
3.在生成消息的实现
ProducerServiceImpl
类里将name换掉
// 这个是队列模式 // @Resource(name = "queueDestination") // 这个是订阅模式 @Resource(name = "topicDestination") private Destination destination;
结果报错为:
信息: Established shared JMS Connection: ActiveMQConnection {id=ID:IAADW5N2T6RHKNQ-51511-1568724152466-1:1,clientId=null,started=false} Exception in thread "main" org.springframework.jms.InvalidDestinationException: Cannot publish to a deleted Destination: temp-topic://imooc-topic; nested exception is javax.jms.InvalidDestinationException: Cannot publish to a deleted Destination: temp-topic://imooc-topic at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:285) at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169) at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:497) at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:569) at com.imooc.jms.producer.impl.ProducerServiceImpl.sendMessage(ProducerServiceImpl.java:26) at com.imooc.jms.producer.APPProducer.main(APPProducer.java:11) Caused by: javax.jms.InvalidDestinationException: Cannot publish to a deleted Destination: temp-topic://imooc-topic
有没有遇到这个问题,是我哪里没有写好,请指出来,谢谢!!
你注册错了类
org.apache.activemq.command.ActiveMQTempTopic改为
org.apache.activemq.command.ActiveMQTopic
你看一下在你的ProducerServiceImpl中有没有注入
@Resource(name = "topicDestination")