根据 consul (camel.apache.org/consul-component.html)的camel文档,支持的HTTP API是kv,event和agent . 有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:注册新的本地服务)?
1 回答
这段代码适合我:
但它看起来有点不合适(如变通方法),我认为还有其他解决方案 .