use of pers.cy.iris.commons.exception.RequestTimeoutException in project iris by chicc999.
the class NettyClientTest method init.
private void init() {
nettyClient = new NettyClient(new NettyClientConfig());
try {
nettyClient.start();
} catch (Exception e) {
e.printStackTrace();
}
try {
Channel channel = nettyClient.createChannelSync(new InetSocketAddress("localhost", 50088));
PutMessage command = new PutMessage();
command.setProducerId(new ProducerId(new ConnectionId(new ClientId("1.0", "localhost", System.currentTimeMillis()))));
Message message = new Message("test", "第一条消息", "1");
message.setApp("app");
Message[] messages = new Message[1];
messages[0] = message;
command.setMessages(messages);
Command command1 = nettyClient.sync(channel, command, 10000);
if (command1.getHeader().getStatus() != 200) {
System.out.println(command1.getHeader().getError());
}
} catch (ConnectException e) {
e.printStackTrace();
} catch (RequestTimeoutException e) {
e.printStackTrace();
} catch (RemotingIOException e) {
e.printStackTrace();
}
}
use of pers.cy.iris.commons.exception.RequestTimeoutException in project iris by chicc999.
the class NettyTransport method sync.
@Override
public Command sync(Channel channel, Command command, int timeout) throws RemotingIOException, RequestTimeoutException {
int sendTimeout = timeout <= 0 ? config.getSendTimeout() : timeout;
// 同步调用
ResponseFuture future = async(channel, command, null);
future.setTimeout(sendTimeout);
Command response;
try {
response = future.get(sendTimeout);
} catch (InterruptedException e) {
throw new RemotingIOException("线程被中断", e);
}
if (!future.isDone()) {
throw new RequestTimeoutException("请求 requestId=" + command.getRequestId() + " 超时");
}
if (!future.isSuccess()) {
throw new RemotingIOException(future.getCause());
}
return response;
}
Aggregations