use of com.akaxin.common.netty.NettyClient2 in project openzaly by akaxincom.
the class WritePackage method syncWrite.
public byte[] syncWrite(String action, byte[] byteData) {
try {
CoreProto.TransportPackageData.Builder packageDataBuilder = CoreProto.TransportPackageData.newBuilder();
Map<Integer, String> header = new HashMap<Integer, String>();
header.put(CoreProto.HeaderKey.SITE_SERVER_VERSION_VALUE, CommandConst.SITE_VERSION);
packageDataBuilder.putAllHeader(header);
packageDataBuilder.setData(ByteString.copyFrom(byteData));
NettyClient2 nettyClient = new NettyClient2();
nettyClient.connect(AKAXIN_PUSH_ADDRESS, AKAXIN_PUSH_PORT);
Future<IRedisCommandResponse> future = nettyClient.sendRedisCommand(new RedisCommand().add(CommandConst.PROTOCOL_VERSION).add(action).add(packageDataBuilder.build().toByteArray()));
IRedisCommandResponse response = future.get(5, TimeUnit.SECONDS);
nettyClient.disconnect();
if (response != null && response.isSuccess()) {
return getPackageBytes(response.getRedisCommand());
}
logger.debug("write push to platform finish response={}", response);
} catch (Exception e) {
logger.error("sync send package error ", e);
}
return null;
}
use of com.akaxin.common.netty.NettyClient2 in project openzaly by akaxincom.
the class WritePackage method asyncWrite.
public void asyncWrite(String action, byte[] byteData) {
try {
CoreProto.TransportPackageData.Builder packageDataBuilder = CoreProto.TransportPackageData.newBuilder();
Map<Integer, String> header = new HashMap<Integer, String>();
header.put(CoreProto.HeaderKey.SITE_SERVER_VERSION_VALUE, CommandConst.SITE_VERSION);
packageDataBuilder.putAllHeader(header);
packageDataBuilder.setData(ByteString.copyFrom(byteData));
NettyClient2 nettyClient = new NettyClient2();
nettyClient.connect(AKAXIN_PUSH_ADDRESS, AKAXIN_PUSH_PORT);
Future<IRedisCommandResponse> future = nettyClient.sendRedisCommand(new RedisCommand().add(CommandConst.PROTOCOL_VERSION).add(action).add(packageDataBuilder.build().toByteArray()));
IRedisCommandResponse response = future.get(5, TimeUnit.SECONDS);
logger.debug("write push to platform finish response={}", response);
nettyClient.disconnect();
} catch (Exception e) {
logger.error("async send package to platform error", e);
}
}
Aggregations