@少帮主 你好,想跟你请教个问题:
import java.io.IOException;
import org.zbus.broker.Broker;
import org.zbus.broker.BrokerConfig;
import org.zbus.broker.SingleBroker;
import org.zbus.kit.ConfigKit;
import org.zbus.rpc.RpcProcessor;
import org.zbus.rpc.mq.Service;
import org.zbus.rpc.mq.ServiceConfig;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
public class RPCService {
private Prop prop = PropKit.use("play.properties");
private String ip = prop.get("zbus.host");
private String port = prop.get("zbus.port");
private ServiceConfig config;
private Service svc;
private boolean isStart = false;
public boolean isStart() {
return isStart;
}
public RPCService(){
final String serverAddress = ConfigKit.option(new String[]{}, "-b", ip+":"+port);
final int threadCount = ConfigKit.option(new String[]{}, "-c", 32);
final String mq = ConfigKit.option(new String[]{}, "-mq", "RPCMessageCenter");
RpcProcessor processor = new RpcProcessor();
//增加模块,模块名在调用时需要指定
processor.addModule(new MessageService());
//配置Broker
BrokerConfig brokerCfg = new BrokerConfig();
brokerCfg.setServerAddress(serverAddress);
/*brokerCfg.setMaxTotal(threadCount);
brokerCfg.setMinIdle(threadCount);*/
Broker broker = null;
try {
broker = new SingleBroker(brokerCfg);
} catch (IOException e) {
e.printStackTrace();
}
config = new ServiceConfig();
//config.setConsumerCount(threadCount);
config.setMq(mq);
config.setBroker(broker);
config.setMessageProcessor(processor);
svc = new Service(config);
}
public boolean start(){
try {
svc.start();
isStart = true;
return isStart;
} catch (IOException e) {
e.printStackTrace();
return isStart;
}
}
}
报错:
Exception in thread "Thread-9" org.zbus.mq.MqException: {"@type":"org.zbus.rpc.RpcCodec$Request","encoding":"UTF-8","method":"sendMessage","module":"","paramTypes":null,"params":["{\"from\":\"Test\",\"to\":\"fb6d56af5fdd4ce9b49ee0f865f83354\"}"]}
at org.zbus.mq.Consumer.recv(Consumer.java:88)
at org.zbus.mq.Consumer$1.run(Consumer.java:145)
at java.lang.Thread.run(Thread.java:745)
<p>
//测试代码
</p>
<p>
public static void RPCMessageCenter() {<br>
Prop prop = PropKit.use("play.properties");
String ip = prop.get("zbus.host");
String port = prop.get("zbus.port");
BrokerConfig brokerConfig = new BrokerConfig();
brokerConfig.setServerAddress(ip + ":" + port);
Broker broker = null;
try {
broker = new SingleBroker(brokerConfig);
} catch (IOException e) {
e.printStackTrace();
}
MqInvoker messageInvoker = new MqInvoker(broker, "RPCMessageCenter");
RpcInvoker rpc = new RpcInvoker(messageInvoker);
rpc.setVerbose(true);
Map<String, String> map = new HashMap<String, String>();
map.put("from", "Test");
map.put("to", "fb6d56af5fdd4ce9b49ee0f865f83354");
boolean s = rpc.invokeSync(boolean.class, "sendMessage", JsonKit.toJson(map));
try {
broker.close();
} catch (IOException e) {
e.printStackTrace();
}
}
报错:
2015-12-31 11:07:48
[INFO]-[Thread: main]-[org.zbus.rpc.RpcInvoker.invokeSync()]: [REP]: Time cost=10430ms
null
Exception in thread "main" org.zbus.rpc.RpcException: module()-method(sendMessage) request timeout
GET / HTTP/1.1
ack: 0
cmd: produce
connection: Keep-Alive
content-length: 388
id: 1f01ede3-d068-4e75-a851-6f8217331148
mq: RPCMessageCenter
{"@type":"org.zbus.rpc.RpcCodec$Request","encoding":"UTF-8","method":"sendMessage","module":"","paramTypes":null,"params":["{"from":"Test","to":"fb6d56af5fdd4ce9b49ee0f865f83354"}"]}
at org.zbus.rpc.RpcInvoker.invokeSync(RpcInvoker.java:161)
at org.zbus.rpc.RpcInvoker.invokeSync(RpcInvoker.java:102)
at org.zbus.rpc.RpcInvoker.invokeSync(RpcInvoker.java:75)
at com.zjhcsoft.test.ZBusTest.RPCMessageCenter(ZBusTest.java:341)
at com.zjhcsoft.test.ZBusTest.main(ZBusTest.java:353)
timeout时间设置长点呐
超时的原因分析:
1.service端异常
2.service执行时间过长,导致超时。
建议service单个方法不要执行长时间任务。可拆分为多个接口!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。