⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmsclient.java

📁 基于eclipse环境下开发的servicemix例程
💻 JAVA
字号:
import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;import org.apache.activemq.ActiveMQConnectionFactory;import org.apache.activemq.command.ActiveMQQueue;import org.logicblaze.lingo.jms.Requestor;import org.logicblaze.lingo.jms.JmsProducerConfig;import org.logicblaze.lingo.jms.impl.MultiplexingRequestor;import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;import edu.emory.mathcs.backport.java.util.concurrent.Executors;import javax.jms.ConnectionFactory;import javax.jms.Destination;import javax.jms.Message;import javax.jms.TextMessage;/** * @version $Revision: 535118 $ */public class JMSClient implements Runnable {    private static ConnectionFactory factory;    private static CountDownLatch latch;    private static Requestor requestor;    /**     * main ...     *      * @param args     * @throws Exception     */    public static void main(String[] args) throws Exception {        System.out.println("Connecting to JMS server.");        factory = new ActiveMQConnectionFactory("tcp://localhost:61616");        Destination inQueue = new ActiveMQQueue("demo.org.servicemix.source");        Destination outQueue = new ActiveMQQueue("demo.org.servicemix.output" + (int)(1000*Math.random()));        requestor = MultiplexingRequestor.newInstance(factory, new JmsProducerConfig(), inQueue, outQueue);         if (args.length == 0) {            new JMSClient().run();        } else {            int nb = Integer.parseInt(args[0]);            int th = 30;            if (args.length > 1) {                th = Integer.parseInt(args[1]);            }            latch = new CountDownLatch(nb);            ExecutorService threadPool = Executors.newFixedThreadPool(th);            for (int i = 0; i < nb; i++) {                threadPool.submit(new JMSClient());            }            latch.await();        }        System.out.println("Closing.");        requestor.close();    }    public void run() {        try {            System.out.println("Sending request."); /*           double amount=Math.random() * 100000; int duration=(int) Math.random() * 48; String request="<tns:getLoanQuoteRequest xmlns:tns='urn:logicblaze:soa:loanbroker'><tns:ssn>112-24532-53254</tns:ssn><tns:amount>"+amount+"</tns:amount><tns:duration>"+duration+"</tns:duration></tns:getLoanQuoteRequest>";                                       */                          /*             String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +"<SOAP-ENV:Envelope xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"  xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +"<SOAP-ENV:Header></SOAP-ENV:Header>" +"<SOAP-ENV:Body><getLoanQuoteRequest xmlns='urn:logicblaze:soa:loanbroker'>\n" +"  <ssn>102-24532-53254</ssn>\n" +"  <amount>" + Math.random() * 100000 + "</amount>\n" +"  <duration>" + (int) Math.random() * 48 + "</duration>\n" +"</getLoanQuoteRequest></SOAP-ENV:Body>" +"</SOAP-ENV:Envelope>";*/           String request = "<getLoanQuoteRequest xmlns='urn:sample:soa:houseloanbroker'>" +"  <name>Zhang San</name>" +"</getLoanQuoteRequest>";            TextMessage out = requestor.getSession().createTextMessage(request);            TextMessage in = (TextMessage) requestor.request(null, out);             if (in == null) {                System.out.println("Response timed out.");            }            else {                System.out.println("Response was: " + in.getText());            }        } catch (Exception e) {            e.printStackTrace();        } finally {            if (latch != null) {                latch.countDown();            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -