...
Dynamic
...
Router
...
The
...
...
...
from
...
the
...
...
...
allows
...
you
...
to
...
route
...
messages
...
while
...
avoiding
...
the
...
dependency
...
of
...
the
...
router
...
on
...
all
...
possible
...
destinations
...
while
...
maintaining
...
its
...
efficiency.
In Camel 2.5
...
we
...
introduced
...
a
...
dynamicRouter
...
in
...
the
...
DSL
...
which
...
is
...
like
...
a
...
dynamic
...
...
...
which
...
evaluates
...
the
...
slip
...
on-the-fly
...
.
...
You must ensure the expression used for the dynamicRouter
such as a bean, will return null
to indicate the end. Otherwise the dynamicRouter
will keep repeating endlessly.
Options
...
Name | Default Value | Description |
---|---|---|
| | Delimiter used if the Expression returned multiple endpoints. |
| | If an endpoint uri could not be resolved, should it be ignored. Otherwise Camel will thrown an exception stating the endpoint uri is not valid. |
| | Camel 2.13.1/2.12.4: Allows to configure the cache size for the |
Dynamic Router in Camel 2.5 onwards
From Camel 2.5 the Dynamic Router will set a property (Exchange.SLIP_ENDPOINT)
...
on
...
the
...
...
which
...
contains
...
the
...
current
...
endpoint
...
as
...
it
...
advanced
...
though
...
the
...
slip.
...
This
...
allows
...
you
...
to
...
know
...
how
...
far
...
we
...
have
...
processed
...
in
...
the
...
slip.
...
(It's
...
a
...
slip
...
because
...
the
...
...
...
implementation
...
is
...
based
...
on
...
top
...
of
...
...
...
).
...
Java
...
DSL
...
In
...
Java
...
DSL
...
you
...
can
...
use
...
the dynamicRouter
as shown below:
...
Which
...
will
...
leverage
...
a
...
...
to
...
compute
...
the
...
slip
...
on-the-fly
...
,
...
which
...
could
...
be
...
implemented
...
as
...
follows:
...
...
Mind
...
that
...
this
...
example
...
is
...
only
...
for
...
show
...
and
...
tell.
...
The
...
current
...
implementation
...
is
...
not
...
thread
...
safe.
...
You
...
would
...
have
...
to
...
store
...
the
...
state
...
on
...
the
...
...
to
...
ensure
...
thread
...
safety, as shown below:
...
You could also store state as message headers, but they are not guaranteed to be preserved during routing, where as properties on the Exchange are. Although there was a bug in the method call expression, see the warning below.
...
Mind that in Camel 2.9.2 or older, when using a Bean the state is not propagated, so you will have to use a Processor instead. This is fixed in Camel 2.9.3 onwards.
Spring XML
The same example in Spring XML would be:
...
@DynamicRouter
...
annotation
...
You
...
can
...
also
...
use
...
the
...
@DynamicRouter
...
annotation,
...
for
...
example
...
the
...
Camel
...
2.4
...
example
...
below
...
could
...
be
...
written
...
as
...
follows.
...
The
...
route
...
method
...
would
...
then
...
be
...
invoked
...
repeatedly
...
as
...
the
...
message
...
is
...
processed
...
dynamically.
...
The
...
idea
...
is
...
to
...
return
...
the
...
next
...
endpoint
...
uri
...
where
...
to
...
go.
...
Return
...
null
...
to
...
indicate
...
the
...
end.
...
You
...
can
...
return
...
multiple
...
endpoints
...
if
...
you
...
like,
...
just
...
as
...
the
...
...
...
,
...
where
...
each
...
endpoint
...
is
...
separated
...
by
...
a
...
delimiter.
...
...
Dynamic Router in Camel 2.4
...
or
...
older
...
The
...
simplest
...
way
...
to
...
implement
...
this
...
is
...
to
...
use
...
the
...
...
...
on
...
a
...
Bean
...
method
...
to
...
determine
...
where
...
to
...
route
...
the
...
message.
...
...
In the above we can use the Parameter Binding Annotations to bind different parts of the Message to method parameters or use an Expression such as using XPath or XQuery.
The method can be invoked in a number of ways as described in the Bean Integration such as
- POJO Producing
- Spring Remoting
- Bean component