第 39 章 组件接口

摘要

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

39.1. 组件接口

概述

要实现 Apache Camel 组件,您必须实施 org.apache.camel.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 () mvapich- iwlReferences 此组件所属的 CamelContext。当您将组件添加到 CamelContext 时,会自动调用 setCamelContext ()。
  • createEndpoint () mvapich- iwlThe factory 方法被调用来为这个组件创建 Endpoint 实例。uri 参数是端点 URI,其中包含创建端点所需的详细信息。