このコンテンツは選択した言語では利用できません。

41.2. Implementing a Simple Processor


Overview

This section describes how to implement a simple processor that executes message processing logic before delegating the exchange to the next processor in the route.

Processor interface

Simple processors are created by implementing the org.apache.camel.Processor interface. As shown in Example 41.2, “Processor Interface”, the interface defines a single method, process(), which processes an exchange object.

Example 41.2. Processor Interface

package org.apache.camel;

public interface Processor {
    void process(Exchange exchange) throws Exception;
}

Implementing the Processor interface

To create a simple processor you must implement the Processor interface and provide the logic for the process() method. Example 41.3, “Simple Processor Implementation” shows the outline of a simple processor implementation.

Example 41.3. Simple Processor Implementation

import org.apache.camel.Processor;

public class MyProcessor implements Processor {
    public MyProcessor() { }

    public void process(Exchange exchange) throws Exception
    {
        // Insert code that gets executed *before* delegating
        // to the next processor in the chain.
        ...
    }
}
All of the code in the process() method gets executed before the exchange object is delegated to the next processor in the chain.
For examples of how to access the message body and header values inside a simple processor, see Section 41.3, “Accessing Message Content”.

Inserting the simple processor into a route

Use the process() DSL command to insert a simple processor into a route. Create an instance of your custom processor and then pass this instance as an argument to the process() method, as follows:
org.apache.camel.Processor myProc = new MyProcessor();

from("SourceURL").process(myProc).to("TargetURL");
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.