126.10. サンプル
たとえば、以下を行うことができます。
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");
また、たとえば .vm テンプレートが変更されない実稼働環境などでコンテンツキャッシュを使用するには、以下を実行します。
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("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"");