...
Tube name will be URL decoded, so if your tube names include special characters like + or ?, you need to URL-encode them appropriately, or use the RAW syntax, see more details here.
By the way, you cannot specify several tubes when you are writing jobs into Beanstalk.
Common URI options
Div |
---|
class | confluenceTableSmall |
---|
|
jobPriority |
Name | Default value | Description |
---|
jobPriority | | | |
|
1000 | Job priority. (0 is the highest, see Beanstalk protocol) | jobDelay | 0 | Job delay in seconds. | jobTimeToRun | 60 | Job time to run in seconds. (when 0, the beanstalkd daemon raises it to 1 automatically, see Beanstalk protocol) |
|
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 |
---|
class | confluenceTableSmall |
---|
|
Name | Type | MessageDefault value | Description |
---|
ExecBinding.EXEC_COMMAND_EXECUTABLE
| String
| in
| The name of the system command that will be executed. Overrides executable in the URI. | ExecBinding.EXEC_COMMAND_ARGS
| java.util.List<String>
| in
| Command-line arguments to pass to the executed process. The arguments are used literally - no quoting is applied. Overrides any existing args in the URI. | ExecBinding.EXEC_COMMAND_ARGS
| String
| in
| Camel 2.5: The arguments of the executable as a Single string where each argument is whitespace separated (see args in URI option). The arguments are used literally, no quoting is applied. Overrides any existing args in the URI. | ExecBinding.EXEC_COMMAND_OUT_FILE
| String
| in
| The name of a file, created by the executable, that should be considered as its output. Overrides any existing outFile in the URI. | ExecBinding.EXEC_COMMAND_TIMEOUT
| long
| in
| The timeout, in milliseconds, after which the executable should be terminated. Overrides any existing timeout in the URI. | ExecBinding.EXEC_COMMAND_WORKING_DIR
| String
| in
| The directory in which the command should be executed. Overrides any existing workingDir in the URI. | ExecBinding.EXEC_EXIT_VALUE
| int
| out
| The value of this header is the exit value of the executable. Non-zero exit values typically indicate abnormal termination. Note that the exit value is OS-dependent. | ExecBinding.EXEC_STDERR
| java.io.InputStream
| out
| The value of this header points to the standard error stream (stderr) of the executable. If no stderr is written, the value is null . | ExecBinding.EXEC_USE_STDERR_ON_EMPTY_STDOUT
| boolean
| in
| Indicates that when stdout is empty, this component will populate the Camel Message Body with stderr . This behavior is disabled (false ) by default. |
|
Message body
command | put | put means to put the job into Beanstalk. Job body is specified in the Camel message body. Job ID will be returned in beanstalk.jobId message header.delete , release , touch or bury expect Job ID in the message header beanstalk.jobId. Result of the operation is returned in beanstalk.result message headerkick expects the number of jobs to kick in the message body and returns the number of jobs actually kicked out in the message header beanstalk.result.
|
|
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 |
---|
class | confluenceTableSmall |
---|
|
Name | Default value | Description |
---|
onFailure | bury | Command to use when processing failed. You can choose among: bury, delete or release. | useBlockIO | true | Whether to use blockIO. | awaitJob | true | Whether to wait for job to complete before ack the job from beanstalk |
|
Info |
---|
The beanstalk consumer is a Scheduled Polling Consumer which means there is more options you can configure, such as how frequent the consumer should poll. For more details see Polling Consumer. |
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 |
---|
class | confluenceTableSmall |
---|
|
FromProperty | ToType | ExecResult Description | java.io.InputStream
|
---|
ExecResult
| String
| ExecResult
| byte []
| ExecResult
| org.w3c.dom.Document
|
If an out file is specified (in the endpoint via outFile or the message headers via ExecBinding.EXEC_COMMAND_OUT_FILE ), converters will return the content of the out file. If no out file is used, then this component will convert the stdout of the process to the target type. For more details, please refer to the usage examples below. |
...
beanstalk.jobId | long | Job ID | beanstalk.tube | string | the name of the tube that contains this job | beanstalk.state | string | “ready” or “delayed” or “reserved” or “buried” (must be “reserved”) | beanstalk.priority | long | the priority value set | beanstalk.age | int | the time in seconds since the put command that created this job | beanstalk.time-left | int | the number of seconds left until the server puts this job into the ready queue | beanstalk.timeouts | int | the number of times this job has timed out during a reservation | beanstalk.releases | int | the number of times a client has released this job from a reservation | beanstalk.buries | int | the number of times this job has been buried | beanstalk.kicks | int | the number of times this job has been kicked |
|
Examples
This Camel component lets you both request the jobs for processing and supply them to Beanstalkd daemon. Our simple demo routes may look like
Code Block |
---|
from("beanstalk:testTube").
log("Processing job #${property.beanstalk.jobId} with body ${in.body}").
|
...
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
.
Code Block |
---|
java | java | from("direct:exec")
.to("exec:wc?args=--words /usr/share/dict/words")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// try Byto default,make theinteger bodyvalue isout ExecResultof instancebody
assertIsInstanceOf(ExecResult.class, exchange.getIn().getBodysetBody());
// Use the Camel Exec String type converter to convert the ExecResult to String
// In this case, the stdout is considered as output
String wordCountOutput = Integer.valueOf(exchange.getIn().getBody(String.classclassOf[String])) );
}
// 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.
}).
log("Parsed job #${property.beanstalk.jobId} to body ${in.body}"); |
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.
...
timer:dig?period=30seconds").
setBody(constant(10)).log("Kick ${in.body} buried/delayed tasks").
to("beanstalk:testTube?command=kick"); |
In the first route we are listening for new jobs in tube “testTube”. When they are arriving, we are trying to parse integer value from the message body. If done successful, we log it and this successful exchange completion makes Camel component to delete this job from Beanstalk automatically. Contrary, when we cannot parse the job data, the exchange failed and the Camel component buries it by default, so that it can be processed later or probably we are going to inspect failed jobs manually.
So the second route periodically requests Beanstalk to kick 10 jobs out of buried and/or delayed state to the normal queue.
Include Page |
---|
| Endpoint See Also |
---|
| Endpoint See Also |
---|
|