在 Spring 应用程序中添加 Apache Camel 自定义组件/端点 [英] Adding Apache Camel custom component/endpoint in a Spring application

查看:40
本文介绍了在 Spring 应用程序中添加 Apache Camel 自定义组件/端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Spring Boot 应用程序中实现自定义端点.

I'm trying to implement a custom endpoint in a Spring Boot application.

目标是使用路由作为:from("...").process("...").to("my:...");

现在,我有 3 个类:一个 DefaultConsumer、一个 DefaultEndpoint、一个 DefaultComponent:

Now, I have 3 classes: a DefaultConsumer, a DefaultEndpoint, a DefaultComponent:

package com.my.endpoint;

import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.support.DefaultEndpoint;

public class MyEndpoint extends DefaultEndpoint {

    public MyEndpoint(String uri, MyComponent myComponent) {

    }
    ...
}

package com.my.endpoint;

import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
import org.apache.camel.support.DefaultConsumer;

public class MyConsumer extends DefaultConsumer {

    public MyConsumer(Endpoint endpoint, Processor processor) {

        super(endpoint, processor);
    }
}

package com.my.endpoint;

import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.DefaultComponent;

import java.util.Map;

@Component("my")
public class MyComponent extends DefaultComponent {

    public MyComponent(CamelContext camelContext) {

        super(camelContext);
    }
    ...
}

现在:我如何注册?

在 Spring 配置类中,我有:

In a Spring configuration class, I have:

  @Override
  public void configure() throws Exception {

        camelContext.addComponent("my", new MyComponent(camelContext));

但不起作用:

    Caused by: org.apache.camel.NoSuchEndpointException: No endpoint could be found for: my, please check your classpath contains the needed Camel component jar.

所以,我在 services/org/apache/camel/component/my 中添加了 META-INF 文件:

So, I added the META-INF file in services/org/apache/camel/component/my:

class=com.my.endpoint.MyComponent

但这也是行不通的.

没有关于如何实现这一点的完整教程.

There is no complete tutorial on how to implement this.

有什么帮助吗?

注意:我正在尝试实现一个端点,因为我需要使用我的数据类型来集成我的系统.我尝试使用 Transformer 但失败了:在 Apache 中设置自定义数据类型骆驼处理器

Note: I'm trying to implement an Endpoint because I need to integrate my systems using my data types. I tried using Transformer but failed because of this: Set a custom DataType in Apache Camel Processor

之前,我尝试使用数据类型转换器,但因此失败(标记为重复,因为人们懒得真正理解问题):在 Apache Camel 中强制对 Rest 使用者进行类型转换

Before, I tried using data type converter, but failed because of this (marked duplicate because people are too lazy to really understand questions): Enforce type conversion on Rest consumer in Apache Camel

我已完整阅读Apache Camel In Action,第二版";但是,目前,我无法继续我的项目,因为?

I've FULLY read "Apache Camel In Action, Second Edition" but, at the moment, I can't continue with my project because of?

推荐答案

这是因为自定义组件必须通过@UriEndpoint注解进行注解.

This is because custom component must be annotated by @UriEndpoint annotation.

这篇关于在 Spring 应用程序中添加 Apache Camel 自定义组件/端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆