---
title: "Camel - Bean Integration"
author: "alloyer"
date: "2009-04-23T22:05:20Z"
tags: []
categories: ["企业架构"]
slug: "camel-bean-integration"
draft: false
lastmod: "2009-04-23T22:10:32Z"
id: 373631
url: "https://alloyer.iteye.com/blog/373631"
---

原文地址： [http://camel.apache.org/bean-integration.html](http://camel.apache.org/bean-integration.html)

 

Camel支持多种方式的对beans和POJO类的集成。

 

**1）Bean绑定 （Bean Binding）**

当Camel调用一个Bean方法时，不管是通过Bean组件，Spring远程服务（Spring Remoting）或者POJO Consuming，Bean绑定机制都会用于指定调用的具体方法（在没有显式指定的情况下），并确定怎么将消息绑定到具体参数，这个过程可能使用参数绑定标注（Parameter Binding Annotations）实现。

**2）标注 （Annotations）**

如果一个Bean是由Spring XML定义，或者使用Spring 2.5的组件扫描机制（component scanning mechanism）扫描得到，并且其中使用了&lt;camelContext&gt;或CamelBeanPostProcessor，那么我们可以借助于大量Camel标注，来提供一些服务支持，比如注入资源或者生产、消息或路由消息。

- POJO Consuming 用于消费消息，也有时会路由消息；
- POJO Producing 用于简化从POJO类中生产Camel消息的过程；
- RecipientList Annotation 用于从POJO类方法中创建接收列表（Recipient List）；
- Bean Injection 用于将Camel相关的资源注入到POJO类中；
- Using Exchange Pattern Annotation 描述了模型标注（pattern annotations）怎样借助于Spring远程服务或POJO Producing改变方法调用行为的。

**3）Spring远程服务 （Spring Remoting）**

Camel支持Spring远程服务提供组件，它可以使用Camel作为底层传输机制。这种方式的好处是我们可以使用任意的Camel传输组件进行beans间的通信。同样意味着我们可以在beans间使用基于内容的路由器（Content Based Router）和其他企业集成模式（Enterprise Integration Patterns）；尤其是使用消息转换器（Message Translator）来转换传输中的消息的样式，甚至为消息添加各种各样的头等等。

**4）Bean组件 （Bean Component）**

Bean组件支持对一个Java接口创建代理；而实现方式仅仅需要发送一条包含有BeanInvocation信息的消息到Camel接入点上（endpoint）。

而后，服务端的实现会处理这条消息，使用Bean绑定来把消息绑定到调用方法上，绑定的过程会传入相应的参数。