Repository: yanghua/banyan
Branch: master
Commit: eff18b0d28e1
Files: 177
Total size: 488.5 KB
Directory structure:
gitextract_25jgdlw4/
├── .gitignore
├── .travis.yml
├── README.md
├── benchmark/
│ ├── README-CN.md
│ ├── pom.xml
│ └── src/
│ └── main/
│ ├── java/
│ │ └── com/
│ │ └── messagebus/
│ │ └── benchmark/
│ │ └── client/
│ │ ├── Benchmark.java
│ │ ├── IFetcher.java
│ │ ├── ILifeCycle.java
│ │ ├── TestConfigConstant.java
│ │ ├── TestMessageFactory.java
│ │ ├── TestUtility.java
│ │ └── testCase/
│ │ ├── CalcService.java
│ │ ├── ConsumeTestCase.java
│ │ ├── MessagebusJSONRpcTestCase.java
│ │ ├── OriginalConsumeTestCase.java
│ │ ├── OriginalProduceTestCase.java
│ │ ├── OriginalProduceWithoutTopologyTestCase.java
│ │ ├── ProduceRemainLogTestCase.java
│ │ ├── ProduceTestCase.java
│ │ ├── ProduceWithoutLogTestCase.java
│ │ └── ThriftJSONRpcTestCase.java
│ └── resources/
│ ├── clearEnv.sh
│ ├── log4j.properties
│ ├── plotscript_consume.sh
│ ├── plotscript_messagebus_client_produce.sh
│ ├── plotscript_messagebus_client_remain_log_produce.sh
│ ├── plotscript_messagebus_client_without_realtime_log_produce.sh
│ ├── plotscript_official_client_produce.sh
│ └── plotscript_official_client_without_topology_produce.sh
├── client/
│ ├── pom.xml
│ └── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── messagebus/
│ │ │ └── client/
│ │ │ ├── AbstractPool.java
│ │ │ ├── Address.java
│ │ │ ├── ConfigManager.java
│ │ │ ├── GenericContext.java
│ │ │ ├── IMessageReceiveListener.java
│ │ │ ├── IRequestListener.java
│ │ │ ├── IRpcMessageProcessor.java
│ │ │ ├── InnerClient.java
│ │ │ ├── InnerPool.java
│ │ │ ├── MessageContext.java
│ │ │ ├── MessageResponseTimeoutException.java
│ │ │ ├── Messagebus.java
│ │ │ ├── MessagebusConnectedFailedException.java
│ │ │ ├── MessagebusFactory.java
│ │ │ ├── MessagebusPool.java
│ │ │ ├── MessagebusSinglePool.java
│ │ │ ├── MessagebusUnOpenException.java
│ │ │ ├── WrappedRpcServer.java
│ │ │ ├── carry/
│ │ │ │ ├── AbstractMessageCarryer.java
│ │ │ │ ├── CarryFactory.java
│ │ │ │ ├── GenericBroadcaster.java
│ │ │ │ ├── GenericConsumer.java
│ │ │ │ ├── GenericProducer.java
│ │ │ │ ├── GenericPublisher.java
│ │ │ │ ├── GenericRequester.java
│ │ │ │ ├── GenericResponser.java
│ │ │ │ ├── GenericRpcRequester.java
│ │ │ │ ├── GenericRpcResponser.java
│ │ │ │ ├── GenericSubscriber.java
│ │ │ │ ├── IBroadcaster.java
│ │ │ │ ├── IConsumer.java
│ │ │ │ ├── IProducer.java
│ │ │ │ ├── IPublisher.java
│ │ │ │ ├── IRequester.java
│ │ │ │ ├── IResponser.java
│ │ │ │ ├── IRpcRequester.java
│ │ │ │ ├── IRpcResponser.java
│ │ │ │ └── ISubscriber.java
│ │ │ ├── event/
│ │ │ │ ├── carry/
│ │ │ │ │ ├── BroadcastEventProcessor.java
│ │ │ │ │ ├── CarryEvent.java
│ │ │ │ │ ├── CommonEventProcessor.java
│ │ │ │ │ ├── ConsumeEventProcessor.java
│ │ │ │ │ ├── ProduceEventProcessor.java
│ │ │ │ │ ├── PublishEventProcessor.java
│ │ │ │ │ ├── RequestEventProcessor.java
│ │ │ │ │ ├── ResponseEventProcessor.java
│ │ │ │ │ ├── RpcRequestEventProcessor.java
│ │ │ │ │ ├── RpcResponseEventProcessor.java
│ │ │ │ │ └── SubscribeEventProcessor.java
│ │ │ │ └── component/
│ │ │ │ ├── ClientDestroyEvent.java
│ │ │ │ ├── ClientDestroyEventProcessor.java
│ │ │ │ ├── ClientInitedEvent.java
│ │ │ │ ├── ClientInitedEventProcessor.java
│ │ │ │ ├── InnerEvent.java
│ │ │ │ └── NoticeEvent.java
│ │ │ ├── extension/
│ │ │ │ └── thrift/
│ │ │ │ ├── TAMQPClientTransport.java
│ │ │ │ └── ThriftMessageHandler.java
│ │ │ ├── message/
│ │ │ │ ├── model/
│ │ │ │ │ ├── Message.java
│ │ │ │ │ ├── MessageFactory.java
│ │ │ │ │ └── MessageJSONSerializer.java
│ │ │ │ └── transfer/
│ │ │ │ └── MessageHeaderTransfer.java
│ │ │ └── model/
│ │ │ ├── BaseModel.java
│ │ │ ├── Config.java
│ │ │ ├── HandlerModel.java
│ │ │ └── MessageCarryType.java
│ │ └── resources/
│ │ └── log4j.properties
│ └── test/
│ └── java/
│ └── com/
│ └── messagebus/
│ └── client/
│ ├── api/
│ │ ├── Broadcast.java
│ │ ├── ComponentEventListener.java
│ │ ├── ProduceConsume.java
│ │ ├── ProduceConsumeLoopback.java
│ │ ├── PublishSubscribe.java
│ │ ├── RequestResponse.java
│ │ └── RpcRequestResponse.java
│ ├── core/
│ │ ├── BaseTestCase.java
│ │ └── MessageUtil.java
│ └── feature/
│ ├── CalcService.java
│ ├── CalcServiceImpl.java
│ ├── MessageBodySize.java
│ ├── MessageNumLimit.java
│ └── ThriftWithAMQPRpc.java
├── common-component/
│ ├── pom.xml
│ └── src/
│ └── main/
│ ├── java/
│ │ └── com/
│ │ └── messagebus/
│ │ └── common/
│ │ ├── AuthInfo.java
│ │ ├── Constants.java
│ │ ├── Event.java
│ │ ├── ExceptionHelper.java
│ │ ├── GsonUtil.java
│ │ ├── HttpHelper.java
│ │ ├── IAsyncCallback.java
│ │ ├── InnerNoticeEntity.java
│ │ ├── NumberHelper.java
│ │ ├── RandomHelper.java
│ │ ├── RouterType.java
│ │ ├── ShellHelper.java
│ │ ├── TestVariableInfo.java
│ │ ├── UUIDGenerator.java
│ │ └── compress/
│ │ ├── CompressEnum.java
│ │ ├── CompressorFactory.java
│ │ ├── ICompressor.java
│ │ ├── LZFCompressor.java
│ │ └── SnappyCompressor.java
│ └── resources/
│ └── log4j.properties
├── httpbridge/
│ ├── README.md
│ ├── pom.xml
│ └── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── messagebus/
│ │ │ └── httpbridge/
│ │ │ ├── controller/
│ │ │ │ ├── ExceptionHandler.java
│ │ │ │ └── HttpBridge.java
│ │ │ ├── filter/
│ │ │ │ └── URLDispatcher.java
│ │ │ ├── listener/
│ │ │ │ └── AppContextListener.java
│ │ │ ├── model/
│ │ │ │ └── TextMessage.java
│ │ │ └── util/
│ │ │ ├── CommonUtil.java
│ │ │ ├── Constants.java
│ │ │ ├── ResponseUtil.java
│ │ │ └── TextMessageJSONSerializer.java
│ │ ├── resources/
│ │ │ └── log4j.properties
│ │ └── webapp/
│ │ └── WEB-INF/
│ │ ├── jetty-web.xml
│ │ └── web.xml
│ └── test/
│ ├── java/
│ │ └── com/
│ │ └── messagebus/
│ │ └── httpbridge/
│ │ └── util/
│ │ └── PropertiesHelper.java
│ └── resource/
│ └── common.properties
├── interactor-component/
│ ├── pom.xml
│ └── src/
│ └── main/
│ └── java/
│ └── com/
│ └── messagebus/
│ └── interactor/
│ ├── proxy/
│ │ ├── ProxyConsumer.java
│ │ └── ProxyProducer.java
│ ├── rabbitmq/
│ │ ├── AbstractInitializer.java
│ │ ├── Exchange.java
│ │ ├── ExchangeManager.java
│ │ ├── MQDataInitializer.java
│ │ ├── Queue.java
│ │ ├── QueueManager.java
│ │ └── RabbitmqServerManager.java
│ └── util/
│ └── ShellHelper.java
├── managesystem/
│ └── banyan_DB.sql
├── pom.xml
└── scenario/
├── pom.xml
└── src/
└── main/
├── java/
│ └── com/
│ └── messagebus/
│ └── scenario/
│ ├── client/
│ │ ├── BroadcastSubscribe.java
│ │ ├── ClientUnderMultiThread.java
│ │ ├── ProduceConsume.java
│ │ ├── PublishSubscribe.java
│ │ ├── RequestResponse.java
│ │ └── XSLTTestCase.java
│ ├── httpBridge/
│ │ ├── ProduceConsume.java
│ │ ├── PublishSubscribe.java
│ │ ├── RequestTemplate.java
│ │ └── ResponseTemplate.java
│ └── util/
│ └── PropertiesHelper.java
└── resources/
├── common.properties
├── consumerSchema.xml
├── pToc.xsl
├── producerSchema.xml
└── producerXml.xml
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.idea/*
.DS_Store
*/target/*
*.iml
META-INF/*
*.rdb
*.MF
*.class
================================================
FILE: .travis.yml
================================================
language: java
================================================
FILE: README.md
================================================
#overview
[](https://travis-ci.org/yanghua/banyan)
![img 15][15]
```
banyan is a tree has thick branches which grows in the East Asia.
```
Thanks for [@ok95](https://github.com/ok95) & [@Joy-Zhang](https://github.com/Joy-Zhang) given the good idea & guidance.
![img 14][14]
banyan used to communicate and integrate over multi-app. It depends on [RabbitMQ](http://www.rabbitmq.com/) as backend broker(message exchanger). Most scenario:
* enterprise information Integration
* oriented-component & oriented-module distributed developer
* infrastructure for esb or soa
* json-rpc / IDL-RPC(thrift)
* configured compress/uncompress
* http-bridge for all platform
* web-console UI
the necessity of encapsulating with RabbitMQ:
* provide router pattern
* embed permission into client-jar
* removed create & delete & update operation from client, replaced with central-register mode
more information please see : [banyan-category](http://blog.csdn.net/column/details/banyan.html)
##tree topology structure
the message bus's implementation is based on Rabbitmq. It can takes advantage of multiple message exchange-types rabbitmq provided and builds many kinds of router pattern. The message bus's router topology lists below:
![img 3][3]
the advantages of the tree topology:
* hide the router topology from client-caller (just need to know the `proxy` node)
* multiple message communication pattern (p2p, pub/sub, broadcast)
* implement the message log without interrupting the message channel
* communication-policy configure once , push everywhere
##web-console
banyan has its' own web console that built as a Apache-ofbiz's component. The web console provide a dashboard about rabbitmq :
![img 16][16]
and some core model's maintenance such as queue :
![img 17][17]
##Restful API
* [apis](https://github.com/yanghua/banyan/tree/master/httpbridge)
##scenario & usage
###produce & consume
* [produce](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FProduceConsume.java#L34) / [pull consume](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FProduceConsume.java#L46)
* [produce](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FProduceConsume.java#L34) / [push consume](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FProduceConsume.java#L64)
* [produce](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FProduceConsume.java#L34) / [async consume with another thread](https://github.com/yanghua/banyan/blob/master/scenario%2Fsrc%2Fmain%2Fjava%2Fcom%2Fmessagebus%2Fscenario%2Fclient%2FProduceConsume.java#L91)
* [produce-loopback](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FProduceConsumeLoopback.java#L15) / [consume-loopback](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FProduceConsumeLoopback.java#L15)
###request & response
* [request](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FRequestResponse.java#L35) / [response](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FRequestResponse.java#L35)
###publish & subscirbe
* [publish](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FPublishSubscribe.java#L31) / [subscribe](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FPublishSubscribe.java#L31)
###broadcast & notification-handler
* [broadcast](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FBroadcast.java#L31) / [notification-handler](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FBroadcast.java#L31)
###json-rpc(wrapped-offical-java-client)
* [rpc-request](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FRpcRequestResponse.java#L28) / [rpc-response](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Fapi%2FRpcRequestResponse.java#L28)
###thrift-rpc(thrid-party-rpc-integrated)
* [rpc-request](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Ffeature%2FThriftWithAMQPRpc.java#L36) / [rpc-response](https://github.com/yanghua/banyan/blob/master/client%2Fsrc%2Ftest%2Fjava%2Fcom%2Fmessagebus%2Fclient%2Ffeature%2FThriftWithAMQPRpc.java#L59)
###http-restful
* [http-apis](https://github.com/yanghua/banyan/tree/master/scenario/src/main/java/com/messagebus/scenario/httpBridge)
##benchmark
it shows the `client` performance:
###hardware
client :
```
OS : Mac os x Yosemite (version 10.10)
Processor : 2.5GHz Intel Core i5
Memory : 8GB 1600 MHz DDR3
JDK Version : 1.7.0_45
```
server :
```
OS : Ubuntu Server 14.04.1 (GNU/Linux 3.13.0-37-generic x86_64)
Processor : Intel(R) Xeon(R) CPU E3-1230 V2 @ 3.30GHz (8核)
Memory : 8GB
JDK Version : 1.7.0_72
```
###produce
* single thread,multiple message size ,cycle send,compare:
![img 10][10]
* single thread,same message size,use client channel pool or not,compare:
![img 11][11]
###consume
* single thread,multiple message size,async receive,compare:
![img 12][12]
* single thread,same message size,use client channel pool or not,compare:
![img 13][13]
##licence
Copyright (c) 2014-2015 yanghua. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
```
http://www.apache.org/licenses/LICENSE-2.0
```
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
[1]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/overview/architecture.png
[2]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/overview/module-dependency.png
[3]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/overview/router-topology.png
[4]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/client/carry-inherits.png
[5]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/client/handle-chain.png
[6]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/client/handler-chain-config.png
[7]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/client/node.png
[8]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/client/node-db-info.png
[9]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/common/message-design.png
[10]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/benchmark/produce/singleThreadClientVSOriginal.png
[11]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/benchmark/produce/singleThreadOptionPool.png
[12]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/benchmark/consume/singleThreadClientVSOriginal.png
[13]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/benchmark/consume/singleThreadOptionPool.png
[14]:https://raw.githubusercontent.com/yanghua/banyan/master/screenshots/overview/rabbitmq-offical-screenshot.png
[15]:https://raw.githubusercontent.com/yanghua/banyan/master/screenshots/overview/banyan.jpg
[16]:https://raw.githubusercontent.com/yanghua/banyan/master/screenshots/overview/webconsole-dashboard.png
[17]:https://raw.githubusercontent.com/yanghua/banyan/master/screenshots/overview/webconsole-queueManage.png
================================================
FILE: benchmark/README-CN.md
================================================
#overview
本项目用于对消息总线的 `client` 进行测试,以展示不同场景下 `client` 的性能表现。
##测试说明
配置说明:
client :
```
OS : Mac os x Yosemite (version 10.10)
Processor : 2.5GHz Intel Core i5
Memory : 8GB 1600 MHz DDR3
JDK Version : 1.7.0_45
```
server :
```
OS : Ubuntu Server 14.04.1 (GNU/Linux 3.13.0-37-generic x86_64)
Processor : Intel(R) Xeon(R) CPU E3-1230 V2 @ 3.30GHz (8核)
Memory : 8GB
JDK Version : 1.7.0_72
```
> 每次测试之前,rabbitmq都会重新初始化,也就是说,每次测试之前总线中没有消息!
##实现说明
测试模块的相关类图:
![img 1][1]
测试逻辑由一个个测试用例构成,测试用例都是形如XXXTestCase的Java文件,所有的TestCase都继承自 `Benchmark` 类,它提供了一个 `test` 方法:
```
public void test(Runnable testTask, int holdTime, int fetchNum, String fileName);
```
它需要的几个参数:
* testTask - 具体的测试逻辑所属类,上面的 `BasicProduce`的实例
* holdTime - 测试维持的毫秒数
* fetchNum - 采样次数
* fileName - 采集数据要存储的文件名
`test` 方法提供了一个实现,并完成了一些 `Aspect`,它们有:
* 日志记录
* testTask的多线程启动
* 测试数据的采集
* testTask的关闭
* 采集数据写入文件
每个继承自 `Benchmark` 的 testcase 都包含有若干个 testTask (它们都是静态内部类,都实现了 `Runnable`接口,如上图的 `BasicProduce`),每个testcase都包含有一个 `main` 入口方法,该方法用于运行测试。
对于每一个testTask,它们通常都会实现两个接口:
* ITerminater : 终止testTask的接口
* IFetcher : 提取/采集测试数据的接口
这两个接口在 `Benchmark` 的 `test` 方法中使用。
除此之外,还有几个辅助类:
- TestMessageFactory : 用于安装给定的size来生成测试消息
- TestConfigConstant : 用于统一配置一些测试常量
- TestUtility : 帮助类,测试数据写文件等
##scenario
###produce
> orignal : native-java-client 发送,但也走server的topology route,测试时共享一个channel
> client : 如无特殊说明,client发送时都基于pool-channel模式
* 单线程,不同大小的消息体,循环发送,对比:
![img 2][2]
* 单线程,相同大小的消息体,是否使用client channel pool,对比:
![img 3][3]
###consume
>所有消息以接收后拆包封装为 `Message` 对象,为接收完成,所有的测试都基于rabbitmq server中预先生成 **50W** 条消息为基础
* 单线程,不同大小的消息体,异步接收,对比:
![img 4][4]
* 单线程,相同大小的消息体,是否使用client channel pool,对比:
![img 5][5]
>由于在异步消费的时候,本身就是使用单个channel的长连接事件循环,所以此处基本没有体现出差异。
###其他通信方式
由于其他两种消息通信方式都是由produce/consume演变而来,因此其他场景下的 **单方面** 的性能跟以上相当!
[1]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/benchmark/benchmark-class-diagram.png
[2]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/benchmark/produce/singleThreadClientVSOriginal.png
[3]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/benchmark/produce/singleThreadOptionPool.png
[4]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/benchmark/consume/singleThreadClientVSOriginal.png
[5]:https://raw.githubusercontent.com/yanghua/messagebus/master/screenshots/benchmark/consume/singleThreadOptionPool.png
================================================
FILE: benchmark/pom.xml
================================================
messagebus
com.messagebus
1.0.5
4.0.0
benchmark
com.messagebus
client
1.0.5
org.apache.thrift
libthrift
0.9.2
org.slf4j
slf4j-api
1.7.12
================================================
FILE: benchmark/src/main/java/com/messagebus/benchmark/client/Benchmark.java
================================================
package com.messagebus.benchmark.client;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.concurrent.TimeUnit;
public abstract class Benchmark {
private static final Log logger = LogFactory.getLog(Benchmark.class);
public void test(Runnable testTask, int holdTime, int fetchNum, String fileName) {
logger.info("test begin");
int fetchInterval = holdTime / fetchNum;
long[] xArr = new long[fetchNum];
long[] yArr = new long[fetchNum];
//initialize value
xArr[0] = 0;
yArr[0] = 0;
ILifeCycle testCase = (ILifeCycle) testTask;
testCase.start();
try {
for (int i = 1; i < fetchNum; i++) {
TimeUnit.MILLISECONDS.sleep(fetchInterval);
xArr[i] = i * fetchInterval;
yArr[i] = ((IFetcher) testTask).fetch();
}
((ILifeCycle) testTask).terminate();
//write to report file
TestUtility.writeFile(fileName, xArr, yArr);
} catch (InterruptedException e) {
}
logger.info("test end");
}
}
================================================
FILE: benchmark/src/main/java/com/messagebus/benchmark/client/IFetcher.java
================================================
package com.messagebus.benchmark.client;
public interface IFetcher {
long fetch();
}
================================================
FILE: benchmark/src/main/java/com/messagebus/benchmark/client/ILifeCycle.java
================================================
package com.messagebus.benchmark.client;
public interface ILifeCycle {
void start();
void terminate();
}
================================================
FILE: benchmark/src/main/java/com/messagebus/benchmark/client/TestConfigConstant.java
================================================
package com.messagebus.benchmark.client;
public class TestConfigConstant {
public static final String ORIGINAL_PRODUCE_ROUTING_KEY = "routingkey.proxy.message.procon.erpDemoConsume";
public static final String DEFAULT_EXCHANGE_NAME_WITHOUT_TOPOLOGY = "amq.fanout";
public static final String PRODUCER_SECRET = "kljasdoifqoikjhhhqwhebasdfasdf";
public static final String PRODUCER_TOKEN = "hlkasjdhfkqlwhlfalksjdhgssssas";
public static final String CONSUMER_QUEUE_NAME = "emapDemoConsume";
public static final String CONSUMER_SECRET = "zxdjnflakwenklasjdflkqpiasdfnj";
public static final String OUTPUT_FILE_PATH_FORMAT = "/tmp/%s.data";
public static final int MSG_BODY_SIZE_OF_BYTE = 3000; //B
public static final int HOLD_TIME_OF_MILLIS = 60000; //one minute
public static final int FETCH_NUM = 6;
}
================================================
FILE: benchmark/src/main/java/com/messagebus/benchmark/client/TestMessageFactory.java
================================================
package com.messagebus.benchmark.client;
import com.messagebus.client.message.model.Message;
import com.messagebus.client.message.model.MessageFactory;
import com.messagebus.client.message.model.MessageType;
public class TestMessageFactory {
public static Message create(MessageType type, int sizeOfByte) {
Message msg = MessageFactory.createMessage(type);
byte[] content = generate(sizeOfByte);
msg.setContent(content);
return msg;
}
public static Message[] create(MessageType type, int sizeOfByte, int num) {
Message[] msgs = new Message[num];
Message msg = create(type, sizeOfByte);
for (int i = 0; i < num; i++) {
msgs[i] = msg;
}
return msgs;
}
private static byte[] generate(int sizeOfByte) {
byte[] result = new byte[sizeOfByte];
for (int i = 0; i < sizeOfByte; i++) {
result[i] = (byte) 1;
}
return result;
}
}
================================================
FILE: benchmark/src/main/java/com/messagebus/benchmark/client/TestUtility.java
================================================
package com.messagebus.benchmark.client;
import com.messagebus.client.Messagebus;
import com.messagebus.client.MessagebusSinglePool;
import com.messagebus.client.MessagebusUnOpenException;
import com.messagebus.client.message.model.Message;
import com.messagebus.client.message.model.MessageType;
import com.messagebus.common.ExceptionHelper;
import com.messagebus.common.TestVariableInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
public class TestUtility {
private final static Log logger = LogFactory.getLog(TestUtility.class);
public static void writeFile(String fileName, long[] xArr, long[] yArr) {
String filePath = String.format(TestConfigConstant.OUTPUT_FILE_PATH_FORMAT, fileName);
File dataFile = new File(filePath);
try {
if (!dataFile.exists() && (!dataFile.createNewFile())) {
throw new RuntimeException("create new file at : " + filePath + " , failure.");
}
} catch (IOException e) {
ExceptionHelper.logException(logger, e, "writeFile");
throw new RuntimeException(e);
}
FileWriter fileWriter = null;
PrintWriter out = null;
try {
fileWriter = new FileWriter(filePath);
out = new PrintWriter(fileWriter);
out.println("#x y");
for (int i = 0; i < xArr.length; i++) {
out.println(xArr[i] + " " + yArr[i]);
}
out.flush();
} catch (IOException e) {
ExceptionHelper.logException(logger, e, "writeFile");
throw new RuntimeException(e);
} finally {
try {
if (fileWriter != null) fileWriter.close();
if (out != null) out.close();
} catch (IOException e) {
}
}
}
public static void exec(String[] cmds, boolean hasOutput) {
if (cmds == null || cmds.length == 0) {
return;
}
if (hasOutput) {
Process process = null;
try {
process = Runtime.getRuntime().exec(cmds);
} catch (IOException e) {
ExceptionHelper.logException(logger, e, "exec");
throw new RuntimeException(e.toString());
}
InputStreamReader ir = null;
LineNumberReader input = null;
try {
ir = new InputStreamReader(process.getInputStream());
input = new LineNumberReader(ir);
String line;
while ((line = input.readLine()) != null)
System.out.println(line);
} catch (IOException e) {
ExceptionHelper.logException(logger, e, "exec");
throw new RuntimeException(e.toString());
} finally {
try {
if (ir != null) ir.close();
if (input != null) input.close();
} catch (IOException e) {
}
}
}
}
public static void produce(long total) {
Message msg = TestMessageFactory.create(MessageType.QueueMessage, TestConfigConstant.MSG_BODY_SIZE_OF_BYTE);
MessagebusSinglePool singlePool = new MessagebusSinglePool(TestVariableInfo.PUBSUBER_HOST,
TestVariableInfo.PUBSUBER_PORT);
Messagebus client = singlePool.getResource();
try {
for (int i = 0; i < total; i++) {
client.produce(TestConfigConstant.PRODUCER_SECRET, TestConfigConstant.CONSUMER_QUEUE_NAME, msg, TestConfigConstant.PRODUCER_TOKEN);
}
} catch (MessagebusUnOpenException e) {
e.printStackTrace();
} finally {
singlePool.returnResource(client);
singlePool.destroy();
}
}
}
================================================
FILE: benchmark/src/main/java/com/messagebus/benchmark/client/testCase/CalcService.java
================================================
/**
* Autogenerated by Thrift Compiler (0.9.2)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package com.messagebus.benchmark.client.testCase;
import org.apache.thrift.EncodingUtils;
import org.apache.thrift.TException;
import org.apache.thrift.async.AsyncMethodCallback;
import org.apache.thrift.protocol.TTupleProtocol;
import org.apache.thrift.scheme.IScheme;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.StandardScheme;
import org.apache.thrift.scheme.TupleScheme;
import org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Generated;
import java.util.*;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2015-4-17")
public class CalcService {
public interface Iface {
public int calcSum() throws TException;
}
public interface AsyncIface {
public void calcSum(AsyncMethodCallback resultHandler) throws TException;
}
public static class Client extends org.apache.thrift.TServiceClient implements Iface {
public static class Factory implements org.apache.thrift.TServiceClientFactory {
public Factory() {
}
public Client getClient(org.apache.thrift.protocol.TProtocol prot) {
return new Client(prot);
}
public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
return new Client(iprot, oprot);
}
}
public Client(org.apache.thrift.protocol.TProtocol prot) {
super(prot, prot);
}
public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
super(iprot, oprot);
}
public int calcSum() throws TException {
send_calcSum();
return recv_calcSum();
}
public void send_calcSum() throws TException {
calcSum_args args = new calcSum_args();
sendBase("calcSum", args);
}
public int recv_calcSum() throws TException {
calcSum_result result = new calcSum_result();
receiveBase(result, "calcSum");
if (result.isSetSuccess()) {
return result.success;
}
throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "calcSum failed: unknown result");
}
}
public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface {
public static class Factory implements org.apache.thrift.async.TAsyncClientFactory {
private org.apache.thrift.async.TAsyncClientManager clientManager;
private org.apache.thrift.protocol.TProtocolFactory protocolFactory;
public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) {
this.clientManager = clientManager;
this.protocolFactory = protocolFactory;
}
public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) {
return new AsyncClient(protocolFactory, clientManager, transport);
}
}
public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) {
super(protocolFactory, clientManager, transport);
}
public void calcSum(AsyncMethodCallback resultHandler) throws TException {
checkReady();
calcSum_call method_call = new calcSum_call(resultHandler, this, ___protocolFactory, ___transport);
this.___currentMethod = method_call;
___manager.call(method_call);
}
public static class calcSum_call extends org.apache.thrift.async.TAsyncMethodCall {
public calcSum_call(AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws TException {
super(client, protocolFactory, transport, resultHandler, false);
}
public void write_args(org.apache.thrift.protocol.TProtocol prot) throws TException {
prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("calcSum", org.apache.thrift.protocol.TMessageType.CALL, 0));
calcSum_args args = new calcSum_args();
args.write(prot);
prot.writeMessageEnd();
}
public int getResult() throws TException {
if (getState() != State.RESPONSE_READ) {
throw new IllegalStateException("Method call not finished!");
}
org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
return (new Client(prot)).recv_calcSum();
}
}
}
public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName());
public Processor(I iface) {
super(iface, getProcessMap(new HashMap>()));
}
protected Processor(I iface, Map> processMap) {
super(iface, getProcessMap(processMap));
}
private static Map> getProcessMap(Map> processMap) {
processMap.put("calcSum", new calcSum());
return processMap;
}
public static class calcSum extends org.apache.thrift.ProcessFunction {
public calcSum() {
super("calcSum");
}
public calcSum_args getEmptyArgsInstance() {
return new calcSum_args();
}
protected boolean isOneway() {
return false;
}
public calcSum_result getResult(I iface, calcSum_args args) throws TException {
calcSum_result result = new calcSum_result();
result.success = iface.calcSum();
result.setSuccessIsSet(true);
return result;
}
}
}
public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(AsyncProcessor.class.getName());
public AsyncProcessor(I iface) {
super(iface, getProcessMap(new HashMap>()));
}
protected AsyncProcessor(I iface, Map> processMap) {
super(iface, getProcessMap(processMap));
}
private static Map> getProcessMap(Map> processMap) {
processMap.put("calcSum", new calcSum());
return processMap;
}
public static class calcSum extends org.apache.thrift.AsyncProcessFunction {
public calcSum() {
super("calcSum");
}
public calcSum_args getEmptyArgsInstance() {
return new calcSum_args();
}
public AsyncMethodCallback getResultHandler(final AsyncFrameBuffer fb, final int seqid) {
final org.apache.thrift.AsyncProcessFunction fcall = this;
return new AsyncMethodCallback() {
public void onComplete(Integer o) {
calcSum_result result = new calcSum_result();
result.success = o;
result.setSuccessIsSet(true);
try {
fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY, seqid);
return;
} catch (Exception e) {
LOGGER.error("Exception writing to internal frame buffer", e);
}
fb.close();
}
public void onError(Exception e) {
byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;
org.apache.thrift.TBase msg;
calcSum_result result = new calcSum_result();
{
msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
msg = (org.apache.thrift.TBase) new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
}
try {
fcall.sendResponse(fb, msg, msgType, seqid);
return;
} catch (Exception ex) {
LOGGER.error("Exception writing to internal frame buffer", ex);
}
fb.close();
}
};
}
protected boolean isOneway() {
return false;
}
public void start(I iface, calcSum_args args, AsyncMethodCallback resultHandler) throws TException {
iface.calcSum(resultHandler);
}
}
}
public static class calcSum_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("calcSum_args");
private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>();
static {
schemes.put(StandardScheme.class, new calcSum_argsStandardSchemeFactory());
schemes.put(TupleScheme.class, new calcSum_argsTupleSchemeFactory());
}
/**
* The set of fields this struct contains, along with convenience methods for finding and manipulating them.
*/
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
;
private static final Map byName = new HashMap();
static {
for (_Fields field : EnumSet.allOf(_Fields.class)) {
byName.put(field.getFieldName(), field);
}
}
/**
* Find the _Fields constant that matches fieldId, or null if its not found.
*/
public static _Fields findByThriftId(int fieldId) {
switch (fieldId) {
default:
return null;
}
}
/**
* Find the _Fields constant that matches fieldId, throwing an exception
* if it is not found.
*/
public static _Fields findByThriftIdOrThrow(int fieldId) {
_Fields fields = findByThriftId(fieldId);
if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
return fields;
}
/**
* Find the _Fields constant that matches name, or null if its not found.
*/
public static _Fields findByName(String name) {
return byName.get(name);
}
private final short _thriftId;
private final String _fieldName;
_Fields(short thriftId, String fieldName) {
_thriftId = thriftId;
_fieldName = fieldName;
}
public short getThriftFieldId() {
return _thriftId;
}
public String getFieldName() {
return _fieldName;
}
}
public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
static {
Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
metaDataMap = Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(calcSum_args.class, metaDataMap);
}
public calcSum_args() {
}
/**
* Performs a deep copy on other.
*/
public calcSum_args(calcSum_args other) {
}
public calcSum_args deepCopy() {
return new calcSum_args(this);
}
@Override
public void clear() {
}
public void setFieldValue(_Fields field, Object value) {
switch (field) {
}
}
public Object getFieldValue(_Fields field) {
switch (field) {
}
throw new IllegalStateException();
}
/**
* Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise
*/
public boolean isSet(_Fields field) {
if (field == null) {
throw new IllegalArgumentException();
}
switch (field) {
}
throw new IllegalStateException();
}
@Override
public boolean equals(Object that) {
if (that == null)
return false;
if (that instanceof calcSum_args)
return this.equals((calcSum_args) that);
return false;
}
public boolean equals(calcSum_args that) {
if (that == null)
return false;
return true;
}
@Override
public int hashCode() {
List