java setHeader() 如何在 Apache 骆驼中工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40623367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 05:21:01  来源:igfitidea点击:

How setHeader() works in Apache camel

javaapache-camel

提问by RoyalTiger

I was going through some documentation on Apache Camel and not able to understand what setHeader()does in Apache Camel. Does it add a header to the file specified within from. And also suggest some link where I can get tutorial on Apache Camel.

我正在阅读有关 Apache Camel 的一些文档,但无法理解setHeader()Apache Camel 的作用。它是否向from. 并建议一些链接,我可以在其中获得有关 Apache Camel 的教程。

回答by Souciance Eqdam Rashti

No, it does not add anything to a file. .setHeader()creates a header that exist within the current route. You can create a header like .setHeader("myHeader", "myHeaderValue"). Use headers to access dynamic properties during your route by .getHeader("myHeader")For more long lasting property use exchange properties.

不,它不会向文件添加任何内容。.setHeader()创建存在于当前路由中的标头。您可以创建一个像.setHeader("myHeader", "myHeaderValue"). 使用标头在您的路线期间访问动态属性.getHeader("myHeader")为了更持久的属性使用交换属性。

回答by Sagar

setHeaderto a file(message) consumed(from) does not set the header to the file.

setHeader到文件(消息)consumed( from) 不设置文件头。

Camel File2check the Message Headers. This lists all the Message Headers supported for produce(to) and consume(from) of File endpoint. For a file consumed, you can access the (getHeader) supported headers in the message. But overwriting these values does not overwrite the meta data of the file though.

Camel File2检查 Message Headers。这列出了文件端点的生产(到)和消费(从)支持的所有消息头。对于使用的文件,您可以访问getHeader消息中支持的 ( ) 标头。但是覆盖这些值并不会覆盖文件的元数据。

Headers and Properties in Apache Camel can be used interchangeably to pass values between processes in a single route, but when you want to carry across different routes the behaviors differs. Headers can be lost at endpoints basically as they usually represent some component specific things. Go through the document to understand further.

Apache Camel 中的标头和属性可以互换使用,以在单个route. 标头基本上可以在端点丢失,因为它们通常代表一些特定于组件的东西。仔细阅读文档以进一步了解。

Best tutorials for Camel - Apache Camel Booksand Apache Cammel Documentation

Camel 的最佳教程 - Apache Camel BooksApache Cammel 文档

回答by Arman Tumanyan

Keep in mind that in Camel you are working with Exchange object and that object has headers, properties, body.in, body.out etc.

请记住,在 Camel 中,您正在使用 Exchange 对象,并且该对象具有标题、属性、body.in、body.out 等。

So when you are writing from(“file:...”)content of your file will be putted into your Exchange's body.inand then you can get your file's content for example in Processor using exchange.getIn().getBody().

因此,当您编写from(“file:...”)文件内容时,您的文件内容将被放入您的 Exchange 中body.in,然后您可以使用exchange.getIn().getBody().

Headers are part of your Exchange, so when you are writing: exchange.setHeader(“headerExample”,”MyHeader”), it will add header of existing Exchange's headers.

标题是您 Exchange 的一部分,因此当您编写: 时exchange.setHeader(“headerExample”,”MyHeader”),它将添加现有 Exchange 标题的标题。