【发布时间】:2017-07-02 10:55:41
【问题描述】:
根据 consul (camel.apache.org/consul-component.html) 的骆驼文档,支持的 HTTP API 是 kv、事件和代理。有 kv(键/值存储)的例子,它们工作正常,但代理 API 没有这样的例子。我还浏览了 Consul [www.consul.io/docs/agent/http/agent.html] 和相应的 java 客户端 [github.com/OrbitzWorldwide/consul-client] 的文档,并试图弄清楚 consul 如何:代理组件应该可以工作,但我发现那里没有什么简单的。
main.getCamelTemplate().sendBodyAndHeader(
"consul:agent?url=http://localhost:8500/v1/agent/service/register",
payload,
ConsulConstants.CONSUL_ACTION, ConsulAgentActions.AGENT); //also tried with ConsulAgentActions.SERVICES, but no luck
我还检查了https://github.com/apache/camel/tree/master/components/camel-consul/src/test/java/org/apache/camel/component/consul 中提到的测试用例,但找不到与代理 api 相关的任何内容。
所以我的问题是如何使用 consul:agent 组件。
更新:我尝试了以下代码并能够获得服务。
Object res = main.getCamelTemplate().requestBodyAndHeader("consul:agent", "", ConsulConstants.CONSUL_ACTION, ConsulAgentActions.SERVICES);
consul 组件似乎只对 HTTP 代理 API 的 GET 操作起作用。但在那种情况下,我如何使用 consul 组件注册新服务(如 /v1/agent/service/register :注册新的本地服务)?
【问题讨论】:
标签: apache-camel consul