-
Notifications
You must be signed in to change notification settings - Fork 63
/
ThriftWithAMQPRpc.java
executable file
·73 lines (61 loc) · 2.55 KB
/
ThriftWithAMQPRpc.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.messagebus.client.feature;
import com.messagebus.client.Messagebus;
import com.messagebus.client.MessagebusSinglePool;
import com.messagebus.client.WrappedRpcServer;
import com.messagebus.client.core.BaseTestCase;
import com.messagebus.client.extension.thrift.TAMQPClientTransport;
import com.messagebus.client.extension.thrift.ThriftMessageHandler;
import com.messagebus.common.TestVariableInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TJSONProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.transport.TTransport;
/**
* Created by yanghua on 4/17/15.
*/
public class ThriftWithAMQPRpc extends BaseTestCase {
private static final Log logger = LogFactory.getLog(ThriftWithAMQPRpc.class);
@Override
public void setUp() throws Exception {
super.setUp();
}
@Override
public void tearDown() throws Exception {
super.tearDown();
}
public void testThriftRpc() throws Exception {
TTransport transport = new TAMQPClientTransport(this.client,
"kliwhiduhaiucvarkjajksdbfkjabw",
"emapDemoRpcResponse",
"klasehnfkljashdnflhkjahwlekdjf",
10000);
transport.open();
TProtocol protocol = new TJSONProtocol(transport);
CalcService.Client client = new CalcService.Client(protocol);
int result = client.calcSum();
logger.info(result);
transport.close();
}
public static void main(String[] args) {
String zkConnectionStr = TestVariableInfo.ZK_CONNECTION_STRING;
MessagebusSinglePool singlePool = new MessagebusSinglePool(zkConnectionStr);
Messagebus client = singlePool.getResource();
//server code
WrappedRpcServer rpcServer = null;
try {
TProcessor processor = new CalcService.Processor(new CalcServiceImpl());
TProtocolFactory inProtocolFactory = new TJSONProtocol.Factory();
TProtocolFactory outProtocolFactory = new TJSONProtocol.Factory();
rpcServer = client.buildRpcServer("mshdfjbqwejhfgasdfbjqkygaksdfa",
new ThriftMessageHandler(processor, inProtocolFactory, outProtocolFactory));
rpcServer.mainLoop();
} finally {
rpcServer.close();
singlePool.returnResource(client);
singlePool.destroy();
}
}
}