有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaCamel隐藏中间件API发送带有头的JMS交换

是否有人知道如何在[camel pojo Producting][1]遵循此建议:

We recommend Hiding Middleware APIs from your application code so the next option might be more suitable. You can add the @Produce annotation to an injection point (a field or property setter) using a ProducerTemplate or using some interface you use in your business logic. e.g.

public interface MyListener {
    String sayHello(String name);
}

public class MyBean {
    @Produce(uri = "activemq:foo")
    protected MyListener producer;

    public void doSomething() {
        // lets send a message
        String response = producer.sayHello("James");
    }
}

Here Camel will automatically inject a smart client side proxy at the @Produce annotation - an instance of the MyListener instance. When we invoke methods on this interface the method call is turned into an object and using the Camel Spring Remoting mechanism it is sent to the endpoint - in this case the ActiveMQ endpoint to queue foo; then the caller blocks for a response.

但是对于头,为了使用这一行DSL:

from("jms:activemq:toBeStored").recipientList(header("stores").tokenize(",")).parallelProcessing().ignoreInvalidEndpoints();

我已经用@EndpointInject方法成功地测试了它

public class Foo {
  @EndpointInject(uri="activemq:foo.bar")
  ProducerTemplate producer;

  public void doSomething() {
    if (whatever) {
      producer.sendBodyAndHeader("<hello>world!</hello>", "stores","store1");
    }
  }
}

如建议前所述。 简言之:如何使注入的智能客户端代理也发送我想要的头? 谢谢


共 (0) 个答案