You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by soumya_sd <so...@yahoo.com> on 2012/07/29 06:47:27 UTC

Options for creating dynamic filters

Hi, 

I've the following static route that is loaded at my server startup. It
listens for UDP messages on a port and pushes these messages to the seda
queue defined in the route below. 

from("mina:udp://hostipaddress:9998?sync=false").wireTap(
				"seda:sometag?size=100&blockWhenFull=true&multipleConsumers=true");


Now I can have multiple clients that want to receive/subscribe to these
messages. They also want to dynamically select which feeds they need. 
Each client send a subscription request (REST) to the server (implemented
using Spring-MVC, Jetty, Camel). 
As soon as the server receives a request I create a new Camel route that
looks like: 

			from("seda:sometag?multipleConsumers=true")
					.routeId(RouteIdCreator.createRouteId(toIP, toPort, "sometag"))
					.filter()
					.xpath(this.xpathFilter).unmarshal().jaxb("sometag").marshal()
					.json().wireTap("mina:udp://client_ip_address:20001?sync=false"); 

Once this route is deployed it will start to send UDP messages to the
client_ip_address: 20001 (as specified in the dynamic route above.) 




The client can send different filters to the server. 

In case this server receives the new filter it does the following 
1. checks if there is a route running (based on client ip and port) 
2. If there is route running it stops that route and deletes this route with
the older filter
3. It then recreates a new route which differs from the last route only in
the xpathfilter. 

My issue is that step 2 takes a lot of time (to stop and restart)

Is there is a way to resolve this issue? 
Basically I want to change the XPath expression in the route without
stops/migrating the route. 

Thanks. 

PS: I've also posted this question on Stackoverflow. 


 




--
View this message in context: http://camel.465427.n5.nabble.com/Options-for-creating-dynamic-filters-tp5716584.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Options for creating dynamic filters

Posted by Christian Müller <ch...@gmail.com>.
Do you try to stop the route running the same thread? You should do it in a
different thread.

Best,
Christian

On Sun, Jul 29, 2012 at 2:14 PM, soumya_sd <so...@yahoo.com> wrote:

> I found a solution for this.
>
> I added the following and now the Camel forces the route to shutdown in 1
> seconds (timeout time) instead of the default 300 seconds.
>
>         <bean id="shutdown"
> class="org.apache.camel.impl.DefaultShutdownStrategy">
>                 <property name="timeout" value="1" />
>         </bean>
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Options-for-creating-dynamic-filters-tp5716584p5716585.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Options for creating dynamic filters

Posted by Pontus Ullgren <ul...@gmail.com>.
Hello,

The reason that camel does not stop the route directly is that there
are inflight messages in the route.
Setting the timeout to 1 will shorten the time camel wait for the
inflight messages to be processed so there is a risk that by doing
this messages will be lost.

Another approch could be that you create your own filter bean that can
be updated dynamicly with a new expression.

So if you change your route to something like this
                     from("seda:sometag?multipleConsumers=true")

.routeId(RouteIdCreator.createRouteId(toIP, toPort, "sometag"))
                                        .filter().bean("myFilter")
                                        .unmarshal().jaxb("sometag")

.marshal().json().wireTap("mina:udp://client_ip_address:20001?sync=false");

Then register a bean called myFilter that implements predicter. That
does somthing like this...

public class MyFilter implements Predicate {
	private Map<String, String> routeFilterMap = new HashMap<String, String>();	
	
	public void addFilter(String routeId, String expression) {
		routeFilterMap.put(routeId, expression);
	}

	@Override
	public boolean matches(Exchange exchange) {
		String expression = routeFilterMap.get(exchange.getFromRouteId());
		if ( expression != null ) {
			// return the result of the evaluated expression
		} else {
			return false;
		}
	}
}

Then you can update the expression in runtime by calling the
addFilter() method from another route.

// Pontus

On Sun, Jul 29, 2012 at 2:14 PM, soumya_sd <so...@yahoo.com> wrote:
> I found a solution for this.
>
> I added the following and now the Camel forces the route to shutdown in 1
> seconds (timeout time) instead of the default 300 seconds.
>
>         <bean id="shutdown" class="org.apache.camel.impl.DefaultShutdownStrategy">
>                 <property name="timeout" value="1" />
>         </bean>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Options-for-creating-dynamic-filters-tp5716584p5716585.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Options for creating dynamic filters

Posted by soumya_sd <so...@yahoo.com>.
I found a solution for this. 

I added the following and now the Camel forces the route to shutdown in 1
seconds (timeout time) instead of the default 300 seconds. 

	<bean id="shutdown" class="org.apache.camel.impl.DefaultShutdownStrategy">
		<property name="timeout" value="1" />
	</bean>





--
View this message in context: http://camel.465427.n5.nabble.com/Options-for-creating-dynamic-filters-tp5716584p5716585.html
Sent from the Camel - Users mailing list archive at Nabble.com.