搜索

第 40 章 端点接口

download PDF

摘要

本章论述了如何实施 Endpoint 接口,这是实施 Apache Camel 组件中的基本步骤。

40.1. 端点接口

概述

org.apache.camel.Endpoint 类型的实例封装了端点 URI,它也充当 消费者、Producer Exchange 对象的工厂。实施端点的方法有三种:

  • Event-driven
  • 计划轮询
  • 轮询

这些端点实施模式与对应的模式补充,用于实施使用者","-abrtsee 第 41.2 节 “实现使用者接口”

图 40.1 “端点继承层次结构” 显示构成 端点 继承层次结构的相关 Java 接口和类。

图 40.1. 端点继承层次结构

端点继承层次结构

Endpoint 接口

例 40.1 “端点接口” 显示 org.apache.camel.Endpoint 接口的定义。

例 40.1. 端点接口

package org.apache.camel;

public interface Endpoint {
    boolean isSingleton();

    String getEndpointUri();

    String getEndpointKey();

    CamelContext getCamelContext();
    void setCamelContext(CamelContext context);

    void configureProperties(Map options);

    boolean isLenientProperties();

    Exchange createExchange();
    Exchange createExchange(ExchangePattern pattern);
    Exchange createExchange(Exchange exchange);

    Producer createProducer() throws Exception;

    Consumer createConsumer(Processor processor) throws Exception;
    PollingConsumer createPollingConsumer() throws Exception;
}

端点方法

Endpoint 接口定义了以下方法:

  • 代表Singleton() InventoryService-abrtRe returns true,如果您要确保每个 URI 映射到 CamelContext 中的一个端点。当此属性为 true 时,指向路由中相同 URI 的多个引用始终引用 单个 端点实例。另一方面,当此属性为 false 时,对路由中同一 URI 的多个引用指的是 不同的 端点实例。每次引用路由中的 URI 时,都会创建一个新的端点实例。
  • getEndpointUri() abrt- the endpointRe 返回此端点的端点 URI。
  • 在注册端点时,由 org.apache.camel.spi.LifecycleStrategygetEndpointKey() Infoblox- InfobloxUsed by org.apache.camel.spi.LifecycleStrategy。
  • getCamelContext() 进行对该端点所属的 CamelContext 实例的引用。
  • 设置此端点 所属的 CamelContext Set。
  • 配置Properties() >_<-jaxbStores 是参数映射的副本,用于在创建新 Consumer 实例时注入参数。
  • isLenientProperties() 时间为 true,表示允许 URI 包含未知参数(即,不能在 Endpoint 或 Consumer 类上注入的参数)。通常,应实施此方法来返回
  • 使用以下变体 创建Exchange() 3.10.0-- theAn overloaded 方法:

    • Exchange createExchange() Infoblox-jaxbCreates a new exchange pattern 设置。
    • Exchange createExchange(ExchangePattern pattern) abrt-abrtCreates a new exchange instance with specified exchange pattern.
    • Exchange createExchange(Exchange exchange) the given exchange 参数到此端点所需的交换类型。如果给定交换尚未正确类型,则此方法将其复制到正确类型的新实例中。DefaultEndpoint 类中提供了此方法的默认实现。
  • createProducer() >_<->_<Factory 方法 用于创建新的 Producer 实例。
  • createConsumer() 10.10.10.2-CustomizationFactory 方法,以创建新的事件驱动的消费者实例。processor 参数是对路由中的第一个处理器的引用。
  • 创建PollingConsumer()10.10.10.2 ->_<Factory 方法,以创建新的轮询消费者实例。

端点单例

为了避免不必要的开销,最好为具有相同 URI(通过 CamelContext)的所有端点创建一个端点实例。您可以通过实施 isSingleton() 来返回 true 来强制实施此条件。

注意

在这个上下文中,同一 URI 意味着,使用字符串相等时两个 URI 相同。在原则上,可以有两个等效的 URI,虽然由不同的字符串表示。在这种情况下,URI 不会像一样对待。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.