Apache Qpid : AMQPVersion.1
This page last changed on Oct 20, 2006 by kpvdr.
Back to Multiple AMQP Version Support Approach to adding support for multiple AMQP versions into the brokerI had intended to follow approach 2 below, however after some brainstorming, a better and more efficient approach has been proposed. The following is a summary of the possible courses of action. Kim van der Riet 1. Present status: No AMQP version discrimination.ADVANTAGES:a. Nothing changes in the code, and everyone keeps doing what they are already doing... DISADVANTAGES: a. There is no easy way of hosting more than one version of AMQP at the same time in the broker.
2. Initial approach to solving problem: Namespace discrimination. a. In this approach, each version of the protocol is generated as before, but into a namespace unique to that version. +--------+ +---------+ +------------+ +---------+ | Broker | | Method | | Generated | | Encoder | | code | <---> | Handler | <---> | MethodBody | <---> | Decoder | | | | classes | | classes | | classes | +--------+ +---------+ +------------+ +---------+ 1 1 set n sets, 1/version 1 or possibly more ADVANTAGES: a. Allows multiple AMQP versions to be used simultaneously in the broker. DISADVANTAGES a. Code duplication: Since in most AMQP version changes, 90+% of the specification remains unchanged, the generated classes will contain mostly exact duplicates from version to version. 3. Revised approach: Intelligent generationa. In this approach, the limitations of the existing XSLT code generation are removed. We assume that we can compare one version of the AMQP specification to another, and generate code for the latest version and code to handle only the differences between the latest and each earlier version. To achieve this, we conceptually refactor the XML specification file so that the version information is contained inside the elements instead of outside them. Then each version of the spec is added cumulatively to create a complete map of the specification. For example, assume the following simple example: AMQP 1.0: Basic.Consume(Ticket ticket, Queue queue, ConsumerTag consumer_tag, NoLocal no_local, NoAck no_ack, bool exclusive, bool nowait); AMQP 1.2: Basic.Consume(Ticket ticket, Queue queue, ConsumerTag consumer_tag, int no_ack, bool exclusive, bool nowait, NoLocal no_local, int priority); would be refactored to something like (abbreviated): <AMQP> <class name="Basic> <version major="1" minor="0" num="60"/> <version major="1" minor="2" num="50"/> <method name="Consume"> <version major="1" minor="0" num="20"/> <version major="1" minor="2" num="20"/> <field name="ticket" type="Ticket"> <version major="1" minor="0" num="0"/> <version major="1" minor="2" num="0"/> </field> <field name="queue" type="Queue"> <version major="1" minor="0" num="1"/> <version major="1" minor="2" num="1"/> </field> <field name="consumer_tag" type="ConsumerTag"> <version major="1" minor="0" num="2"/> <version major="1" minor="2" num="2"/> </field> <field name="no_local" type="NoLocal"> <version major="1" minor="0" num="3"/> <version major="1" minor="2" num="6"/> </field> <field name="no_ack" type="NoAck"> <version major="1" minor="0" num="4"/> </field> <field name="no_ack" type="int"> <version major="1" minor="2" num="3"/> </field> <field name="exclusive" type="bool"> <version major="1" minor="0" num="5"/> <version major="1" minor="2" num="4"/> </field> <field name="nowait" type="bool"> <version major="1" minor="0" num="6"/> <version major="1" minor="2" num="5"/> </field> <field name="priority" type="int"> <version major="1" minor="2" num="7"/> </field> </method> </class> </AMQP> This would result in the generation of only a single MethodBody class, and since all instances of this class are version-aware, each knows how to handle calls for a given version (pseudo-java): class BasicConsumeBody extends AMQPMethodBody { public int _major, _minor; public BasicConsumeBody(int major, int minor) {_major = major; _minor = minor;} public int getAMQPClass(){if (major == 1 && minor == 0) return 60; else return 50;} // the class number has changed! public int getAMQPMethod(){return 20;} public Ticket getTicket() {...} public Queue getQueue() {...} public ConsumerTag getConsumerTag() {...} public NoLocal getNoLocal() {....} public T getNoAck(Class<T>) {if (major == 1 && minor == 0)...} // NoAck changes type public boolean getExclusive() {...} public boolean getNoWait() {...} public int getPriority() throws Exception {if (major != 1 || minor != 2) throw...} // Priority field is in 1.2 only // also for setXXX() methods... } Static functions would require major and minor to be passed to be able to operate. ADVANTAGES a. Only a single class for each method body DISADVANTAGES a. Complexity... |
Document generated by Confluence on Apr 22, 2008 02:47 |