40.7. REST producer 示例
您可以使用其他组件来像任何其他 Camel 组件一样调用 REST 服务。
例如,若要使用 hello/{me}
调用 上的 REST 服务,您可以执行以下操作
from("direct:start") .to("rest:get:hello/{me}");
然后,动态值 {me}
映射到带有相同名称的 Camel 消息。要调用此 REST 服务,您可以发送空消息正文和一个标头,如下所示:
template.sendBodyAndHeader("direct:start", null, "me", "Donald Duck");
Rest producer 需要知道 REST 服务的主机名和端口,您可以使用主机选项进行配置,如下所示:
from("direct:start") .to("rest:get:hello/{me}?host=myserver:8080/foo");
您可以在 restConfiguration
中配置主机,而不使用 host 选项,如下所示:
restConfiguration().host("myserver:8080/foo"); from("direct:start") .to("rest:get:hello/{me}");
您可以使用 producerComponent
选择将哪些 Camel 组件用作 HTTP 客户端,例如使用 http。
restConfiguration().host("myserver:8080/foo").producerComponent("http"); from("direct:start") .to("rest:get:hello/{me}");