JBoss ESB学习笔记9第八个ESB应用JMS Router.docx

上传人:b****6 文档编号:8506002 上传时间:2023-01-31 格式:DOCX 页数:10 大小:77.50KB
下载 相关 举报
JBoss ESB学习笔记9第八个ESB应用JMS Router.docx_第1页
第1页 / 共10页
JBoss ESB学习笔记9第八个ESB应用JMS Router.docx_第2页
第2页 / 共10页
JBoss ESB学习笔记9第八个ESB应用JMS Router.docx_第3页
第3页 / 共10页
JBoss ESB学习笔记9第八个ESB应用JMS Router.docx_第4页
第4页 / 共10页
JBoss ESB学习笔记9第八个ESB应用JMS Router.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

JBoss ESB学习笔记9第八个ESB应用JMS Router.docx

《JBoss ESB学习笔记9第八个ESB应用JMS Router.docx》由会员分享,可在线阅读,更多相关《JBoss ESB学习笔记9第八个ESB应用JMS Router.docx(10页珍藏版)》请在冰豆网上搜索。

JBoss ESB学习笔记9第八个ESB应用JMS Router.docx

JBossESB学习笔记9第八个ESB应用JMSRouter

JBossESB学习笔记9——第八个ESB应用JMSRouter

续上篇介绍了第七个ESB应用,本文介绍第八个ESB应用——JMSRouter。

1概述

该实例演示如何配置JMSRouteraction类来实现消息的路由和转发,以及JMSCorrelationID在ESB中的使用。

2新建ESB工程

操作过程略。

3ESB配置

3.1创建消息队列

本例中只用到了四个消息队列,其中:

jmsrouterRequestGw:

用于接收外部消息

jmsrouterRequestEsb:

用于接收ESB内部消息

jmsrouterRouteTo:

用于接收JMSRouter转发的消息

jmsrouterReplyTo:

用于客户端转发消息

如下所示:

Xml代码

1

xmlversion="1.0"encoding="UTF-8"?

>

2

3

service=Queue,name=jmsrouterRequestGw"xmbean-dd="xmdesc/Queue-xmbean.xml">

4

5jboss.messaging:

service=ServerPeer

6

7jboss.messaging:

service=PostOffice

8

9

service=Queue,name=jmsrouterRequestEsb"xmbean-dd="xmdesc/Queue-xmbean.xml">

10

11jboss.messaging:

service=ServerPeer

12

13jboss.messaging:

service=PostOffice

14

15

service=Queue,name=jmsrouterRouteTo"xmbean-dd="xmdesc/Queue-xmbean.xml">

16

17jboss.messaging:

service=ServerPeer

18

19jboss.messaging:

service=PostOffice

20

21

22

23

24

25

26

service=Queue,name=jmsrouterReplyTo"xmbean-dd="xmdesc/Queue-xmbean.xml">

27

28jboss.messaging:

service=ServerPeer

29

30jboss.messaging:

service=PostOffice

31

32

3.2定义Provider

这里将定义两个JMSProvider,分别用于监听外部消息和ESB消息,内容如下:

Xml代码

33

34

35name="JBossMessaging">

36

37

38dest-type="QUEUE"/>

39

40

41

42dest-type="QUEUE"/>

43

44

45

3.3定义Service

Xml代码

46

47name="JmsRouterService">

48

49

50

3.4定义Listener

这里定义两个listener,分别用于监听外部消息和ESB消息,内容如下:

Xml代码

51

52

53name="jmsrouterGwListener"/>

54

55name="jmsrouterEsbListener"/>

56

3.5配置Action

Xml代码

57

58

59name="printMessage">

60

61

62

63

64name="routerToReplyQueue">

65

66

67value="ConnectionFactory"/>

68

69

70

71

72

73

74value="propertyValue"/>

75

76

配置说明:

这里定义了两个action,第一个是JBossESB提供的action类,用于打印输出消息内容。

第二个action是一个JMS消息路由器,它将接收到的消息转发到消息队列queue/jmsrouterRouteTo,客户端可从该消息队列获取经转发后的消息。

JMSRouter的其他属性说明如下,摘自JBossESBAPI,英文比较简单,懒得翻译了。

unwrap:

'true'willextractthemessagepayloadfromtheMessageobjectbeforesending.false(default)willsendtheserializedMessageobject.

jndi-context-factory:

TheJNDIcontextfactorytouse.Defaultis"org.jnp.interfaces.NamingContextFactory"

jndi-URL:

TheJNDIURLtouse.Defaultis"127.0.0.1:

1099"

jndi-pkg-prefix:

TheJNDInamingpackageprefixestouse.Defaultis"org.jboss.naming:

org.jnp.interfaces".

connection-factory:

ThenameoftheConnectionFactorytouse.Defaultis"ConnectionFactory".

persistent:

TheJMSDeliveryMode.'true'or'false'.Defaultis"true".

priority:

TheJMSPrioritytobeused.Defaultis"javax.jms.Message.DEFAULT_PRIORITY"

time-to-live:

TheJMSTime-To-Livetobeused.Defaultis"javax.jms.Message.DEFAULT_TIME_TO_LIVE"

security-principal:

SecurityprincipalusewhencreatingtheJMSconnection.

security-credential:

ThesecuritycredentialstousewhencreatingtheJMSconnection.

property-strategy:

TheimplementationoftheJMSPropertiesSetterinterface,ifoverridingthedefault.

message-prop:

Propertiestobesetonthemessageareprefixedwith"message-prop-".

jndi-prefixes:

Acommaseparatedstringofprefixes.PropertiesthathavetheseprefixeswillbeaddedtotheJNDIenvironment.

org.xyz.propertyName:

Ajndienvironmentpropertythatwillbeaddedtothejndienvironmentiftheprefix'org.xyz'wasspecifiedinthejndi-prefixeslist.

3.6配置部署文件

部署依赖文件deployment.xml内容如下:

Xml代码

77

78jboss.esb.quickstart.destination:

service=Queue,name=jmsrouterRequestGw

79

80jboss.esb.quickstart.destination:

service=Queue,name=jmsrouterRequestEsb

81

82jboss.esb.quickstart.destination:

service=Queue,name=jmsrouterRouteTo

83

84

3.7部署ESB

将整个工程导出成一个ESB文件,并保存至JBossESBServer的部署目录下,启动JBossESBServer即可。

4ESB客户端

4.1新建Java工程

这里略去操作过程以及添加所需要的Jar包,具体操作过程可参考第一个ESB实例说明。

4.2客户端实现

Java代码

85/***********************************************************************

86*

ProjectName:

helloworldclient

87*

FileName:

com.thu.afa.esb.jbossesb.client.JmsRouterClient.java

88*

Copyright:

Copyright(c)2010

89*

Company:

90***********************************************************************/

91packagecom.thu.afa.esb.jbossesb.client;

92

93importjava.util.Calendar;

94importjava.util.Properties;

95

96importjavax.jms.Connection;

97importjavax.jms.ConnectionFactory;

98importjavax.jms.Destination;

99importjavax.jms.Message;

100importjavax.jms.MessageConsumer;

101importjavax.jms.MessageProducer;

102importjavax.jms.ObjectMessage;

103importjavax.jms.QueueSession;

104importjavax.jms.Session;

105importjavax.jms.TextMessage;

106importjavax.naming.Context;

107importjavax.naming.InitialContext;

108

109/**

110*

ClassName:

JmsRouterClient

111*

Description:

112*@authorAfa

113*@date2010-9-12

114*@version1.0

115*/

116publicclassJmsRouterClient

117{

118privateConnectionconnection;

119privateSessionsession;

120privateDestinationgatewayDestination;

121privateDestinationresponseDestination;

122privateDestinationreplyToDestination;

123privateStringcorrelationId;

124

125privateStringpropertyKey="MyProperty";

126

127publicvoidsetupConnection(Stringdestination)throwsException

128{

129Propertiesproperties=newProperties();

130properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");

131properties.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:

org.jnp.interfaces");

132properties.put(Context.PROVIDER_URL,"jnp:

//127.0.0.1:

1099");

133InitialContextcontext=newInitialContext(properties);

134

135ConnectionFactoryfactory=(ConnectionFactory)context.lookup("ConnectionFactory");

136connection=factory.createConnection();

137gatewayDestination=(Destination)context.lookup("queue/jmsrouterRequestGw");

138responseDestination=(Destination)context.lookup(destination);

139replyToDestination=(Destination)context.lookup("queue/jmsrouterReplyTo");

140session=connection.createSession(false,QueueSession.AUTO_ACKNOWLEDGE);

141connection.start();

142

143System.out.println("ConnectionStarted");

144}

145

146publicvoidstop()throwsException

147{

148if(connection!

=null)connection.stop();

149if(session!

=null)session.close();

150if(connection!

=null)connection.close();

151}

152

153publicvoidsendAMessage(Stringtext)throwsException

154{

155correlationId="QuickstartId["+Calendar.getInstance().get(Calendar.SECOND)+"]";

156MessageProducerproducer=session.createProducer(gatewayDestination);

157ObjectMessageobjectMsg=session.createObjectMessage(text);

158objectMsg.setJMSCorrelationID(correlationId);

159objectMsg.setJMSReplyTo(replyToDestination);

160objectMsg.setStringProperty(propertyKey,"Mypropertyvalue");

161producer.send(objectMsg);

162System.out.println("SentmessagewithCorrelationID:

"+correlationId);

163System.out.println("");

164producer.close();

165}

166

167publicvoidreceiveMessage()throwsException

168{

169MessageConsumerconsumer=session.createConsumer(responseDestination,"JMSCorrelationID='"+correlationId+"'");

170Messagemessage=consumer.receive();

171System.out.println("Receivedfrom"+responseDestination+":

");

172System.out.println("\t[JMSMessageID:

"+message.getJMSMessageID()+"]");

173System.out.println("\t[JMSCorrelelationID:

"+message.getJMSCorrelat

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 实习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1