138.10. Samples
例如,您可以使用:
from("activemq:My.Queue").
to("velocity:com/acme/MyResponse.vm");
from("activemq:My.Queue").
to("velocity:com/acme/MyResponse.vm");
要使用 Velocity 模板来对 InOut 消息交换(其中有一个 JMSReplyTo 标头)的响应来建立一个响应。
如果要使用 InOnly 并使用消息并将其发送到另一个目的地,您可以使用以下路由:
from("activemq:My.Queue").
to("velocity:com/acme/MyResponse.vm").
to("activemq:Another.Queue");
from("activemq:My.Queue").
to("velocity:com/acme/MyResponse.vm").
to("activemq:Another.Queue");
使用内容缓存,例如在生产环境中使用,.vm 模板永远不会更改:
from("activemq:My.Queue").
to("velocity:com/acme/MyResponse.vm?contentCache=true").
to("activemq:Another.Queue");
from("activemq:My.Queue").
to("velocity:com/acme/MyResponse.vm?contentCache=true").
to("activemq:Another.Queue");
以及基于文件的资源:
from("activemq:My.Queue").
to("velocity:file://myfolder/MyResponse.vm?contentCache=true").
to("activemq:Another.Queue");
from("activemq:My.Queue").
to("velocity:file://myfolder/MyResponse.vm?contentCache=true").
to("activemq:Another.Queue");
可以指定组件应通过标头动态使用的模板,例如:
from("direct:in").
setHeader("CamelVelocityResourceUri").constant("path/to/my/template.vm").
to("velocity:dummy?allowTemplateFromHeader=true"");
from("direct:in").
setHeader("CamelVelocityResourceUri").constant("path/to/my/template.vm").
to("velocity:dummy?allowTemplateFromHeader=true"");
可以将模板直接指定为标头,则组件应通过标头来动态使用,例如:
from("direct:in").
setHeader("CamelVelocityTemplate").constant("Hi this is a velocity template that can do templating ${body}").
to("velocity:dummy?allowTemplateFromHeader=true"");
from("direct:in").
setHeader("CamelVelocityTemplate").constant("Hi this is a velocity template that can do templating ${body}").
to("velocity:dummy?allowTemplateFromHeader=true"");