本文主要介紹weblogic jms的配置,包括JMS 服務器和JMS 模塊(連接工廠、隊列、遠程 SAF 上下文、SAF 導入目的地、SAF 錯誤處理)的配置;并在Spring環境下進行消息的監聽及發送;為了更多的使用webloigc jms的功能,發送的隊列使用saf配置的遠程weblogic jms隊列(兩邊的weblogic版本須一致),當然本地也是可以的。本文中demo所使用的軟件環境為:weblogic 10.3.6.0、spring5.1.2.RELEASE
注:saf配置的遠程隊列只能發送消息,不能監聽消息。
1、weblogic jms配置
1.1、配置JMS 服務器
注:需配置持久性存儲,沒有就創建一個
1.2、配置JMS 模塊
下面的功能都是在JMS 模塊中配置;連接工廠、隊列、遠程 SAF 上下文、SAF 導入目的地、SAF 錯誤處理
這里就不一一截圖配置過程了,按頁面提示配置就行;配置結果如下
連接工廠需設置jndi,程序里會用到
SAF 遠程上下文配置的遠程地址及用戶名密碼信息
SAF 導入目的地配置的遠程的隊列消息及對應到本地的jndi
SAF 錯誤處理程序配置錯誤處理策略屬性,選配
隊列需設置jndi,程序里會用到
SAF 導入目的地配置的隊列消息如下:
點擊隊列名稱:
本地 JNDI 名稱程序里會用到,向該jndi發送消息實際會發送到遠程的隊列里。
2、spring配置
增加applicationContext-jms.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" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:security="http://www.springframework.org/schema/security" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.3.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd"> <bean class="org.springframework.jndi.JndiTemplate"> <property name="environment"> <props> <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop> <prop key="java.naming.provider.url">t3://10.39.196.10:7001</prop> <prop key="java.naming.security.principal">weblogic</prop> <prop key="java.naming.security.credentials">weblogic1</prop> </props> </property> </bean> <bean class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiTemplate" ref="jndiTemplate" /> <property name="proxyInterface" value="javax.jms.ConnectionFactory" /> <property name="jndiName" value="ConnectionFactory-test" /> </bean> <bean class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="testQueueSend" /> <property name="jndiTemplate" ref="jndiTemplate" /> </bean> <bean class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="testQueue" /> <property name="jndiTemplate" ref="jndiTemplate" /> </bean> <bean class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="jmsConnectionFactory" /> </bean> <bean class="com.inspur.demo.jms.Sender"> </bean> <task:scheduled-tasks> <task:scheduled ref="sender" method="hello" cron="0/5 * * * * ?" /> </task:scheduled-tasks> <bean class="com.inspur.demo.jms.Receiver"> </bean> <bean class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="jmsConnectionFactory" /> <property name="destination" ref="testQueueReceive" /> <property name="messageListener" ref="receiver" /> <property name="autoStartup" value="true" /> </bean></beans>
新聞熱點
疑難解答
圖片精選