Spring JMS消息处理-不基于JNDI

        在Spring JMS消息处理-基于JNDI一文中,JMS和WebSphere MQ中间是有一层JNDI的,但如果在实际应用中不想或者不需要JDNI,又该怎么处理呢?

        下面还是一步步操作讲解吧。

一.准备环境

        打开下载下来的工程,找到batch下的Appconfig.txt文件,将其拷贝到WebSphere MQ的安装目录下的bin目录中(如C:\Program Files\IBM\WebSphere MQ\bin),再打开cmd窗口,运行batch文件夹中的 mqsetup.bat 文件(当然,如果在 path 环境变量中设置好 MQ 安装的 bin 文件夹,如IBM\WebSphere MQ\bin,就无需将Appconfig.txt文件拷贝到WebSphere MQ的安装目录下的bin目录中)。

        运行了批文件之后,打开 MQ Explorer 并检查已经创建的队列管理器和队列,请选择 Start -> Programs -> IBM WebSphere MQ -> WebSphere MQ Explorer。下图显示出示例应用程序 QueueManagerMQJMS.QManager 已经创建并正在运行。


        但不知为什么,发现MQJMS.QManager队列管理器没有侦听器和服务器通道,手动创建如下:



        最后,还有需要设置队列管理器MQJMS.QManager的通道认证记录设为“已禁用”。

 

二.修改JMS配置文件

        将工程的JMS配置文件修改成如下样子。

<?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>
    <!-- Spring JMS Queue Connection Factory -->
    <bean id="jmsQueueConnectionFactory" class="com.ibm.mq.jms.MQConnectionFactory">
        <property name="connectionNameList" value="bijian-PC(1416)" />
		<property name="CCSID" value="1051"/>
		<property name="queueManager" value="MQJMS.QManager"/>
		<property name="channel" value="DC.SVRCONN"/>
		<property name="transportType" value="1"/>
    </bean>

    <!-- JMS Queue Template -->
    <bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory">
            <ref bean="jmsQueueConnectionFactory"/>
        </property>
    </bean>
    
     <bean id="jmsSender" class="springexample.client.JMSSender">
      	<property name="jmsTemplate">
            <ref bean="jmsQueueTemplate"/>
        </property>
      </bean>
    
      <bean id="jmsReceiver" class="springexample.client.JMSReceiver">
      	<property name="jmsTemplate">
            <ref bean="jmsQueueTemplate"/>
        </property>
      </bean>
</beans>

 

三.运行验证

        运行SendMQSpringJMS文件,控制台输出如下信息:

SendMQSpringJMS started
Classpath loaded
SendMQSpringJMS end

        此时,打开MQ Explorer,将会看到消息已成功发送到队列中。


        再运行ReceiveMQSpringJMS,将消息从RequestResponseQueue队列中取出,运行后控制台输出如下信息:

ReceiveMQSpringJMS started
Classpath loaded
 Message Received -->JMSMessageID:ID:414d51204d514a4d532e514d616e61673f795a5720006502,text:This is a sample message
ReceiveMQSpringJMS end

        再打开MQ Explorer,将会看到消息已被取出,不在RequestResponseQueue队列中了。

猜你喜欢

转载自bijian1013.iteye.com/blog/2304181