第 39 章 组件接口

摘要

本章论述了如何实现组件接口。

39.1. 组件接口

概述

要实施 Apache Camel 组件,您必须实施 org.apache.camel.Component 接口。组件类型 的实例 提供自定义组件的入口点。也就是说,组件中的其他所有对象最终都可通过 component 实例访问图 39.1 “组件继承层次结构” 显示构成 组件 继承层次结构的相关 Java 接口和类。

图 39.1. 组件继承层次结构

组件继承层次结构

组件接口

例 39.1 “组件接口” 显示 org.apache.camel.Component 接口的定义。

例 39.1. 组件接口

package org.apache.camel;

public interface Component {
    CamelContext getCamelContext();
    void setCamelContext(CamelContext context);

    Endpoint createEndpoint(String uri) throws Exception;
}

组件方法

组件接口定义了以下方法:

  • getCamelContext()setCamelContext() 时间为这个组件所属的 CamelContext References。当您将组件添加到 CamelContext 时,会自动调用 setCamelContext() 方法。
  • createEndpoint() the factory 方法被调用,为这个组件创建 Endpoint 实例。uri 参数是端点 URI,其中包含创建端点所需的详细信息。