-1
要將我部署的包含camel路由的bundle用作我的中間件,我想將消息發送到駱駝路由,並將其發送到cxf端點。響應被記錄。現在我的外部應用程序,如果我使用MessageConsumer
,無法接收來自駱駝路線的響應。在java中從camel路由收到消息
有沒有辦法在我的主程序中從camel路徑獲取響應消息並打印出來?
要將我部署的包含camel路由的bundle用作我的中間件,我想將消息發送到駱駝路由,並將其發送到cxf端點。響應被記錄。現在我的外部應用程序,如果我使用MessageConsumer
,無法接收來自駱駝路線的響應。在java中從camel路由收到消息
有沒有辦法在我的主程序中從camel路徑獲取響應消息並打印出來?
下面是我的最終路線。它接收來自外部應用程序的請求,向cxf端點發送webservice請求,接收併發回對inonly隊列的響應,這在外部應用程序中被使用。
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();
您是否可以添加更多信息,例如:路線? – soilworker
從( 「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。爲( 「的freemarker:Envelope.ftl」) \t \t \t \t .setHeader( 「operationName」,簡單( 「findCustomer」)) \t \t \t \t。要( 「CXF:豆:我-WS DATAFORMAT =淨荷?」) \t \t \t \t。要( 「文件:// E:// //目標響應」); –
MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 的TextMessage的TextMessage =會話 \t \t \t \t .createTextMessage( 「 AGI00002 」); producer.send(textMessage); /******這裏我想顯示我的cxf響應******/ –