问题1,AMQ 4的openWireFormat与AMQ 5的不兼容型问题。
AMQ 4的客户端与AMQ 5的服务端在初次通信时,通过比对自身openWireFormat与AMQ 5发送过来的openWireFormat两者的版本,来确定AMQ 4的客户端选用哪个版本的openWire。现在AMQ 4采用两者之间的最大值,这会造成AMQ 4去使用自身不存在的较高版本的openWire。代码如下:
org.apache.activemq.openwire.OpenWireFormat.renegociatWireFormat 569th line
public void renegociatWireFormat(WireFormatInfo info) throws IOException {
if( preferedWireFormatInfo==null )
throw new IllegalStateException("Wireformat cannot not be renegociated.");
this.setVersion(Math.max(preferedWireFormatInfo.getVersion(), info.getVersion()) );
}
应该采用两者之间的最小值,代码如下:
public void renegociatWireFormat(WireFormatInfo info) throws IOException {
if( preferedWireFormatInfo==null )
throw new IllegalStateException("Wireformat cannot not be renegociated.");
this.setVersion(min(preferedWireFormatInfo.getVersion(), info.getVersion()) );
}
问题1,JMS,ActiveMQ的发送消息原理。
比如,发送者发送一个TextMessage对象通过JMS中间件发送到JMS server,JMS server如何拿到这个TextMessage,TextMessage在整个流程中做了哪些处理。
TextMessage的内部处理 (针对TCP OpenFire 协议)
org.apache.activemq.openwire.v1.MessageMarshaller
org.apache.activemq.openwire.v1.BaseCommandMarshaller
这两个类完成Object到bytes的转换。
ActiveMQ 将TextMessage里的text转成byte流,使用socket方式发送二进制流。其中会调用:
org.apache.activemq.command.ActiveMQTextMessage.beforeMarshall(WireFormat wireFormat)
TextMessage中的text转成byte流会调用其中下面一个方法
org.apache.activemq.openwire.v1.BaseDataStreamMarshaller
protected void tightMarshalByteSequence2(ByteSequence data, DataOutput dataOut, BooleanStream bs)
throws IOException {
if (bs.readBoolean()) {
dataOut.writeInt(data.getLength());
dataOut.write(data.getData(), data.getOffset(), data.getLength());
}
}
ActiveMQ 接收时将 bytes二进制流转成ByteSequence对象。会调用下面的方法:
ActiveMQ将ByteSequence放入TextMessage的content,其内容会作为ActiveMQTextMessage.getText() 中的输入源的内容。
org.apache.activemq.command.ActiveMQTextMessage.getText()
org.apache.activemq.openwire.v1.BaseDataStreamMarshaller.tightUnmarshalByteSequence(DataInput dataIn, BooleanStream bs)
protected ByteSequence tightUnmarshalByteSequence(DataInput dataIn, BooleanStream bs) throws IOException {
ByteSequence rc = null;
if (bs.readBoolean()) {
int size = dataIn.readInt();
byte[] t = new byte[size];
dataIn.readFully(t);
return new ByteSequence(t, 0, size);
}
return rc;
}
分享到:
相关推荐
JMS 是接口,相当于jdbc ,要真正使用它需要某些厂商进行实现 ,即jms provider 常见的jms provider 有 ActiveMQ JBoss 社区所研发的 HornetQ (在jboss6 中默认即可以使用它) jbossmq 等 在jboss 5 之前好像...
MQ简介、JMS基础、ActiveMQ基础应用、ActiveMQ高级特性
基于Spring+JMS+ActiveMQ+Tomcat,我使用的版本情况如下所示:Spring 3.2.0,ActiveMQ 5.4.3,Tomcat 6.0.43。本例通过详细的说明和注释,实现消息服务的基本功能:发送与接收。Spring对JMS提供了很好的支持,可以...
ActiveMQ 是Apache出品,最流行的,能力强劲的开源jms...ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久的事情了,但是JMS在当今的J2EE应用中间仍然扮演着特殊的地位。
sprin jms activemq 测试 两个 一个是jndi 一个是activemq
java JMS模拟ActiveMQ代理服务器并实现消息收发,这里是工程源码,已经过测试,可以直接使用。
利用ActiveMQ中间件发送JMS消息的例子
SUN JMS 教程 APACHE ACTIVEMQ 教程
spring整合JMS-居于ActiveMQ实现
JMS的实现ActiveMQ的演示代码,直接放在工程下即可运行。
详细内容: SpringJMS整合ActiveMQ.doc 详细说明文档 apache-activemq-5.8.0-bin.zip ActiveMQ安装包 JMSTest.rar MyEclipse8.5下web工程
找了不少关于JMS方面的资料,ActiveMQ方面的中文书籍挺少的,讲的都不是很系统,这个是在博客上收集的,讲的还是挺不错的,希望能够帮助你
Apache ActiveMQ JMS实现
activemq-all-5.9.0.jar jms的一个很好实现
<a href=http://activemq.apache.org/version-5-getting-started.html >http://activemq.apache.org/version-5-getting-started.html</a> <a href=http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html>...
activeMQ JMS 3种创建方式 公共方式 QUEUE TOPIC
简单消息服务-httpsqs 博文链接:https://sosuny.iteye.com/blog/509846
jms测试程序,将tomcat和activeMq整合在一起做的一个发送接受的发布订阅的例子
JMS学习指导讲解PPT,ActiveMQ学习PPT 以及对JMS实现的研究