2015-05-26 2 views
-1

Чтобы использовать мой развернутый комплект, содержащий верблюжий маршрут в качестве моего промежуточного программного обеспечения, я хочу отправить сообщение на маршрут верблюда, который отправляет конечную точку cxf. Ответ регистрируется. Теперь мое внешнее приложение, если я использую MessageConsumer, не может получить ответ от верблюжьего маршрута.Получение сообщения с верблюжьего маршрута в java

Есть ли способ получить ответное сообщение с верблюжьего маршрута в моей основной программе и распечатать его?

+1

Возможно, вы добавите дополнительную информацию, например, маршруты? – soilworker

+0

из ("ActiveMQ: очереди: вилочных клиентов") \t \t \t \t .routeId ("ActiveMQ: очереди: вилочных клиенты") \t \t \t \t .setExchangePattern (ExchangePattern.InOut) \t \t \t \t .convertBodyTo (String.class) \t \t \t \t .to ("FreeMarker: Envelope.ftl") \t \t \t \t .setHeader ("operationName", простой ("findCustomer")) \t \t \t \t .to ("CXF: боб: мой-WS DataFormat = ПОЛЕЗНОЙ?") \t \t \t \t .to ("Файл: // E: // Target // Response"); –

+0

MessageProducer производитель = session.createProducer (destination); производитель.setDeliveryMode (DeliveryMode.NON_PERSISTENT); TextMessage TextMessage = сессия \t \t \t \t .createTextMessage (" AGI00002"); производитель.send (textMessage); /****** здесь я хочу показать свой ответ cxf ******/ –

ответ

1

Ниже мой последний маршрут. и он получает запрос от внешнего приложения, отправляет запрос webservice на конечную точку cxf, получает и отправляет обратно ответ на нестандартную очередь, которая потребляется во внешнем приложении.

from("activemq:queue:fork-customers") 
       .routeId("activemq:queue:fork-customers") 
       .setExchangePattern(ExchangePattern.InOut) 
       .convertBodyTo(String.class) 
       .process(new Processor() { 
        public void process(Exchange exchange) throws Exception { 
         Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() 
           .parse(new InputSource(new StringReader((String) exchange.getIn().getBody()))); 
         exchange.getIn().setBody(doc); 
        } 
       }) 
       .to("freemarker:Envelope.ftl") 
       .setHeader("operationName", simple("findCustomer")) 
       .to("cxf:bean:my-webservice?dataFormat=PAYLOAD") 
       .to("log:reply") 
       .process(new Processor() { 
        public void process(Exchange exchange) throws Exception { 
         Logger log = LoggerFactory.getLogger(XmlRouting.class); 
         Message msg = exchange.getIn(); 
         log.info("CXF Response : " +msg.toString());       
        } 
       }) 
       .to("file://E://Target//Response") 
       .inOnly("activemq:queue:jmsResponse"); 

Внешний код приложения, который производит и отправить сообщение для ActiveMQ и получает ответ через inonly ActiveMQ.

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
       "tcp://localhost:61616"); 
     // Create a Connection 
     String userName = "smx"; 
     String password = "smx"; 
     Connection connection = connectionFactory.createConnection(userName, 
       password); 
     connection.start(); 
     // Create a Session 
     Session session = connection.createSession(false, 
       Session.AUTO_ACKNOWLEDGE); 
     // Create the destination (Queue) 
     Queue destination = session.createQueue("fork-customers"); 
     // Create a MessageProducer from the Session to the Topic or Queue 
     MessageProducer producer = session.createProducer(destination); 
     producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 
     // pass the arguements here 
     TextMessage textMessage = session 
       .createTextMessage("<root><arg0>CUST1001</arg0></root>"); 
     // Tell the producer to send the message 
     Queue tempQueue = session.createQueue("jmsResponse"); 
     textMessage.setJMSReplyTo(tempQueue); 
     producer.send(textMessage); 
     MessageConsumer consumer = session.createConsumer(tempQueue); 
     Message response = consumer.receive(); 
     String text; 
     if (response instanceof TextMessage) { 
      text = ((TextMessage) response).getText(); 
     } else { 
      byte[] body = new byte[(int) ((BytesMessage) response) 
        .getBodyLength()]; 
      ((BytesMessage) response).readBytes(body); 
      text = new String(body); 
     } 
     System.out.println("responseMsg " + text); 
     // Clean up 
     session.close(); 
     connection.close(); 
Смежные вопросы