use of io.seata.core.protocol.RpcMessage in project seata by seata.
the class AbstractNettyRemotingServer method sendAsyncResponse.
@Override
public void sendAsyncResponse(RpcMessage rpcMessage, Channel channel, Object msg) {
Channel clientChannel = channel;
if (!(msg instanceof HeartbeatMessage)) {
clientChannel = ChannelManager.getSameClientChannel(channel);
}
if (clientChannel != null) {
RpcMessage rpcMsg = buildResponseMessage(rpcMessage, msg, msg instanceof HeartbeatMessage ? ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE : ProtocolConstants.MSGTYPE_RESPONSE);
super.sendAsync(clientChannel, rpcMsg);
} else {
throw new RuntimeException("channel is error.");
}
}
use of io.seata.core.protocol.RpcMessage in project seata by seata.
the class ClientChannelHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof RpcMessage) {
RpcMessage rpcMessage = (RpcMessage) msg;
int msgId = rpcMessage.getId();
DefaultPromise future = (DefaultPromise) client.futureMap.remove(msgId);
if (future != null) {
future.setSuccess(msg);
} else {
LOGGER.warn("miss msg id:{}", msgId);
}
}
}
use of io.seata.core.protocol.RpcMessage in project seata by seata.
the class ProtocolV1Client method sendRpc.
public Future sendRpc(Map<String, String> head, Object body) {
int msgId = idGenerator.incrementAndGet();
RpcMessage rpcMessage = new RpcMessage();
rpcMessage.setId(msgId);
rpcMessage.setCodec(SerializerType.SEATA.getCode());
rpcMessage.setCompressor(ProtocolConstants.CONFIGURED_COMPRESSOR);
rpcMessage.setHeadMap(head);
rpcMessage.setBody(body);
rpcMessage.setMessageType(ProtocolConstants.MSGTYPE_RESQUEST_SYNC);
if (channel != null) {
DefaultPromise promise = new DefaultPromise(defaultEventExecutor);
futureMap.put(msgId, promise);
channel.writeAndFlush(rpcMessage);
return promise;
} else {
LOGGER.warn("channel is null");
}
return null;
}
use of io.seata.core.protocol.RpcMessage in project seata by seata.
the class ProtocolV1Client method main.
// can test tps
public static void main(String[] args) {
ProtocolV1Client client = new ProtocolV1Client();
client.connect("127.0.0.1", 8811, 500);
Map<String, String> head = new HashMap<>();
head.put("tracerId", "xxadadadada");
head.put("token", "adadadad");
BranchCommitRequest body = new BranchCommitRequest();
body.setBranchId(12345L);
body.setApplicationData("application");
body.setBranchType(BranchType.AT);
body.setResourceId("resource-1234");
body.setXid("xid-1234");
final int threads = 50;
final AtomicLong cnt = new AtomicLong(0);
// no queue
final ThreadPoolExecutor service1 = new ThreadPoolExecutor(threads, threads, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("client-", false));
for (int i = 0; i < threads; i++) {
service1.execute(() -> {
while (true) {
try {
Future future = client.sendRpc(head, body);
RpcMessage resp = (RpcMessage) future.get(200, TimeUnit.MILLISECONDS);
if (resp != null) {
cnt.incrementAndGet();
}
} catch (Exception e) {
// ignore
}
}
});
}
Thread thread = new Thread(new Runnable() {
private long last = 0;
@Override
public void run() {
while (true) {
long count = cnt.get();
long tps = count - last;
LOGGER.error("last 1s invoke: {}, queue: {}", tps, service1.getQueue().size());
last = count;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}, "Print-tps-THREAD");
thread.start();
}
use of io.seata.core.protocol.RpcMessage in project seata by seata.
the class ServerChannelHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
Channel channel = ctx.channel();
if (msg instanceof RpcMessage) {
((RpcMessage) msg).setMessageType(ProtocolConstants.MSGTYPE_RESPONSE);
}
channel.writeAndFlush(msg);
}
Aggregations