Avro を使用すると、json のような形式を使用してメッセージタイプとプロトコルを定義し、指定したタイプとメッセージの Java コードを生成できます。スキーマがどのように見えるかの例を以下に示します。
			
{"namespace": "org.apache.camel.avro.generated",
 "protocol": "KeyValueProtocol",
 "types": [
     {"name": "Key", "type": "record",
      "fields": [
          {"name": "key",   "type": "string"}
      ]
     },
     {"name": "Value", "type": "record",
      "fields": [
          {"name": "value",   "type": "string"}
      ]
     }
 ],
 "messages": {
     "put": {
         "request": [{"name": "key", "type": "Key"}, {"name": "value", "type": "Value"} ],
         "response": "null"
     },
     "get": {
         "request": [{"name": "key", "type": "Key"}],
         "response": "Value"
     }
 }
} 
{"namespace": "org.apache.camel.avro.generated",
 "protocol": "KeyValueProtocol",
 "types": [
     {"name": "Key", "type": "record",
      "fields": [
          {"name": "key",   "type": "string"}
      ]
     },
     {"name": "Value", "type": "record",
      "fields": [
          {"name": "value",   "type": "string"}
      ]
     }
 ],
 "messages": {
     "put": {
         "request": [{"name": "key", "type": "Key"}, {"name": "value", "type": "Value"} ],
         "response": "null"
     },
     "get": {
         "request": [{"name": "key", "type": "Key"}],
         "response": "Value"
     }
 }
} 
Copy to Clipboard 
Copied! 
 
   
 
 
Toggle word wrap 
Toggle overflow 
 
  
    
       
    
       
   
 
 
 
package org.apache.camel.avro.reflection;
public interface KeyValueProtocol {
    void put(String key, Value value);
    Value get(String key);
}
class Value {
    private String value;
    public String getValue() { return value; }
    public void setValue(String value) { this.value = value; }
} 
package org.apache.camel.avro.reflection;
public interface KeyValueProtocol {
    void put(String key, Value value);
    Value get(String key);
}
class Value {
    private String value;
    public String getValue() { return value; }
    public void setValue(String value) { this.value = value; }
} 
Copy to Clipboard 
Copied! 
 
   
 
 
Toggle word wrap 
Toggle overflow