You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Hadrian Zbarcea (JIRA)" <ji...@apache.org> on 2012/07/25 21:06:35 UTC
[jira] [Commented] (CAMEL-5466) new virtual endpoint component
[ https://issues.apache.org/jira/browse/CAMEL-5466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13422520#comment-13422520 ]
Hadrian Zbarcea commented on CAMEL-5466:
----------------------------------------
How is that different than something like below?
Note that it's simpler, more concise, the template is configurable, the number of uri(s) to use is also flexible. I supplied a whole unit test for you to try out. In a real project you want to move the TempleateRouteBuilder in a separate file. (I can think of ways of making this even more flexible, powerful and 'functionaly' by defining an interface that supplies the templates, etc).
I hope I didn't miss something in the scenario you described. I will close this issue in a few days as "won't fix" unless you come up with a convincing argument that your solution is more appealing.
{code}
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class TemplateRouteBuilderTest extends CamelTestSupport {
@Test
public void testHelloWorldValidInput() throws Exception {
((MockEndpoint)getMandatoryEndpoint("mock:one")).expectedMessageCount(1);
((MockEndpoint)getMandatoryEndpoint("mock:two")).expectedMessageCount(1);
template.sendBody("direct:one", "Hello World");
template.sendBody("direct:two", "Bonjour Monde");
assertMockEndpointsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
String[][] uris = {{"direct:one", "mock:one"}, {"direct:two", "mock:two"}};
return new TemplateRouteBuilder(uris) {
public void configureRouteTemplate(String[] uris) {
if (uris.length != 2) {
throw new RuntimeCamelException("Invalid number of endpoints...");
}
from(uris[0]).to(uris[1]);
}
};
}
public abstract class TemplateRouteBuilder extends RouteBuilder {
private final String[][] config;
public TemplateRouteBuilder(String[][] config) {
this.config = config;
}
@Override
public void configure() throws Exception {
if (config != null) {
for (String[] values : config) {
configureRouteTemplate(values);
}
}
}
public abstract void configureRouteTemplate(String[] uris);
}
}
{code}
> new virtual endpoint component
> ------------------------------
>
> Key: CAMEL-5466
> URL: https://issues.apache.org/jira/browse/CAMEL-5466
> Project: Camel
> Issue Type: Improvement
> Affects Versions: 2.9.2
> Reporter: Ari Mando
> Fix For: 2.9.3
>
> Attachments: camel-virtual.tar.gz
>
>
> I had the recurring need for a virtual endpoint in camel routes. Often I need to define the same route, but just with different endpoint locations, typically queues.
> The supplied component allows for:
> <route>
> <from uri="virtual://source-queue?real=amq://@?"/>
> <to uri="virtual://destination-queue?real=amq2://@?"/>
> </route>
> Then in a virtual.properties file:
> *source-queue,destination-queue
> queue1,queue4
> queue2,queue5
> queue3,queue6
> The above properties file would be like adding 3 routes.
> The supplied impl is a bit rough, it needs some more work. The first cut was sufficient for the usecase I needed it for.
> I already thought it should be really like:
> <virtual id="test" uri="file://queues.xml">
> <route>
> <from uri="virtual://source-queue?real=amq://@?"/>
> <to uri="virtual://destination-queue?real=amq2://@?"/>
> </route>
> </virtual>
> then an xml file:
> <endpointValues>
> <header>
> <value>source-queue</value>
> <value>destination-queue</value>
> </headers>
> <entry>
> <value>queue1,queue4</value>
> <value>queue5,queue6</value>
> </entry>
> </endpointValues>
> Using the DSL would allow multiple virtual routes with different config being pulled from other camel endpoints.
> Dynamic routing! Call it virtual routing or template routing.
> Tasks to be finished on it:
> * implement threading (concurrentConsumers)
> * move to high level dsl model
> * unit tests
> * source configuration from enrichment uri call
> * more robust error handling
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira