├── RabbitMQ ├── src │ └── com │ │ ├── performance │ │ ├── test │ │ │ ├── C.java │ │ │ ├── Main.java │ │ │ ├── Init.java │ │ │ └── P.java │ │ └── main │ │ │ ├── MyProducer.java │ │ │ ├── Main.java │ │ │ ├── MyConsumer.java │ │ │ └── EndPoint.java │ │ └── kiven │ │ ├── test │ │ ├── Public.java │ │ ├── Producer.java │ │ ├── Main.java │ │ ├── Declare.java │ │ ├── EndPoint.java │ │ ├── QueueConsumer.java │ │ ├── ToLog.java │ │ ├── CopyOfSend.java │ │ ├── CopyOfRecv.java │ │ ├── Send.java │ │ ├── Recv.java │ │ └── ThreadPools.java │ │ └── main │ │ ├── MDC.java │ │ ├── MDP.java │ │ └── P.java ├── libs │ ├── junit.jar │ ├── commons-io-1.2.jar │ ├── commons-cli-1.1.jar │ ├── rabbitmq-client.jar │ ├── commons-lang3-3.2.1.jar │ └── rabbitmq-client-tests.jar ├── log │ ├── 2014-2-24-164928-.log │ ├── 2014-2-24-13103-.log │ ├── 2014-2-24-135017-.log │ ├── 2014-2-24-115829-.log │ ├── 2014-2-24-133834-.log │ ├── 2014-2-24-133017-.log │ ├── 2014-2-24-152439-.log │ ├── 2014-2-24-135538-.log │ ├── 2014-2-24-13623-.log │ ├── 2014-2-24-122544-.log │ ├── 2014-2-24-121333-.log │ ├── 2014-2-24-15332-.log │ ├── 2014-2-24-14829-.log │ ├── 2014-2-24-145330-.log │ ├── 2014-2-24-15594-.log │ ├── 2014-2-24-141927-.log │ ├── 2014-2-24-154026-.log │ ├── 2014-2-24-162043-.log │ ├── 2014-2-24-161037-.log │ ├── 2014-2-24-143942-.log │ ├── 2014-2-24-15314-.log │ ├── 2014-2-24-15155-.log │ ├── 2014-2-24-111930-.log │ └── 2014-2-24-163434-.log ├── bin │ └── com │ │ ├── kiven │ │ ├── main │ │ │ ├── MDC.class │ │ │ ├── MDP.class │ │ │ ├── P.class │ │ │ ├── MDC$MC.class │ │ │ ├── MDP$MP.class │ │ │ └── P$SendThread.class │ │ └── test │ │ │ ├── Main.class │ │ │ ├── Recv.class │ │ │ ├── Send.class │ │ │ ├── ToLog.class │ │ │ ├── Declare.class │ │ │ ├── EndPoint.class │ │ │ ├── Producer.class │ │ │ ├── Public.class │ │ │ ├── CopyOfRecv.class │ │ │ ├── CopyOfSend.class │ │ │ ├── QueueConsumer.class │ │ │ ├── ThreadPools$R.class │ │ │ ├── ThreadPools$S.class │ │ │ ├── ThreadPools.class │ │ │ ├── Recv$RecvThread.class │ │ │ ├── Send$SendThread.class │ │ │ ├── CopyOfRecv$RecvThread.class │ │ │ └── CopyOfSend$SendThread.class │ │ └── performance │ │ ├── test │ │ ├── C.class │ │ ├── P.class │ │ ├── Init.class │ │ ├── Main.class │ │ ├── P$1.class │ │ └── P$TestThread.class │ │ └── main │ │ ├── Main.class │ │ ├── EndPoint.class │ │ ├── MyConsumer.class │ │ └── MyProducer.class ├── .project ├── .classpath └── .settings │ └── org.eclipse.jdt.core.prefs └── README.md /RabbitMQ/src/com/performance/test/C.java: -------------------------------------------------------------------------------- 1 | package com.performance.test; 2 | 3 | public class C { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /RabbitMQ/libs/junit.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/libs/junit.jar -------------------------------------------------------------------------------- /RabbitMQ/libs/commons-io-1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/libs/commons-io-1.2.jar -------------------------------------------------------------------------------- /RabbitMQ/libs/commons-cli-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/libs/commons-cli-1.1.jar -------------------------------------------------------------------------------- /RabbitMQ/libs/rabbitmq-client.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/libs/rabbitmq-client.jar -------------------------------------------------------------------------------- /RabbitMQ/log/2014-2-24-164928-.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/log/2014-2-24-164928-.log -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/main/MDC.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/main/MDC.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/main/MDP.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/main/MDP.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/main/P.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/main/P.class -------------------------------------------------------------------------------- /RabbitMQ/libs/commons-lang3-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/libs/commons-lang3-3.2.1.jar -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/Main.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/Recv.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/Recv.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/Send.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/Send.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/ToLog.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/ToLog.class -------------------------------------------------------------------------------- /RabbitMQ/libs/rabbitmq-client-tests.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/libs/rabbitmq-client-tests.jar -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/main/MDC$MC.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/main/MDC$MC.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/main/MDP$MP.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/main/MDP$MP.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/Declare.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/Declare.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/EndPoint.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/EndPoint.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/Producer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/Producer.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/Public.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/Public.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/test/C.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/test/C.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/test/P.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/test/P.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/CopyOfRecv.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/CopyOfRecv.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/CopyOfSend.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/CopyOfSend.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/main/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/main/Main.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/test/Init.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/test/Init.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/test/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/test/Main.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/test/P$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/test/P$1.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/main/P$SendThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/main/P$SendThread.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/QueueConsumer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/QueueConsumer.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/ThreadPools$R.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/ThreadPools$R.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/ThreadPools$S.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/ThreadPools$S.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/ThreadPools.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/ThreadPools.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/Recv$RecvThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/Recv$RecvThread.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/Send$SendThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/Send$SendThread.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/main/EndPoint.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/main/EndPoint.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/main/MyConsumer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/main/MyConsumer.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/main/MyProducer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/main/MyProducer.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/performance/test/P$TestThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/performance/test/P$TestThread.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/CopyOfRecv$RecvThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/CopyOfRecv$RecvThread.class -------------------------------------------------------------------------------- /RabbitMQ/bin/com/kiven/test/CopyOfSend$SendThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrKiven/rabbitmq-performance-test/HEAD/RabbitMQ/bin/com/kiven/test/CopyOfSend$SendThread.class -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | rabbitmq-performance-test 2 | ========================= 3 | 4 | test for rabbitmq with java 5 | 6 | Using rabbitmq-performance-test/RabbitMQ/src/com/kiven/test/Send.java and Recv.java for performance testing! 7 | -------------------------------------------------------------------------------- /RabbitMQ/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RabbitMQ 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /RabbitMQ/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/kiven/test/Public.java: -------------------------------------------------------------------------------- 1 | package com.kiven.test; 2 | 3 | 4 | public class Public { 5 | public static String host = "172.16.177.180"; 6 | public static String QUEUE_NAME = "MyTest"; 7 | public static String EXCHANGE_NAME = "MyExchange"; 8 | public static String ROUTINGKEY = "MyRoutingKey"; 9 | 10 | /** 11 | * 线程设置 12 | */ 13 | public static int threads = 1; // 运行的测试线程数 14 | public static int runs = 1; // 每个线程运行的次数 15 | public static int size = 10; //写入数据的大小,单位:字节 16 | 17 | } 18 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/performance/main/MyProducer.java: -------------------------------------------------------------------------------- 1 | package com.performance.main; 2 | 3 | import java.io.IOException; 4 | 5 | import com.rabbitmq.client.MessageProperties; 6 | 7 | /** 8 | * 生产者 9 | * @author Kiven 10 | * 生产者类的任务是向队列里写一条消息。我们使用Apache Commons Lang把可序列化的Java对象转换成 byte 数组。 11 | */ 12 | public class MyProducer extends EndPoint{ 13 | 14 | public MyProducer() throws IOException{ 15 | super(); 16 | } 17 | 18 | public void sendMessage(byte[] message) throws IOException { 19 | channel.basicPublish(EXCHANGE_NAME,ROUTINGKEY, MessageProperties.PERSISTENT_TEXT_PLAIN, message); 20 | } 21 | } -------------------------------------------------------------------------------- /RabbitMQ/src/com/kiven/test/Producer.java: -------------------------------------------------------------------------------- 1 | package com.kiven.test; 2 | 3 | import java.io.IOException; 4 | import java.io.Serializable; 5 | import org.apache.commons.lang3.SerializationUtils; 6 | 7 | /** 8 | * 生产者 9 | * @author Kiven 10 | * 生产者类的任务是向队列里写一条消息。我们使用Apache Commons Lang把可序列化的Java对象转换成 byte 数组。 11 | */ 12 | public class Producer extends EndPoint{ 13 | 14 | public Producer(String endPointName) throws IOException{ 15 | super(endPointName); 16 | } 17 | 18 | public void sendMessage(Serializable object) throws IOException { 19 | channel.basicPublish("",endPointName, null, SerializationUtils.serialize(object)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /RabbitMQ/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jan 06 17:28:12 CST 2014 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.6 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/performance/main/Main.java: -------------------------------------------------------------------------------- 1 | package com.performance.main; 2 | 3 | import java.io.IOException; 4 | import java.sql.SQLException; 5 | 6 | public class Main { 7 | int size = 1024; 8 | int threads = 1; 9 | int runs = 10000; 10 | 11 | public Main() throws Exception{ 12 | byte[] message = new byte[size]; 13 | for(int i=0;i message = new HashMap(); 20 | message.put("message number", i); 21 | 22 | producer.sendMessage(message); 23 | 24 | System.out.println("Message Number "+ i +" sent."); 25 | //Thread.sleep(1000); 26 | } 27 | } 28 | 29 | 30 | /** 31 | * @param args 32 | * @throws SQLException 33 | * @throws IOException 34 | */ 35 | public static void main(String[] args) throws Exception{ 36 | new Main(); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /RabbitMQ/log/2014-2-24-13103-.log: -------------------------------------------------------------------------------- 1 | 发送1 5秒发送的消息数:69809 2 | 发送消息QPS:13961 3 | ================================== 4 | 5 | 6 | 接收1 5秒收到的消息数:50501 7 | 接收消息QPS:10100 8 | ================================== 9 | 10 | 11 | 发送1 5秒发送的消息数:40110 12 | 发送消息QPS:8022 13 | ================================== 14 | 15 | 16 | 接收1 5秒收到的消息数:79128 17 | 接收消息QPS:15825 18 | ================================== 19 | 20 | 21 | 发送1 5秒发送的消息数:73725 22 | 发送消息QPS:14745 23 | ================================== 24 | 25 | 26 | 接收1 5秒收到的消息数:87002 27 | 接收消息QPS:17400 28 | ================================== 29 | 30 | 31 | 发送1 5秒发送的消息数:87693 32 | 发送消息QPS:17538 33 | ================================== 34 | 35 | 36 | 接收1 5秒收到的消息数:86846 37 | 接收消息QPS:17369 38 | ================================== 39 | 40 | 41 | 发送1 5秒发送的消息数:86267 42 | 发送消息QPS:17253 43 | ================================== 44 | 45 | 46 | 接收1 5秒收到的消息数:87922 47 | 接收消息QPS:17584 48 | ================================== 49 | 50 | 51 | 发送1 5秒发送的消息数:87341 52 | 发送消息QPS:17468 53 | ================================== 54 | 55 | 56 | 接收1 5秒收到的消息数:84949 57 | 接收消息QPS:16989 58 | ================================== 59 | 60 | 61 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/performance/main/MyConsumer.java: -------------------------------------------------------------------------------- 1 | package com.performance.main; 2 | 3 | import java.io.IOException; 4 | 5 | import com.rabbitmq.client.QueueingConsumer; 6 | 7 | /** 8 | * 读取队列的程序端,实现了Runnable接口。 9 | * @author kiven 10 | * 11 | */ 12 | public class MyConsumer extends EndPoint implements Runnable{ 13 | 14 | public MyConsumer() throws IOException{ 15 | super(); 16 | consumer = new QueueingConsumer(channel); 17 | } 18 | 19 | public void run() { 20 | int msgNum = 0; 21 | try { 22 | //取消 autoACK 23 | channel.basicConsume(QUEUE_NAME, false, consumer); 24 | while(true){ 25 | try { 26 | //获取消息,如果没有消息,这一步将会一直阻塞 27 | QueueingConsumer.Delivery delivery = consumer.nextDelivery(); 28 | String message = new String(delivery.getBody()); 29 | msgNum++; 30 | System.out.println(message+" received."); 31 | //确认消息已经收到.必须 32 | channel.basicAck(delivery.getEnvelope().getDeliveryTag(),false); 33 | } catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | } catch (IOException e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /RabbitMQ/src/com/performance/test/Main.java: -------------------------------------------------------------------------------- 1 | package com.performance.test; 2 | 3 | /* 4 | The MIT License (MIT) 5 | 6 | Copyright (c) 2013 Xoom Corporation 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | 28 | public class Main { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/kiven/test/Declare.java: -------------------------------------------------------------------------------- 1 | package com.kiven.test; 2 | 3 | import java.io.IOException; 4 | 5 | import com.rabbitmq.client.Channel; 6 | import com.rabbitmq.client.Connection; 7 | import com.rabbitmq.client.ConnectionFactory; 8 | 9 | public class Declare { 10 | private final static String host = Public.host; 11 | private final static String QUEUE_NAME = Public.QUEUE_NAME; 12 | private final static String EXCHANGE_NAME = Public.EXCHANGE_NAME; 13 | private final static String ROUTINGKEY = Public.ROUTINGKEY; 14 | 15 | private static ConnectionFactory factory; 16 | private static Connection connection; 17 | 18 | public Declare(){ 19 | // 创建链接工程 20 | factory = new ConnectionFactory(); 21 | factory.setHost(host); 22 | 23 | try { 24 | // 创建一个新的消息队列服务器实体的连接 25 | connection = factory.newConnection(); 26 | // 创建一个新的消息读写的通道 27 | Channel channel = connection.createChannel(); 28 | // 声明exchange模式并且为持久化exchange 29 | channel.exchangeDeclare(EXCHANGE_NAME, "topic", true); 30 | // declare a queue (声明一个队列) 31 | channel.queueDeclare(QUEUE_NAME, true, false, false, null); 32 | //绑定 33 | channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, ROUTINGKEY); 34 | } catch (IOException e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/performance/test/Init.java: -------------------------------------------------------------------------------- 1 | package com.performance.test; 2 | 3 | import com.rabbitmq.client.Channel; 4 | import com.rabbitmq.client.Connection; 5 | import com.rabbitmq.client.ConnectionFactory; 6 | 7 | public class Init { 8 | static String host = "172.16.217.148"; 9 | static String QUEUE_NAME = ""; 10 | static String EXCHANGE_NAME = ""; 11 | static String ROUTINGKEY = ""; 12 | 13 | public Init() { 14 | try{ 15 | ConnectionFactory factory; 16 | Connection connection; 17 | // 创建链接工程 18 | factory = new ConnectionFactory(); 19 | factory.setHost(host); 20 | // 创建一个新的消息队列服务器实体的连接 21 | connection = factory.newConnection(); 22 | 23 | // 创建一个新的消息读写的通道 24 | Channel channel = connection.createChannel(); 25 | // 声明exchange模式并且为持久化exchange 26 | channel.exchangeDeclare(EXCHANGE_NAME, "topic", true); 27 | // declare a queue (声明一个队列) 28 | // 参数分别为 29 | // 1,队列的名字 30 | // 2,是否为一个持久的队列,持久的队列在服务重新启动的后依然存在 31 | // 3,如果为true,那么就在此次连接中建立一个独占的队列 32 | // 4,是否为自动删除 33 | // 5,队列的一些其他构造参数 34 | channel.queueDeclare(QUEUE_NAME, true, false, false, null); 35 | //绑定 36 | channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, ROUTINGKEY); 37 | }catch(Exception e){ 38 | 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/kiven/test/EndPoint.java: -------------------------------------------------------------------------------- 1 | package com.kiven.test; 2 | 3 | import java.io.IOException; 4 | 5 | import com.rabbitmq.client.Channel; 6 | import com.rabbitmq.client.Connection; 7 | import com.rabbitmq.client.ConnectionFactory; 8 | 9 | /** 10 | * 抽象类 11 | * @author Kiven 12 | * 我们首先写一个类,将产生产者和消费者统一为 EndPoint类型的队列。不管是生产者还是消费者, 连接队列的代码都是一样的,这样可以通用一些。 13 | */ 14 | public abstract class EndPoint{ 15 | 16 | protected String host = "172.16.217.148"; 17 | protected Channel channel; 18 | protected Connection connection; 19 | protected String endPointName; 20 | 21 | public EndPoint(String endpointName) throws IOException{ 22 | this.endPointName = endpointName; 23 | 24 | //Create a connection factory 25 | ConnectionFactory factory = new ConnectionFactory(); 26 | 27 | //hostname of your rabbitmq server 28 | factory.setHost(host); 29 | 30 | //getting a connection 31 | connection = factory.newConnection(); 32 | 33 | //creating a channel 34 | channel = connection.createChannel(); 35 | 36 | //declaring a queue for this channel. If queue does not exist, 37 | //it will be created on the server. 38 | channel.queueDeclare(endpointName, false, false, false, null); 39 | } 40 | 41 | 42 | /** 43 | * 关闭channel和connection。并非必须,因为隐含是自动调用的。 44 | * @throws IOException 45 | */ 46 | public void close() throws IOException{ 47 | this.channel.close(); 48 | this.connection.close(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/performance/test/P.java: -------------------------------------------------------------------------------- 1 | package com.performance.test; 2 | 3 | import java.io.IOException; 4 | import java.util.Random; 5 | 6 | import com.rabbitmq.client.Channel; 7 | import com.rabbitmq.client.Connection; 8 | import com.rabbitmq.client.ConnectionFactory; 9 | import com.rabbitmq.client.ShutdownListener; 10 | import com.rabbitmq.client.ShutdownSignalException; 11 | 12 | public class P { 13 | 14 | public static void main(String[] args) throws Exception { 15 | try { 16 | ConnectionFactory factory = new ConnectionFactory(); 17 | factory.setHost("172.16.217.148"); 18 | Connection conn = factory.newConnection(); 19 | conn.addShutdownListener(new ShutdownListener() { 20 | 21 | @Override 22 | public void shutdownCompleted(ShutdownSignalException cause) { 23 | cause.printStackTrace(); 24 | System.exit(1); 25 | } 26 | }); 27 | 28 | for (int i = 0; i < 5; i++) { 29 | new TestThread(conn).start(); 30 | } 31 | 32 | } catch (IOException e) { 33 | e.printStackTrace(); 34 | } finally { 35 | } 36 | } 37 | 38 | static class TestThread extends Thread { 39 | private Random r; 40 | private Connection conn; 41 | 42 | public TestThread(Connection conn) { 43 | this.conn = conn; 44 | this.r = new Random(); 45 | } 46 | 47 | @Override 48 | public void run() { 49 | int i = 0; 50 | while (true) { 51 | try { 52 | Channel c = conn.createChannel(); 53 | 54 | if ((i++ % 1000) == 0) { 55 | System.out.println("Opened " + this.toString() + ", i = " + i); 56 | } 57 | c.queueDelete("non-existing-" + r.nextInt()); 58 | } catch (IOException e) { 59 | } 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/performance/main/EndPoint.java: -------------------------------------------------------------------------------- 1 | package com.performance.main; 2 | 3 | import java.io.IOException; 4 | 5 | import com.rabbitmq.client.Channel; 6 | import com.rabbitmq.client.Connection; 7 | import com.rabbitmq.client.ConnectionFactory; 8 | import com.rabbitmq.client.QueueingConsumer; 9 | 10 | /** 11 | * 抽象类 12 | * @author Kiven 13 | * 我们首先写一个类,将产生产者和消费者统一为 EndPoint类型的队列。不管是生产者还是消费者, 连接队列的代码都是一样的,这样可以通用一些。 14 | */ 15 | public abstract class EndPoint{ 16 | 17 | public String host = "172.16.217.148"; 18 | public Channel channel; 19 | public Connection connection; 20 | public QueueingConsumer consumer ;; 21 | 22 | public String QUEUE_NAME = "ABC"; 23 | public String EXCHANGE_NAME = "ABC"; 24 | public String ROUTINGKEY = "ABC"; 25 | 26 | public EndPoint() throws IOException{ 27 | //Create a connection factory 28 | ConnectionFactory factory = new ConnectionFactory(); 29 | //hostname of your rabbitmq server 30 | factory.setHost(host); 31 | // 创建一个新的消息队列服务器实体的连接 32 | connection = factory.newConnection(); 33 | // 创建一个新的消息读写的通道 34 | channel = connection.createChannel(); 35 | // 声明exchange模式并且为持久化exchange 36 | channel.exchangeDeclare(EXCHANGE_NAME, "topic", true); 37 | channel.queueDeclare(QUEUE_NAME, true, false, false, null); 38 | //绑定 39 | channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, ROUTINGKEY); 40 | } 41 | 42 | /** 43 | * 关闭channel和connection。并非必须,因为隐含是自动调用的。 44 | * @throws IOException 45 | */ 46 | public void close() throws IOException{ 47 | this.channel.close(); 48 | this.connection.close(); 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/kiven/test/QueueConsumer.java: -------------------------------------------------------------------------------- 1 | package com.kiven.test; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.commons.lang3.SerializationUtils; 8 | 9 | import com.rabbitmq.client.AMQP.BasicProperties; 10 | import com.rabbitmq.client.Consumer; 11 | import com.rabbitmq.client.Envelope; 12 | import com.rabbitmq.client.ShutdownSignalException; 13 | 14 | 15 | /** 16 | * 读取队列的程序端,实现了Runnable接口。 17 | * @author kiven 18 | * 19 | */ 20 | public class QueueConsumer extends EndPoint implements Runnable, Consumer{ 21 | 22 | public QueueConsumer(String endPointName) throws IOException{ 23 | super(endPointName); 24 | } 25 | 26 | public void run() { 27 | try { 28 | //start consuming messages. Auto acknowledge messages. 29 | channel.basicConsume(endPointName, true, this); 30 | } catch (IOException e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | /** 36 | * Called when consumer is registered. 37 | */ 38 | public void handleConsumeOk(String consumerTag) { 39 | System.out.println("Consumer "+consumerTag +" registered"); 40 | } 41 | 42 | /** 43 | * Called when new message is available. 44 | */ 45 | public void handleDelivery(String consumerTag, Envelope env,BasicProperties props, byte[] body) throws IOException { 46 | Map map = (HashMap)SerializationUtils.deserialize(body); 47 | System.out.println(consumerTag+" Message Number "+ map.get("message number") + " received."); 48 | } 49 | 50 | public void handleCancel(String consumerTag) {} 51 | public void handleCancelOk(String consumerTag) {} 52 | public void handleRecoverOk(String consumerTag) {} 53 | public void handleShutdownSignal(String consumerTag, ShutdownSignalException arg1) {} 54 | } 55 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/kiven/test/ToLog.java: -------------------------------------------------------------------------------- 1 | package com.kiven.test; 2 | 3 | import java.io.File; 4 | import java.io.FileWriter; 5 | import java.io.IOException; 6 | import java.util.Calendar; 7 | import java.util.Date; 8 | import java.util.GregorianCalendar; 9 | 10 | /* 11 | * 日志类 12 | * 当运行遇到错误后会生成一个error的日志文件,方便查找问题 13 | */ 14 | public class ToLog { 15 | 16 | static GregorianCalendar time = new GregorianCalendar(); 17 | 18 | private static final String getToday = time.get(Calendar.YEAR)+"-"+(time.get(Calendar.MONTH)+1)+"-"+time.get(Calendar.DAY_OF_MONTH)+"-"+time.get(Calendar.HOUR_OF_DAY)+time.get(Calendar.MINUTE)+time.get(Calendar.SECOND)+"-"; 19 | 20 | private static final String filePath = "log\\"+getToday+".log"; 21 | 22 | //写入文件 23 | public void toLog(String message){ 24 | // StackTraceElement stack[] = (new Throwable()).getStackTrace(); 25 | // StackTraceElement s = stack[1]; 26 | // 27 | // String headerMessage = s.getClassName()+"."+s.getMethodName()+"()"+"★LineNum:"+s.getLineNumber()+"\r\nMessage:"; 28 | // 29 | // headerMessage = addDateTimeHeader(headerMessage); 30 | // message = headerMessage + message; 31 | 32 | FileWriter fw = null; 33 | File file = null; 34 | 35 | try{ 36 | file = new File(filePath); 37 | fw = new FileWriter(file,true); 38 | fw.write(message + "\r\n"); 39 | }catch(IOException ie){ 40 | ie.printStackTrace(); 41 | }finally{ 42 | try{ 43 | fw.close(); 44 | }catch(IOException ie){ 45 | ie.printStackTrace(); 46 | } 47 | } 48 | } 49 | 50 | @SuppressWarnings("deprecation") 51 | public String addDateTimeHeader(String headerMessage) { 52 | String dateTimeHeader = new Date().toLocaleString()+"★"; 53 | return dateTimeHeader += headerMessage; 54 | } 55 | 56 | 57 | // public static void main(String args[]){ 58 | // ToLog log = new ToLog(); 59 | // String message = "这只是测试"; 60 | // log.toLog(message); 61 | // } 62 | } 63 | -------------------------------------------------------------------------------- /RabbitMQ/log/2014-2-24-135017-.log: -------------------------------------------------------------------------------- 1 | 发送1 5秒发送的消息数:29364 2 | 发送消息QPS:5872 3 | ================================== 4 | 5 | 6 | 接收1 5秒收到的消息数:30235 7 | 接收消息QPS:6047 8 | ================================== 9 | 10 | 11 | 发送1 5秒发送的消息数:30100 12 | 发送消息QPS:6020 13 | ================================== 14 | 15 | 16 | 接收1 5秒收到的消息数:29585 17 | 接收消息QPS:5917 18 | ================================== 19 | 20 | 21 | 发送1 5秒发送的消息数:29496 22 | 发送消息QPS:5899 23 | ================================== 24 | 25 | 26 | 接收1 5秒收到的消息数:29977 27 | 接收消息QPS:5995 28 | ================================== 29 | 30 | 31 | 发送1 5秒发送的消息数:30194 32 | 发送消息QPS:6038 33 | ================================== 34 | 35 | 36 | 接收1 5秒收到的消息数:30229 37 | 接收消息QPS:6045 38 | ================================== 39 | 40 | 41 | 发送1 5秒发送的消息数:30274 42 | 发送消息QPS:6054 43 | ================================== 44 | 45 | 46 | 接收1 5秒收到的消息数:30358 47 | 接收消息QPS:6071 48 | ================================== 49 | 50 | 51 | 发送1 5秒发送的消息数:30432 52 | 发送消息QPS:6086 53 | ================================== 54 | 55 | 56 | 接收1 5秒收到的消息数:30448 57 | 接收消息QPS:6089 58 | ================================== 59 | 60 | 61 | 发送1 5秒发送的消息数:30345 62 | 发送消息QPS:6069 63 | ================================== 64 | 65 | 66 | 接收1 5秒收到的消息数:30264 67 | 接收消息QPS:6052 68 | ================================== 69 | 70 | 71 | 发送1 5秒发送的消息数:30125 72 | 发送消息QPS:6025 73 | ================================== 74 | 75 | 76 | 接收1 5秒收到的消息数:30169 77 | 接收消息QPS:6033 78 | ================================== 79 | 80 | 81 | 发送1 5秒发送的消息数:30300 82 | 发送消息QPS:6060 83 | ================================== 84 | 85 | 86 | 接收1 5秒收到的消息数:30397 87 | 接收消息QPS:6079 88 | ================================== 89 | 90 | 91 | 发送1 5秒发送的消息数:30444 92 | 发送消息QPS:6088 93 | ================================== 94 | 95 | 96 | 接收1 5秒收到的消息数:30360 97 | 接收消息QPS:6072 98 | ================================== 99 | 100 | 101 | 发送1 5秒发送的消息数:30358 102 | 发送消息QPS:6071 103 | ================================== 104 | 105 | 106 | 接收1 5秒收到的消息数:30325 107 | 接收消息QPS:6065 108 | ================================== 109 | 110 | 111 | 发送1 5秒发送的消息数:30384 112 | 发送消息QPS:6076 113 | ================================== 114 | 115 | 116 | 接收1 5秒收到的消息数:30156 117 | 接收消息QPS:6031 118 | ================================== 119 | 120 | 121 | -------------------------------------------------------------------------------- /RabbitMQ/log/2014-2-24-115829-.log: -------------------------------------------------------------------------------- 1 | 2 | 3 | 发送1 5秒发送的消息数:27708 4 | 发送消息QPS:5541 5 | ================================== 6 | 7 | 8 | 接收1 5秒收到的消息数:41575 9 | 接收消息QPS:8315 10 | ================================== 11 | 12 | 13 | 发送1 5秒发送的消息数:31739 14 | 发送消息QPS:6347 15 | ================================== 16 | 17 | 18 | 接收1 5秒收到的消息数:41847 19 | 接收消息QPS:8369 20 | ================================== 21 | 22 | 23 | 发送1 5秒发送的消息数:38926 24 | 发送消息QPS:7785 25 | ================================== 26 | 27 | 28 | 接收1 5秒收到的消息数:41318 29 | 接收消息QPS:8263 30 | ================================== 31 | 32 | 33 | 发送1 5秒发送的消息数:42603 34 | 发送消息QPS:8520 35 | ================================== 36 | 37 | 38 | 接收1 5秒收到的消息数:40353 39 | 接收消息QPS:8070 40 | ================================== 41 | 42 | 43 | 发送1 5秒发送的消息数:40000 44 | 发送消息QPS:8000 45 | ================================== 46 | 47 | 48 | 接收1 5秒收到的消息数:40484 49 | 接收消息QPS:8096 50 | ================================== 51 | 52 | 53 | 发送1 5秒发送的消息数:39257 54 | 发送消息QPS:7851 55 | ================================== 56 | 57 | 58 | 接收1 5秒收到的消息数:40514 59 | 接收消息QPS:8102 60 | ================================== 61 | 62 | 63 | 发送1 5秒发送的消息数:39139 64 | 发送消息QPS:7827 65 | ================================== 66 | 67 | 68 | 接收1 5秒收到的消息数:39759 69 | 接收消息QPS:7951 70 | ================================== 71 | 72 | 73 | 发送1 5秒发送的消息数:41319 74 | 发送消息QPS:8263 75 | ================================== 76 | 77 | 78 | 接收1 5秒收到的消息数:41000 79 | 接收消息QPS:8200 80 | ================================== 81 | 82 | 83 | 发送1 5秒发送的消息数:39425 84 | 发送消息QPS:7885 85 | ================================== 86 | 87 | 88 | 接收1 5秒收到的消息数:38902 89 | 接收消息QPS:7780 90 | ================================== 91 | 92 | 93 | 发送1 5秒发送的消息数:46131 94 | 发送消息QPS:9226 95 | ================================== 96 | 97 | 98 | 接收1 5秒收到的消息数:39464 99 | 接收消息QPS:7892 100 | ================================== 101 | 102 | 103 | 发送1 5秒发送的消息数:35082 104 | 发送消息QPS:7016 105 | ================================== 106 | 107 | 108 | 接收1 5秒收到的消息数:41821 109 | 接收消息QPS:8364 110 | ================================== 111 | 112 | 113 | 发送1 5秒发送的消息数:40821 114 | 发送消息QPS:8164 115 | ================================== 116 | 117 | 118 | 接收1 5秒收到的消息数:40949 119 | 接收消息QPS:8189 120 | ================================== 121 | 122 | 123 | -------------------------------------------------------------------------------- /RabbitMQ/log/2014-2-24-133834-.log: -------------------------------------------------------------------------------- 1 | 发送1 5秒发送的消息数:27982 2 | 发送消息QPS:5596 3 | ================================== 4 | 5 | 6 | 接收1 5秒收到的消息数:28361 7 | 接收消息QPS:5672 8 | ================================== 9 | 10 | 11 | 发送1 5秒发送的消息数:27886 12 | 发送消息QPS:5577 13 | ================================== 14 | 15 | 16 | 接收1 5秒收到的消息数:26342 17 | 接收消息QPS:5268 18 | ================================== 19 | 20 | 21 | 发送1 5秒发送的消息数:25262 22 | 发送消息QPS:5052 23 | ================================== 24 | 25 | 26 | 接收1 5秒收到的消息数:25378 27 | 接收消息QPS:5075 28 | ================================== 29 | 30 | 31 | 发送1 5秒发送的消息数:26108 32 | 发送消息QPS:5221 33 | ================================== 34 | 35 | 36 | 接收1 5秒收到的消息数:26548 37 | 接收消息QPS:5309 38 | ================================== 39 | 40 | 41 | 发送1 5秒发送的消息数:26522 42 | 发送消息QPS:5304 43 | ================================== 44 | 45 | 46 | 接收1 5秒收到的消息数:27306 47 | 接收消息QPS:5461 48 | ================================== 49 | 50 | 51 | 发送1 5秒发送的消息数:28154 52 | 发送消息QPS:5630 53 | ================================== 54 | 55 | 56 | 接收1 5秒收到的消息数:28083 57 | 接收消息QPS:5616 58 | ================================== 59 | 60 | 61 | 发送1 5秒发送的消息数:27878 62 | 发送消息QPS:5575 63 | ================================== 64 | 65 | 66 | 接收1 5秒收到的消息数:27681 67 | 接收消息QPS:5536 68 | ================================== 69 | 70 | 71 | 发送1 5秒发送的消息数:28170 72 | 发送消息QPS:5634 73 | ================================== 74 | 75 | 76 | 接收1 5秒收到的消息数:27902 77 | 接收消息QPS:5580 78 | ================================== 79 | 80 | 81 | 发送1 5秒发送的消息数:26440 82 | 发送消息QPS:5288 83 | ================================== 84 | 85 | 86 | 接收1 5秒收到的消息数:26510 87 | 接收消息QPS:5302 88 | ================================== 89 | 90 | 91 | 发送1 5秒发送的消息数:26568 92 | 发送消息QPS:5313 93 | ================================== 94 | 95 | 96 | 接收1 5秒收到的消息数:26601 97 | 接收消息QPS:5320 98 | ================================== 99 | 100 | 101 | 发送1 5秒发送的消息数:26586 102 | 发送消息QPS:5317 103 | ================================== 104 | 105 | 106 | 接收1 5秒收到的消息数:26482 107 | 接收消息QPS:5296 108 | ================================== 109 | 110 | 111 | 发送1 5秒发送的消息数:26576 112 | 发送消息QPS:5315 113 | ================================== 114 | 115 | 116 | 接收1 5秒收到的消息数:26580 117 | 接收消息QPS:5316 118 | ================================== 119 | 120 | 121 | 发送1 5秒发送的消息数:25092 122 | 发送消息QPS:5018 123 | ================================== 124 | 125 | 126 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/kiven/main/MDC.java: -------------------------------------------------------------------------------- 1 | package com.kiven.main; 2 | 3 | import com.rabbitmq.client.Channel; 4 | import com.rabbitmq.client.Connection; 5 | import com.rabbitmq.client.ConnectionFactory; 6 | import com.rabbitmq.client.Envelope; 7 | import com.rabbitmq.client.QueueingConsumer; 8 | 9 | public class MDC { 10 | private int thdnum = 10; 11 | 12 | private String host = "172.16.217.148"; 13 | private String user ="guest"; 14 | private String pwd ="guest"; 15 | 16 | public void receiver(){ 17 | MC mc = new MC(host,user,pwd); 18 | for(int i =0;i= 30000){ 71 | flag = false; 72 | }else if(delivery != null){ 73 | Envelope envelope = delivery.getEnvelope(); 74 | ++rcvNum; 75 | } 76 | } 77 | channel.close(); 78 | connection.close(); 79 | }catch(Exception e){ 80 | e.printStackTrace(); 81 | }finally{ 82 | System.out.println("thread id:" + thdno + " receive message num:" + rcvNum); 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /RabbitMQ/src/com/kiven/main/MDP.java: -------------------------------------------------------------------------------- 1 | package com.kiven.main; 2 | 3 | import com.rabbitmq.client.AMQP; 4 | import com.rabbitmq.client.Channel; 5 | import com.rabbitmq.client.Connection; 6 | import com.rabbitmq.client.ConnectionFactory; 7 | 8 | public class MDP { 9 | /** 10 | * 11 | */ 12 | private int msgnum = 1000000; 13 | private int thdnum = 10; 14 | private int perthdnum = 0; 15 | 16 | private String host = "172.16.217.148"; 17 | private String user ="guest"; 18 | private String pwd ="guest"; 19 | 20 | public void dipatcher(){ 21 | perthdnum = msgnum / thdnum; 22 | MP mp = new MP(perthdnum,host,user,pwd); 23 | 24 | for(int i =0;i