SHARE
TWEET

Untitled

a guest Oct 4th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package routers;
  2.  
  3. import java.util.Properties;
  4.  
  5. import notifiers.WsNotifierManager;
  6.  
  7. import org.apache.camel.Exchange;
  8. import org.apache.camel.Processor;
  9. import org.apache.camel.builder.RouteBuilder;
  10.  
  11.  
  12. public class Router extends RouteBuilder {
  13.     @Override
  14.     public void configure(){
  15.         final WsNotifierManager wsnot = new WsNotifierManager("tcp://localhost:61616");
  16.        
  17.         from("jms:queue:requests")
  18.             .choice()
  19.                 .when(simple("${in.headers.action} == 'subscribe' or ${in.headers.action} == 'unsubscribe'")).process(new Processor() {
  20.                     public void process(Exchange exchange) throws Exception {
  21.                         /*
  22.                          * Verifico se a acção pretendida é a de iniciar ou terminar uma subscrição de uma fila/tópico.
  23.                          * Se fôr para iniciar, indicar o endereço para onde serão enviadas as mensagens que chegam à fila/tópico.
  24.                          */
  25.                         String action = (String)exchange.getIn().getHeader("action");
  26.                         String target = (String)exchange.getIn().getHeader("target");
  27.                         String type = (String)exchange.getIn().getHeader("target_type");
  28.                         String replyToAddress = (String)exchange.getIn().getHeader("notification_address");
  29.                         String username = (String)exchange.getIn().getHeader("username");
  30.                         String password = (String)exchange.getIn().getHeader("password");
  31.                         if(action == "subscribe")
  32.                             wsnot.addSubscription(target, type, replyToAddress, username, password, new Properties());
  33.                         if(action == "unsubscribe")
  34.                             wsnot.removeSubscription(target, type, username, password);
  35.                     }
  36.                 })
  37.                 /*
  38.                  * Pode-se também, em vez de criar ou terminar subscrições, enviar uma mensagem para um tópico/queue
  39.                  */
  40.                 .when(simple("${in.headers.action} == 'send'")).dynamicRouter(bean(DynamicRouter1.class, "getRoute"));
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top