标签: apache-camel

如何以自动方式关闭独立的 Apache Camel 应用程序?

我正在尝试使用 Apache Camel 从 FTP 服务器下载和路由文件。然而,文件只是偶尔添加到 FTP 服务器,所以让程序连续运行似乎有点过分热情。相反,我宁愿有一个每周运行的 cronjob 并处理已添加到服务器的任何新文件。

一旦不再有任何新文件要处理,有没有办法让 Camel 自动关闭?

我当前的main功能如下所示:

public static void main (String[] args) throws Exception {
    org.apache.camel.spring.Main main = new org.apache.camel.spring.Main ();
    main.setApplicationContextUri ("applicationContext.xml");
    main.enableHangupSupport ();
    main.run (args);
}
Run Code Online (Sandbox Code Playgroud)

有趣的部分applicationContext.xml是:

<camelContext>
    <route>
        <from uri="ftp://ftp.example.com/remoteDir?username=user&amp;password=pass"/>
        <to uri="file:../ftp_data?tempPrefix=."/>
    </route>
</camelContext>
Run Code Online (Sandbox Code Playgroud)

java apache-camel

6
推荐指数
2
解决办法
7250
查看次数

Camel - 如何在异常时停止路由执行?

有什么办法可以在捕获异常时停止路由执行(在显示日志消息后)?

        <doTry>
            <process ref="messageProcessor"/>
            <doCatch>
                <exception>java.lang.IllegalArgumentException</exception>
                <log message="some message related to the exception" />
            </doCatch>
        </doTry>
Run Code Online (Sandbox Code Playgroud)

请提供一种在 Spring DSL 中实现此目的的方法。我已经尝试过 < stop/> ,但是没有显示日志消息。

apache-camel

6
推荐指数
2
解决办法
1万
查看次数

无法识别 Soap 请求消息部分

当我向我的网络服务发送请求(使用 apache camel 构建并在 apache karaf 上运行)时,我总是得到

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body>
  <soap:Fault>
     <faultcode>soap:Client</faultcode>
     <faultstring>Message part {http://localhost:8181/cxf/webservices/inputoutput}input was not recognized.  (Does it exist in service WSDL?)</faultstring>
  </soap:Fault>
 </soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)

我的 wsdl 看起来像这样

<?xml version="1.0" encoding="ISO-8859-1"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://localhost:8181/cxf/webservices/inputoutput"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://localhost:8181/cxf/webservices/inputoutput">

<!-- Type definitions for input- and output parameters for webservice -->
<wsdl:types>
    <xs:schema targetNamespace="http://localhost:8181/cxf/webservices/inputoutput">
        <xs:element name="input">
            <xs:complexType>
                <xs:sequence>
                    <xs:element type="xs:string" name="surname"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="output">
            <xs:complexType>
                <xs:sequence>
                    <xs:element type="xs:string" name="forename"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>
</wsdl:types>

<!-- Message definitions for …
Run Code Online (Sandbox Code Playgroud)

soap wsdl web-services apache-camel apache-karaf

6
推荐指数
1
解决办法
2万
查看次数

了解骆驼的进/出交换模式行为

在骆驼中,说不是所有人都ENDPOINT支持是正确的INOUT ExchangePattern吗?
如果是,那么文档的哪一部分告诉哪个端点支持哪个ExchangePattern或这是一种隐含的知识。

由它ENDPOINT来支持INOUT

下面是我得出结论的代码示例。


我正在玩骆驼示例-jms-file,我将其修改为

queue1 --> queue2 ---> file://test ---> file://test1

context.addRoutes(new RouteBuilder() {
        public void configure() {                         

            from("test-jms:queue:test.queue1")
            .process(sleep(1))
            .to("test-jms:queue:test.queue2");

            from("test-jms:queue:test.queue2")
            .process(sleep(2))
            .to("file://test");

            from("file://test")
            .process(sleep(3))
            .to("file://test1");
        }

        private Processor sleep(final int sleepId) {
            return new Processor() {                    
                @Override
                public void process(Exchange exchange) throws Exception {                       
                    System.out.println("Going for sleep sleepid=" + sleepId + ",  thread=" + Thread.currentThread().getName());
                    Thread.sleep(5000l);                        
                    System.out.println("Done sleep sleepid=" + sleepId + ",  thread=" + Thread.currentThread().getName()); …
Run Code Online (Sandbox Code Playgroud)

java apache-camel

6
推荐指数
1
解决办法
6093
查看次数

如何使用camel-jms组件将Artemis与Camel Java DSL一起使用?

现在我在 Java EE 7 应用程序上使用 JMS 2.0 和 Artemis 1.2.0,我想用 Camel 做一些集成任务。

现在检查camel-jms 文档,没有提到如何使用通用camel JMS 组件生成和使用任何JMS 2.0 兼容代理的消息。

组件文档中的唯一示例是使用 Spring DSL 为其专用 ActiveMQ 组件配置 ActiveMQ 连接工厂。如何为 Camel JMS 配置连接以连接到我的 Artemis 实例?

考虑到即使 Artemis 与 ActiveMQ 5.x 兼容,我将使用 Camel 路由来发布和订阅共享的持久主题,因此我需要能够配置一个 Artemis 连接并做一个发布者和一个与其共享持久订阅者(仅在 JMS 2.0 中支持,ActiveMQ 仅支持 JMS 1.1)。

谢谢!

activemq-classic apache-camel jms2

6
推荐指数
1
解决办法
2271
查看次数

如何在 Apache Camel 中的内部拆分中使用外部拆分的 CamelSplitIndex

我必须为数组 B 的每个元素调用一个服务。但数组 A 在数组 A 内。所以我尝试在camel_Context.xml 中使用 split inside split,如下所示。一旦执行了所有内部分割数组值,我还需要聚合它们。

<split>
    <jsonpath>$.Request.Fruits</jsonpath>
    <split>
        <jsonpath>$.request.Fruits[index].item</jsonpath>

        <to someURI>
    </split>
</split> 
Run Code Online (Sandbox Code Playgroud)

我在内部分割中使用的索引应该表示外部分割的当前迭代。CamelSplitIndex 将为您提供内部拆分的迭代次数。我不确定如何在外部分割中使用任何显式计数器。请问还有其他方法可以实现我的目标吗?

split apache-camel

6
推荐指数
1
解决办法
4158
查看次数

从 Java 中的骆驼路线获取可视化文档?

我是 apache Camel 的新手,并通过 Java DSL 使一些路由正常工作。

现在我想知道是否有机会使用 JBoss Fuse 自动获得这些路线的可视化表示?

我的意思是不再手工绘制它,更多的是自动记录:-)

编辑: 由于否决似乎比答案更容易,我尝试稍微改一下我的问题。
我正在寻找一种可能性,对我定义的路线(Java)进行逆向工程,并从中获取带有盒子的图片。

Hawtoi,我之前尝试过的,给出了一个漂亮的结果,但也提供了很多我的文档不需要的其他东西。
因此我看了一下 JBoss Fuse。但在这里我只能绘制我的流程并将它们保存为blueprint.xml。JBoss Fuse 中无法从 Java 代码到 blueprint.xml 吗?我错过了什么吗?

java apache-camel hawtio jbossfuse

6
推荐指数
1
解决办法
3438
查看次数

Apache Camel 读取/写入输入流

我目前正在尝试使用 Apache Camel 来解密已加载到 InputStream 中的 PGP 加密文件。我目前面临的问题是 CamelContext 似乎在启动后就挂起,就好像它direct:is在耗尽流后继续读取一样。我关注了Apache Camel - 如何使用 InputStream 作为源?达到可能将给定的 InputStream 加载到输入通道的点。

    CamelContext context = new DefaultCamelContext();
    CountDownLatch latch = new CountDownLatch(1);

    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("direct:is")
                    .unmarshal().pgp(secretKeyFileName, keyUserId, keyPassword)
                    .to("direct:os")
                    .process(exchange -> latch.countDown());
        }
    });

    DefaultFluentProducerTemplate.on(context).withBody(inputStream).to("direct:is");
    DefaultFluentProducerTemplate.on(context).withBody(outputStream);
    context.start();
    latch.await();
    context.stop();
Run Code Online (Sandbox Code Playgroud)

java apache-camel

6
推荐指数
0
解决办法
497
查看次数

从 Apache Camel 中的 JSON 主体访问数据

我正在使用一个 API,它基本上允许导航文件系统。我试图从 API 返回的 JSON 中访问数据,以便对其执行功能。

下面是我使用访问 API 的代码。我尝试使用 unmarshal 将返回的 JSON 转换为 Map。

from("timer://foo?fixedRate=true&period=120000")
    .log("Checking for files")
    .setHeader("Authorization", simple(myHttp.getAuth()))
    .setHeader("CamelHttpMethod", constant("GET"))
    .to(myHttp.getFullRequest())
    .unmarshal(new JacksonDataFormat(Map.class)).log("${body}");
Run Code Online (Sandbox Code Playgroud)

这将这些数据返回给我:

{
    objects=[
    {
        name=file1.csv,
        type=file
    },
    {
        name=dir1,
        type=directory,
    },
    {
        name=dir2,
        type=directory
    },
    {
        name=dir3,
        type=directory
    },
    {
        name=dir4,
        type=directory
    }]
}
Run Code Online (Sandbox Code Playgroud)

我想访问“对象”下的数组,以检查此目录中是否存在任何文件。到目前为止,我只尝试记录对象下的数据,因此我使用了以下代码:

   .unmarshal(new JacksonDataFormat(Map.class)).log("${body.objects}");
Run Code Online (Sandbox Code Playgroud)

使用 ${body.objects},我仍然无法访问 MAP 中的数据。我期望返回这样的东西:

        [{
            name=file1.csv,
            type=file
        },
        {
            name=dir1,
            type=directory,
        },
        {
            name=dir2,
            type=directory
        },
        {
            name=dir3,
            type=directory
        },
        {
            name=dir4,
            type=directory
        }]
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误:

带有名称的方法:在 bean 上找不到对象:{objects=[{name=file1.csv,type=file},{name=dir1,type=directory,},{name=dir2,type=directory},{name= …

java json apache-camel

6
推荐指数
1
解决办法
8108
查看次数

如何远程运行 spark-submit?

我在集群中运行 Spark(远程)

如何使用 spark-submit 将应用程序提交到具有以下场景的远程集群:

  1. spark-submit 通过骆驼作为命令执行

  2. 应用程序在它自己的容器中运行。

从以下链接:

https://github.com/mvillarrealb/docker-spark-cluster

https://github.com/big-data-europe/docker-spark

我们可以提交 spark 应用程序,但我们已将文件和 jar 复制到卷中。

我如何避免这种情况?

有什么办法吗?

apache-camel docker apache-spark spark-submit

6
推荐指数
1
解决办法
3663
查看次数