国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

JMS

2019-11-14 21:44:17
字體:
供稿:網(wǎng)友
JMS - 基于JMS的RPC

現(xiàn)在試試通過JMS,在應(yīng)用程序之間發(fā)送消息。先看看sPRing提供的RPC方案(其實(shí)還有其他方案,只是沒見過誰用)。需要使用到這兩個(gè)類:·org.springframework.jms.remoting.JmsInvokerServiceExporter將bean導(dǎo)出為基于消息的服務(wù)·org.springframework.jms.remoting.JmsInvokerProxyFactoryBean讓客戶端調(diào)用服務(wù)

比較一下JmsInvokerServiceExporter和RmiServiceExporter:

package pac.testcase.jms;public interface JmsRmiService {    String doServe(String requestedNum);}

package pac.testcase.jms;import org.springframework.stereotype.Service;@Servicepublic class JmsRmiServiceImpl implements JmsRmiService {                                                                                                                                                         public String doServe(String content) {        System.out.println(content.concat(" has been requested!!"));        return "your message::".concat(content).concat(":::length:")+content.length();    }}

將這個(gè)pojo聲明為服務(wù),在spring配置文件中配置:

<bean id="serverService" class="org.springframework.jms.remoting.JmsInvokerServiceExporter"    p:serviceInterface="pac.testcase.jms.JmsRmiService"    p:service-ref="JmsRmiServiceImpl"></bean>

需將他設(shè)置為jms監(jiān)聽器,配置方法和一般的jmsMessageListener的配置相同:

<amq:connectionFactory id="jmsFactory" /><jms:listener-container    destination-type="queue"    connection-factory="jmsFactory"    concurrency="3"    container-type="simple">    <jms:listener  destination="sparta" ref="serverService"  /></jms:listener-container>

container-type有simple和default,根據(jù)不同的type也可以使用task-Executor,這里先簡(jiǎn)單記錄一下。

先啟動(dòng)jms broker再啟動(dòng):

new ClassPathxmlapplicationContext("classpath:applicationContext-*.xml").getBean(JmsRmiService.class);

client這邊我需要一個(gè)調(diào)用代理幫我去調(diào)用接口,也就是JmsInvokerProxyFactoryBean;配置如下:

<amq:connectionFactory id="connectionFactory" /><bean id="clientService" class="org.springframework.jms.remoting.JmsInvokerProxyFactoryBean"    p:serviceInterface="pac.test.jms.SenderRmiService"    p:connectionFactory-ref="connectionFactory"    p:queueName="sparta"/>

配置中的serviceInterface是client端中根據(jù)要調(diào)用的方法創(chuàng)建的一個(gè)接口。

main方法試著調(diào)用看看:

public static void main(String[] args) {    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");    SenderRmiService service = (SenderRmiService)context.getBean("clientService");    System.out.println(service.doServe("這才是斯巴達(dá)!!"));}

server端輸出:client端輸出:


上一篇:JMS

下一篇:CXF

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大渡口区| 英吉沙县| 霞浦县| 如皋市| 望城县| 甘孜| 无锡市| 北辰区| 堆龙德庆县| 洪泽县| 仁布县| 斗六市| 阜宁县| 晋中市| 长子县| 山东| 万山特区| 东兰县| 尚志市| 察隅县| 侯马市| 凯里市| 金坛市| 上蔡县| 长汀县| 库车县| 大石桥市| 黄浦区| 临西县| 同德县| 中西区| 防城港市| 遂溪县| 南丰县| 宣武区| 广西| 肇东市| 陆川县| 县级市| 且末县| 翁牛特旗|