4

With Camel proxy I can do the following:

public class MyBean {
    @Produce(uri = "direct:mybean")
    private MyProxy producer;

    public void doSomething() {
        String response = producer.sayHello("James");
    }
}

where MyProxy is interface with one method - sayHello().

But in my case I want to have multiple methods in the MyProxy interface which ideally would have separate URI endpoints. Otherwise I will have an interface for every endpoint that I want to proxy.

The anotations @Produce and @EndpointInject can be set on methods too so I guess that this is possible. Is it? And if not can you recommend me another approach?

Emil Gotsev
  • 223
  • 2
  • 12

1 Answers1

-2

You could do this by registering the MyProxy Bean in camel and calling the methods with the bean and beanRef calls.

from("")
    .bean(MyProxy.class, "sayHello(James)");

or

from("")
    .beanRef("idOfProxyBeanFromRegistry", "sayHello(James)");

For more info see camel bean binding: http://camel.apache.org/bean-binding.html

Matthew Fontana
  • 3,790
  • 2
  • 30
  • 50
  • Sorry, I know this answer is old but I didn't get it. If I have an interface "MyService" with 2 methods, functionA and functionB. I want functionA to produce "seda:fun-a" and functionB to "seda:fun-b". How would you accomplish that? – jfneis Jun 19 '18 at 17:10
  • A bean is just going to be a logical processor and return some sort of object. You need your route to send to a seda. from("").bean(MyService.class, "functionA()").to("seda:fun-a"); from("").bean(MyService.class, "functionB()").to("seda:fun-b"); If you are trying to have the method call dynamically select which route to be sent to you can look at dynamic routing: https://github.com/apache/camel/blob/master/camel-core/src/main/docs/dynamic-router.adoc – Matthew Fontana Jun 19 '18 at 18:35
  • But the point of the question is to do that using Produce (or another) annotation. Using the Route Builder it's clear how to do it. I'd like to have an interface annotated with multiple Produce annotations (1 for each method) and inject it in my Bean, so I don't have to handle Camel objects directly. Take a look: http://camel.apache.org/pojo-producing.html – jfneis Jun 19 '18 at 18:48
  • As far as I am aware the way the Pojo Producing is implemented with Spring Remoting, it is expecting a single method interface to function correctly. If you want to target a specific method call it looks like you will need to use bean binding. http://camel.apache.org/spring-remoting.html – Matthew Fontana Jun 19 '18 at 19:32
  • I understand Bean Binding focuses on beans consuming a message, not producing it (which is the objective of the question): 1 single interface/class, multiple methods, each one producing messages to one endpoint. – jfneis Jun 20 '18 at 14:09
  • For that I would start a new question to the community. – Matthew Fontana Jun 20 '18 at 15:48
  • 1
    Actually this is the original question. Your answer didnt answer it – jfneis Jun 20 '18 at 16:19
  • I don't believe what you want to do is possible. Rather than posting a comment on a 3 year old message which only notifies me you should ask the community in a new question. – Matthew Fontana Jun 21 '18 at 13:22
  • 1
    It's a meta discussion actually. My point is: the original question was about Producing messages and your answer was about Consuming them. Your answer should be "You can't do that", as you answered me now in the comments, or do not exist at all. But you're right, it's 3 years old now and makes no sense keeping commenting. Sorry for bothering you, nothing personal! – jfneis Jun 21 '18 at 13:55