...
By the way, you cannot specify several tubes when you are writing jobs into Beanstalk.
Common URI options
Div | |||||||
---|---|---|---|---|---|---|---|
| |||||||
|
Message headers
|
Producer UIR options
Producer behavior is affected by the command
parameter which tells what to do with the job, it can beThe supported headers are defined in org.apache.camel.component.exec.ExecBinding
.
Div | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||
|
Message body
|
Consumer UIR options
The consumer may delete the job immediately after reserving it or wait until Camel routes process it. While the first scenario is more like a “message queue”, the second is similar to “job queue”. This behavior is controlled by consumer.awaitJob
parameter, which equals true
by default (following Beanstalkd nature).
When synchronous, the consumer calls delete
on successful job completion and calls bury
on failure. You can choose which command to execute in the case of failure by specifying consumer.onFailure
parameter in the URI. It can take values of bury
, delete
or release
.
There is a boolean parameter consumer.useBlockIO
which corresponds to the same parameter in JavaBeanstalkClient library. By default it is true
.
Be careful when specifying release
, as the failed job will immediately become available in the same tube and your consumer will try to acquire it again. You can release
and specify jobDelay though.
Div | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
|
Consumer Headers
The consumer stores a number of job headers in the Exchange messageIf the Exec
component receives an in
message body that is convertible to java.io.InputStream
, it is used to feed input to the executable via its stdin. After execution, the message body is the result of the execution,- that is, an org.apache.camel.components.exec.ExecResult
instance containing the stdout, stderr, exit value, and out file. This component supports the following ExecResult
type converters for convenience:
Div | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
If an out file is specified (in the endpoint via |
...
Usage examples
Executing word count (Linux)
The example below executes wc
(word count, Linux) to count the words in file /usr/share/dict/words
. The word count (output) is written to the standard output stream of wc
.
...
from("direct:exec")
.to("exec:wc?args=--words /usr/share/dict/words")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
// By default, the body is ExecResult instance
assertIsInstanceOf(ExecResult.class, exchange.getIn().getBody());
// Use the Camel Exec String type converter to convert the ExecResult to String
// In this case, the stdout is considered as output
String wordCountOutput = exchange.getIn().getBody(String.class);
// do something with the word count
}
});
|
Executing java
The example below executes java
with 2 arguments: -server
and -version
, provided that java
is in the system path.
Code Block |
---|
from("direct:exec")
.to("exec:java?args=-server -version")
|
The example below executes java
in c:\temp
with 3 arguments: -server
, -version
and the sytem property user.name
.
Code Block |
---|
from("direct:exec")
.to("exec:c:/program files/jdk/bin/java?args=-server -version -Duser.name=Camel&workingDir=c:/temp")
|
Executing Ant scripts
The following example executes Apache Ant (Windows only) with the build file CamelExecBuildFile.xml
, provided that ant.bat
is in the system path, and that CamelExecBuildFile.xml
is in the current directory.
Code Block |
---|
from("direct:exec")
.to("exec:ant.bat?args=-f CamelExecBuildFile.xml")
|
In the next example, the ant.bat
command redirects its output to CamelExecOutFile.txt
with -l
. The file CamelExecOutFile.txt
is used as the out file with outFile=CamelExecOutFile.txt
. The example assumes that ant.bat
is in the system path, and that CamelExecBuildFile.xml
is in the current directory.
...
from("direct:exec")
.to("exec:ant.bat?args=-f CamelExecBuildFile.xml -l CamelExecOutFile.txt&outFile=CamelExecOutFile.txt")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
InputStream outFile = exchange.getIn().getBody(InputStream.class);
assertIsInstanceOf(InputStream.class, outFile);
// do something with the out file here
}
});
Executing echo
(Windows)
Commands such as echo
and dir
can be executed only with the command interpreter of the operating system. This example shows how to execute such a command - echo
- in Windows.
...
from("direct:exec").to("exec:cmd?args=/C echo echoString")
...