請問我照著敲的consumer為什么獲取消息為null?萬分感謝!
consumer消息接收為Null值

producer消息發送是成功的

以下為consumer相關代碼:
1.執行consumer入口:
AppConsumer?{
????(String[]?args)?{
????????ApplicationContext?context?=?ClassPathXmlApplicationContext()}
}2.consumer.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"
? ? ? xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
? ?<!--導入公共配置-->
? ?<import resource="common.xml"/>
? ?<!--配置消息監聽器-->
? ?<bean id="consumerMessageListener" class="com.lee.jms.consumer.ConsumerMessageListener"/>
? ?<!--配置消息監聽容器,Spring提供的監聽容器,管理容器去自動連接ConnectionFactory,指定具體的消息Destination和消息監聽者-->
? ?<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
? ? ? ?<!--指定連接工廠,對應的是spring提供的SingleConnectionFactory-->
? ? ? ?<property name="connectionFactory" ref="connectionFactory"/>
? ? ? ?<!--指定目的地-->
? ? ? ?<property name="destination" ref="queueDestination"/>
? ? ? ?<!--指定消息監聽器-->
? ? ? ?<property name="messageListener" ref="consumerMessageListener"/>
? ?</bean>
</beans>
3.公共配置文件
<?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:context="http://www.springframework.org/schema/context"
? ? ? xsi:schemaLocation="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.xsd">
? ?<!--注解聲明-->
? ?<context:annotation-config/>
? ?<!--基礎配置 START-->
? ?<!--ActiveMQ為我們提供的ConnectionFactory-->
? ?<bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
? ? ? ?<property name="brokerURL" value="tcp://localhost:61616"/>
? ?</bean>
? ?<!--spring jms為我們提供的連接池-->
? ?<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
? ? ? ?<property name="targetConnectionFactory" ref="targetConnectionFactory"/>
? ?</bean>
? ?<!--一個隊列的目的地,點對點的-->
? ?<bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue">
? ? ? ?<!--該構造參數的值即該目的地隊列的隊列名-->
? ? ? ?<constructor-arg value="queue"/>
? ?</bean>
? ?<!--基礎配置 END-->
</beans>
4.消息監聽者
ConsumerMessageListener?MessageListener?{
????(Message?message)?{
????????TextMessage?textMessage?=?(TextMessage)message{
????????????System..println(+?textMessage.getText())}?(JMSException?e)?{
????????????e.printStackTrace()}
????}
}
2018-04-17
問題解決了,是因為在createMessage方法里面沒有把值傳過去