이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 46. Endpoint Interface


Abstract

This chapter describes how to implement the Endpoint interface, which is an essential step in the implementation of a Apache Camel component.

46.1. The Endpoint Interface

Overview

An instance of org.apache.camel.Endpoint type encapsulates an endpoint URI, and it also serves as a factory for Consumer, Producer, and Exchange objects. There are three different approaches to implementing an endpoint:
  • Event-driven
  • scheduled poll
  • polling
These endpoint implementation patterns complement the corresponding patterns for implementing a consumer—see Section 47.2, “Implementing the Consumer Interface”.
Figure 46.1, “Endpoint Inheritance Hierarchy” shows the relevant Java interfaces and classes that make up the Endpoint inheritance hierarchy.

Figure 46.1. Endpoint Inheritance Hierarchy

The Endpoint interface

Example 46.1, “Endpoint Interface” shows the definition of the org.apache.camel.Endpoint interface.

Example 46.1. Endpoint Interface

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;
}
Copy to Clipboard Toggle word wrap

Endpoint methods

The Endpoint interface defines the following methods:
  • isSingleton()—Returns true, if you want to ensure that each URI maps to a single endpoint within a CamelContext. When this property is true, multiple references to the identical URI within your routes always refer to a single endpoint instance. When this property is false, on the other hand, multiple references to the same URI within your routes refer to distinct endpoint instances. Each time you refer to the URI in a route, a new endpoint instance is created.
  • getEndpointUri()—Returns the endpoint URI of this endpoint.
  • getEndpointKey()—Used by org.apache.camel.spi.LifecycleStrategy when registering the endpoint.
  • getCamelContext()—return a reference to the CamelContext instance to which this endpoint belongs.
  • setCamelContext()—Sets the CamelContext instance to which this endpoint belongs.
  • configureProperties()—Stores a copy of the parameter map that is used to inject parameters when creating a new Consumer instance.
  • isLenientProperties()—Returns true to indicate that the URI is allowed to contain unknown parameters (that is, parameters that cannot be injected on the Endpoint or the Consumer class). Normally, this method should be implemented to return false.
  • createExchange()—An overloaded method with the following variants:
    • Exchange createExchange()—Creates a new exchange instance with a default exchange pattern setting.
    • Exchange createExchange(ExchangePattern pattern)—Creates a new exchange instance with the specified exchange pattern.
    • Exchange createExchange(Exchange exchange)—Converts the given exchange argument to the type of exchange needed for this endpoint. If the given exchange is not already of the correct type, this method copies it into a new instance of the correct type. A default implementation of this method is provided in the DefaultEndpoint class.
  • createProducer()—Factory method used to create new Producer instances.
  • createConsumer()—Factory method to create new event-driven consumer instances. The processor argument is a reference to the first processor in the route.
  • createPollingConsumer()—Factory method to create new polling consumer instances.

Endpoint singletons

In order to avoid unnecessary overhead, it is a good idea to create a single endpoint instance for all endpoints that have the same URI (within a CamelContext). You can enforce this condition by implementing isSingleton() to return true.
Note
In this context, same URI means that two URIs are the same when compared using string equality. In principle, it is possible to have two URIs that are equivalent, though represented by different strings. In that case, the URIs would not be treated as the same.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat