【问题标题】:Apache Camel: consuming a file after a directApache Camel:直接使用文件
【发布时间】:2014-08-22 20:06:54
【问题描述】:

我想要做的是有一个“jms”队列,它发送一条消息,正文包含一个文件的名称和一个表示切换到的路由的“标题”(例如 JMSType)。切换路由后(使用“直接:”),我希望能够使用消息正文中指示的文件,但我不知道如何正确执行。这就是我的意思(在一种伪代码中):

from('jms:whatToDo')
  .choice().header('JMSType')
    .when('this').to('direct:this')
    .when('that').to('direct:that')
    .otherwise().to('direct:nothing')
  .end()

from ('direct:this').from('file:/tmp/${jms-body()}?noop=true')
                .split(body().tokenize('\n'))...etc

我已经连续放置了 2 个 "from"s ("direct:" 和 "file:") 在骆驼中是错误的,但这是为了突出我的意思。

知道如何使用 Camel 实现这一目标吗?

【问题讨论】:

    标签: jms apache-camel


    【解决方案1】:

    您可以进行消息转换以将正文设置为您要读取的文件的 java.io.File

    from ('direct:this')
      .transform(simple("file:/tmp/${body}", java.io.File.class))
      .split(body().tokenize('\n'))...etc
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      • 2013-07-24
      • 1970-01-01
      相关资源
      最近更新 更多