Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package routers;
- import java.util.Properties;
- import notifiers.WsNotifierManager;
- import org.apache.camel.Exchange;
- import org.apache.camel.Processor;
- import org.apache.camel.builder.RouteBuilder;
- public class Router extends RouteBuilder {
- @Override
- public void configure(){
- final WsNotifierManager wsnot = new WsNotifierManager("tcp://localhost:61616");
- from("jms:queue:requests")
- .choice()
- .when(simple("${in.headers.action} == 'subscribe' or ${in.headers.action} == 'unsubscribe'")).process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- /*
- * Verifico se a acção pretendida é a de iniciar ou terminar uma subscrição de uma fila/tópico.
- * Se fôr para iniciar, indicar o endereço para onde serão enviadas as mensagens que chegam à fila/tópico.
- */
- String action = (String)exchange.getIn().getHeader("action");
- String target = (String)exchange.getIn().getHeader("target");
- String type = (String)exchange.getIn().getHeader("target_type");
- String replyToAddress = (String)exchange.getIn().getHeader("notification_address");
- String username = (String)exchange.getIn().getHeader("username");
- String password = (String)exchange.getIn().getHeader("password");
- if(action == "subscribe")
- wsnot.addSubscription(target, type, replyToAddress, username, password, new Properties());
- if(action == "unsubscribe")
- wsnot.removeSubscription(target, type, username, password);
- }
- })
- /*
- * Pode-se também, em vez de criar ou terminar subscrições, enviar uma mensagem para um tópico/queue
- */
- .when(simple("${in.headers.action} == 'send'")).dynamicRouter(bean(DynamicRouter1.class, "getRoute"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement