����λ�ã���ҳ > �����̳� > �̳� > Dubbo��ܵ�1��������Ƶ�
Java����Ҫ˵�����������RPC��ܵ���Dubbo��Ô�������࣬�����������ҵĻ�������Զ�̵������������Ƶú���������
Java����Ҫ˵�����������RPC��ܵ���Dubbo��Ô�������࣬�����������ҵĻ�������Զ�̵������������Ƶú���������
ҵ�ڶ���΢����֮����õĿ��ѡ��϶࣬������Spring Cloud��Rest��ʽ �� Dubbo��ʽ����ʹ��Dubbo��ʽ�ӶࡣDubbo��ҵ�����ã��ȶ��ָ�Ч�����ܸ���˾�з�ͬѧ��ϲ����
Dubbo���ŵ�϶࣬���磺
���ǣ�Dubbo�������˵ģ�
��֧��
���÷�����������RPC���á�Dubbo�Ķ�λ��һ��RPC��ܣ��������ĺ��ĺ�����֮�أ�����Dubbo��RPC�ĵ��ù���͸������ʹ�ÿ����߿���רע��ҵ���߼��������ù�ע�ײ�ͨ�����⡣
һ��RPC���ֻ�о۽�������������RPC���ù������ģ�飬�Ż����˹�ע��������ŵ㶼������֮����������������
���߽�RPC���õ�������̣������ һ��Ð����Ϣ�Ĵ������ ����ͨ�� ���ƺ��̵߳ĵȴ��ͻ��� ����ʵ��Զ�̷������á���һ���˼·�������������������ߵ��ǻۡ�
ѧDubbo�����Ⱦ���Ҫѧϰ����������������˼·�����ڴˣ���ʵ��һ�����׵�Զ�̷������ã���Dubbo��RPC���̼��׻���
���׵�RPC���̲������£����·�5��������ʹ��Netty����SocketͨѶ���ߡ�
public class BProcessServer {
private final int port;
public BProcessServer(int port) {
this.port = port;
}
public void start() throws InterruptedException {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer() {
@Override
protected void initChannel(SocketChannel ch) {
ch.pipeline().addLast(new BProcessServerHandler());
}
});
ChannelFuture future = bootstrap.bind(port).sync();
System.out.println("B�����˷��񣬶˿ں�: " + port);
future.channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
public static void main(String[] args) throws InterruptedException {
new BProcessServer(8088).start();
}
}
public class BProcessServerHandler extends SimpleChannelInboundHandler {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
String reqData = msg.toString(CharsetUtil.UTF_8);
System.out.println("B���̽��ܵ�����������: " + reqData);
executeMethod(ctx);
}
/**
* ִ�з���
*
* @param ctx
* @throws InterruptedException
*/
private void executeMethod(ChannelHandlerContext ctx) throws InterruptedException {
// TODO ��������Ϣ����ij�ֹ�������ɷ����������������ȣ���ʵ���Ƿ����л��Ĺ��̡�
System.out.println("�Խ��ܵ������������л���Ȼ��ʼִ�� ��Ϣ����ָ���ķ���...");
// ģ�ⷽ��ִ��
Thread.sleep(2000);
System.out.println("ִ����ϣ����ؽ��...");
// ����� ֪ͨ�� A ����
ByteBuf dataByteBuf = ctx.alloc().buffer().writeBytes("Task completed".getBytes(CharsetUtil.UTF_8));
ctx.writeAndFlush(dataByteBuf);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}
public class AProcessClient {
private final String host;
private final int port;
private final Object lock = new Object(); // ����������
public AProcessClient(String host, int port) {
this.host = host;
this.port = port;
}
public void start() throws InterruptedException {
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer() {
@Override
protected void initChannel(SocketChannel ch) {
ch.pipeline().addLast(new AProcessClientHandler(lock));
}
});
ChannelFuture future = bootstrap.connect(host, port).sync();
System.out.println("A������B���̽�����ͨ������");
Channel channel = future.channel();
// ����Զ�̵���
callRemoteMethod(channel);
channel.closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
/**
* ִ�з���
*
* @param channel
* @throws InterruptedException
*/
private void callRemoteMethod(Channel channel) throws InterruptedException {
//TODO �˴���Ҫ�����õķ����Ͳ���������Ð��������л����������ʡȥ�˹��̡�
System.out.println("A���̽� ����ķ����Ͳ��� �������л���Ȼ����B���̷����������...");
ByteBuf dataByteBuf = channel.alloc().buffer().writeBytes("Start call method".getBytes(CharsetUtil.UTF_8));
channel.writeAndFlush(dataByteBuf);
// ʹ��wait�ȴ�B����֪ͨ
synchronized (lock) {
System.out.println("A���̵ȴ�B���̵���Ӧ...");
lock.wait(); // �ȴ�֪ͨ
}
System.out.println("A�����յ���B���̵���Ӧ֪ͨ����������...");
}
public static void main(String[] args) throws InterruptedException {
new AProcessClient("localhost", 8088).start();
}
}
lock.wait()
�Ժ�Ĵ�����Լ���ִ�С�
public class AProcessClientHandler extends SimpleChannelInboundHandler {
private final Object lock;
public AProcessClientHandler(Object lock) {
this.lock = lock;
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
String resData = msg.toString(CharsetUtil.UTF_8);
System.out.println("A���̽��ܵ�����Ӧ����: " + resData);
// B ����������ɣ�ʹ�� notify ���ѵȴ����߳�
synchronized (lock) {
lock.notify(); // ���� A ����
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}
Dubbo���������˼·�����࣬��ֻ������һ���Ǿ���RPC�ĵ��ù��̡�������һ�����׵�RPCԶ�̵��õ�ʾ������������Dubbo��Ô����Դ�룬ϣ�������а�����
ï¿½ï¿½Æªï¿½ï¿½á£¡ï¿½ï¿½Ó ï¿½ï¿½×¢ï¿½ï¿½ï¿½ï¿½V(yclxiao)������ȫ������(����Ա��֧��)
Ô�����ӣ� https://mp.weixin.qq.com/s/J0fzDH-iqGnnnjqaXMLs-A
ʹ��Blender���ɳ���ģ��
�Ķ�ȫ����������ERA5�����ط���
�Ķ�Xpath���������﷨
�Ķ�����ѧϰ�������繹�����£�
�Ķ���ΪMateƷ��ʢ�䣺HarmonyOS NEXT�ӳ�����Ϸ���ܵõ�����ͷ�
�Ķ�ʵ�ֶ��󼯺���DataTable���໥ת��
�Ķ�Ӳ�̵Ļ���֪ʶ��ѡ��ָ��
�Ķ�������й��ƶ��ı�ͼ��ײ�
�Ķ�����NEXTԪ�����������ѿ����ϼ���Ʒ
�Ķ��ᳲ���С������������Ƽ��رշ���
�Ķ������ArcMap�����н���դ��ͼ���ز�������
�Ķ��㷨�����ݽṹ 1 - ģ��
�Ķ���Ѷ�����߿ͷ���Ӫ��ϵͳ����
�Ķ���Ѷ��Ƶҹ��ģʽ���ý̳�
�Ķ����ں���NEXT��Ѫ���Ŵ���������������
�Ķ�5. Spring Cloud OpenFeign ����ʽ WebService �ͻ��˵ij���ϸʹ��
�Ķ�Java����ģʽ����̬�����Ͷ�̬�����ĶԱȷ���
�Ķ�Win11�ʼDZ����Զ�����Ӧ�õ���ɫ����ʾ����
�Ķ�˼�� V1.5.6 ��׿��
��ս�귨 V7.5.0 ��׿��
У��������������׵������� V1.0 ��׿��
��˸֮�� V1.9.7 ��׿��
������Ե����� v1.0.4 ��׿��
������֮ŠV5.2.3 ��׿��
��������������Դ V1.0 ��׿��
���֮Ϣ V1.0 ��׿��
��ħ������������䣩 V1.0 ��׿��
���ں�������ϵ�����������������վ�����������������Ƽ�����
Ƶ�� ����Ƶ��������ר������������׿�������app����
�Ƽ� ��Ô���������°��������ܿ������ز���
���� ����ɫ������������ ���������ս������������
ɨ��ά�����������ֻ��汾��
ɨ��ά����������΢�Ź��ںţ�
��վ�������������������ϴ��������ַ���İ�Ȩ���뷢�ʼ�[email protected]
��ICP��2022002427��-10 �湫��������43070202000427��© 2013~2025 haote.com ������