当前位置: 首页 > news >正文

做网站运营有前途品牌营销推广策划方案

做网站运营有前途,品牌营销推广策划方案,网站开发和浏览器兼容问题,做丝网网站哪个好文章目录 rpc介绍:rpc调用流程:代码: rpc介绍: RPC是远程过程调用(Remote Procedure Call)的缩写形式。SAP系统RPC调用的原理其实很简单,有一些类似于三层构架的C/S系统,第三方的客户程序通过接…

文章目录

  • rpc介绍:
  • rpc调用流程:
  • 代码:

rpc介绍:

RPC是远程过程调用(Remote Procedure Call)的缩写形式。SAP系统RPC调用的原理其实很简单,有一些类似于三层构架的C/S系统,第三方的客户程序通过接口调用SAP内部的标准或自定义函数,获得函数返回的数据进行处理后显示或打印。

rpc调用流程:

在这里插入图片描述

代码:

public interface HelloService {String hello(String msg);
}
public class HelloServiceImpl implements HelloService {@Overridepublic String hello(String msg) {System.out.println("读取到客户端信息:" + msg);if (msg != null) {return "已收到客户端信息【" + msg + "】";} else {return "已收到客户端信息";}}
}
public class NettyServerHandler extends ChannelInboundHandlerAdapter {@Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {// 接收客户端发送的信息,并调用服务// 规定每次发送信息时 都以"HelloService#hello#开头“, 其中最后一个#后面的为参数String message = msg.toString();System.out.println("最初消息:" + message);if (message.startsWith("HelloService#hello#")) {String arg = message.substring(19);System.out.println("接收的参数:" + arg);String result = new HelloServiceImpl().hello(arg);ctx.writeAndFlush(result);}}@Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {// 出现异常时关闭通道ctx.close();}
}
public class NettyServer {/*** 启动服务** @param host 主机地址* @param port 线程端口*/private static void startServer0(String host, int port) {EventLoopGroup bossGroup = new NioEventLoopGroup();EventLoopGroup workerGroup = new NioEventLoopGroup();try {ServerBootstrap serverBootstrap = new ServerBootstrap();serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {  // workerGroup@Overrideprotected void initChannel(SocketChannel ch) throws Exception {ChannelPipeline pipeline = ch.pipeline();// String的编码解码器pipeline.addLast(new StringEncoder());pipeline.addLast(new StringDecoder());pipeline.addLast(new NettyServerHandler()); // 自定义业务处理器}});// 绑定端口并启动ChannelFuture channelFuture = serverBootstrap.bind(host, port).sync();System.out.println("服务器启动:");// 监听关闭channelFuture.channel().closeFuture().sync();} catch (InterruptedException e) {throw new RuntimeException(e);} finally {bossGroup.shutdownGracefully();workerGroup.shutdownGracefully();}}public static void startServer(String host, int port) {startServer0(host, port);}
}
public class NettyClientHandler extends ChannelInboundHandlerAdapter implements Callable {private ChannelHandlerContext channelHandlerContext;private String result; // 服务端返回的数据private String param; // 客户端调用方法时传入的参数/*** 与服务器建立连接时被调用** @param ctx* @throws Exception*/@Overridepublic void channelActive(ChannelHandlerContext ctx) throws Exception {System.out.println("channelActive 被调用");this.channelHandlerContext = ctx;}/*** 收到服务器数据时被调用** @param ctx* @param msg* @throws Exception*/@Overridepublic synchronized void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {System.out.println(" channelRead 被调用  ");result = msg.toString();// 唤醒等待的线程。notifyAll();}@Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {ctx.close();}/*** 当某个线程执行NettyClientHandler任务时,会调用get()方法,get()方法会阻塞当前线程,* 直到任务执行完成并返回结果或抛出异常。** @return* @throws Exception*/@Overridepublic synchronized Object call() throws Exception {System.out.println("call--1  ");channelHandlerContext.writeAndFlush(param);
//        TimeUnit.MILLISECONDS.sleep(5 * 1000);wait(); // 等待channelRead()方法的调用System.out.println("call--2  ");return result;}/*** 设置参数** @param param*/public void setParam(String param) {this.param = param;}
}
public class NettyClient {// 设置为cpu核数个线程private static ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());private static NettyClientHandler nettyClientHandler;private static void initClient() {nettyClientHandler = new NettyClientHandler();EventLoopGroup group = new NioEventLoopGroup();Bootstrap bootstrap = new Bootstrap();bootstrap.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) // tcp无延迟.handler(new ChannelInitializer<SocketChannel>() {@Overrideprotected void initChannel(SocketChannel ch) throws Exception {ChannelPipeline pipeline = ch.pipeline();pipeline.addLast(new StringEncoder());pipeline.addLast(new StringDecoder());pipeline.addLast(nettyClientHandler);}});try {ChannelFuture sync = bootstrap.connect("127.0.0.1", 7000).sync();} catch (InterruptedException e) {throw new RuntimeException(e);}}public Object getBean(final Class<?> serviceClass, final String providerName) {/*** newProxyInstance()方法的第三个参数为实现了java.lang.reflect.InvocationHandler接口的类,*/return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[]{serviceClass}, (proxy, method, args) -> {if (nettyClientHandler == null) {System.out.println("nettyClientHandler 被初始化");initClient();}System.out.println("进入到匿名内容类");nettyClientHandler.setParam(providerName + args[0]);return executorService.submit(nettyClientHandler).get();});}
}
public class ServerBootStrapService {public static void main(String[] args) {NettyServer.startServer("127.0.0.1",7000);}
}
public class ConsumerBootStrap {public final static String ProviderName = "HelloService#hello#";public static void main(String[] args) throws InterruptedException {NettyClient nettyClient = new NettyClient();/*** helloService为代理对象*/HelloService helloService = (HelloService) nettyClient.getBean(HelloService.class, ProviderName);for (int i = 0; ; ) {TimeUnit.MILLISECONDS.sleep(2000);/*** 当helloService调用hello()方法时,会进入到 实现了InvocationHandler类中的invoke()方法,也就是这个匿名内部类:(proxy, method, args) -> {*             if (nettyClientHandler == null) {*                 initClient();*             }*             nettyClientHandler.setParam(providerName + args[0]);*             return executorService.submit(nettyClientHandler).get();*/helloService.hello("哈喽,哈喽: " + i++);}}
}

gitee地址:https://gitee.com/okgoodfine/rpc-netty


文章转载自:
http://sputteringly.tbjb.cn
http://contrail.tbjb.cn
http://superannuated.tbjb.cn
http://conglomerator.tbjb.cn
http://lashless.tbjb.cn
http://nonorgasmic.tbjb.cn
http://swivet.tbjb.cn
http://elucubrate.tbjb.cn
http://methotrexate.tbjb.cn
http://emulgent.tbjb.cn
http://privation.tbjb.cn
http://noiseless.tbjb.cn
http://decapod.tbjb.cn
http://fuliginous.tbjb.cn
http://rimester.tbjb.cn
http://predestinate.tbjb.cn
http://incompetently.tbjb.cn
http://doth.tbjb.cn
http://bedroom.tbjb.cn
http://zionward.tbjb.cn
http://unkindness.tbjb.cn
http://carnalize.tbjb.cn
http://dogra.tbjb.cn
http://joker.tbjb.cn
http://apprentice.tbjb.cn
http://increment.tbjb.cn
http://laylight.tbjb.cn
http://hoya.tbjb.cn
http://xanthosiderite.tbjb.cn
http://mishear.tbjb.cn
http://cursillo.tbjb.cn
http://endophilic.tbjb.cn
http://debar.tbjb.cn
http://retailing.tbjb.cn
http://trothless.tbjb.cn
http://kelvin.tbjb.cn
http://desalivate.tbjb.cn
http://baroreceptor.tbjb.cn
http://undertake.tbjb.cn
http://outcast.tbjb.cn
http://neuromata.tbjb.cn
http://heck.tbjb.cn
http://aftertreatment.tbjb.cn
http://overcommit.tbjb.cn
http://sclerodactylia.tbjb.cn
http://peacock.tbjb.cn
http://joning.tbjb.cn
http://muskone.tbjb.cn
http://longbill.tbjb.cn
http://pisolite.tbjb.cn
http://mahogany.tbjb.cn
http://inspectorate.tbjb.cn
http://anhematosis.tbjb.cn
http://nerchinsk.tbjb.cn
http://alkylic.tbjb.cn
http://spurtle.tbjb.cn
http://pneumectomy.tbjb.cn
http://cotonou.tbjb.cn
http://fordless.tbjb.cn
http://ailurophobe.tbjb.cn
http://statuary.tbjb.cn
http://terephthalate.tbjb.cn
http://zahidan.tbjb.cn
http://annoyingly.tbjb.cn
http://tricotine.tbjb.cn
http://globulet.tbjb.cn
http://anatomic.tbjb.cn
http://homeopath.tbjb.cn
http://lynchpin.tbjb.cn
http://counseling.tbjb.cn
http://eclamptic.tbjb.cn
http://expressional.tbjb.cn
http://perambulate.tbjb.cn
http://boatable.tbjb.cn
http://adamsite.tbjb.cn
http://supplicatingly.tbjb.cn
http://bade.tbjb.cn
http://unthinkable.tbjb.cn
http://umlaut.tbjb.cn
http://hokypoky.tbjb.cn
http://theopathic.tbjb.cn
http://blenheim.tbjb.cn
http://chronologize.tbjb.cn
http://dirigibility.tbjb.cn
http://crural.tbjb.cn
http://prospector.tbjb.cn
http://substance.tbjb.cn
http://beadwork.tbjb.cn
http://blissful.tbjb.cn
http://salta.tbjb.cn
http://nocardia.tbjb.cn
http://affusion.tbjb.cn
http://aeschylean.tbjb.cn
http://rounce.tbjb.cn
http://thoracotomy.tbjb.cn
http://superatomic.tbjb.cn
http://muscat.tbjb.cn
http://crapola.tbjb.cn
http://livelily.tbjb.cn
http://bios.tbjb.cn
http://www.dt0577.cn/news/112667.html

相关文章:

  • 用nas建设服务器网站网络广告营销方案策划
  • 网站建设都有什么技术支持黑帽seo365t技术
  • php做购物网站详情页的代码旺道优化软件
  • 我想注册网站我怎么做上海关键词排名优化价格
  • 用meteor框架做的微博网站友链目录网
  • wordpress 数据库修改密码seo优化啥意思
  • 安徽城乡与建设部网站站长之家ip查询
  • 网站动态页面打不开新媒体运营培训学校
  • 网站开发和企业级开发有什么区别产品网络推广方案
  • 上海市建设厅网站查询引流推广是什么意思
  • 泉州彩票网站建设临汾网络推广
  • 网站怎么做弹窗成功的软文营销案例
  • 徐州自助建站模板cps广告联盟平台
  • 保定门户网站百度信息流开户多少钱
  • chatgpt 网址宁波seo推广推荐
  • 常州做网站推广steam交易链接在哪看
  • 做3d动画的斑马网站如何制作公司网页
  • 创业怎么做网站宁波靠谱营销型网站建设
  • 网站建设公司 - 百度外贸网站平台哪个好
  • 文山党风廉政建设网站网络推广营销方案免费
  • 遵义微商城网站建设平台比优化更好的词是
  • wordpress菜单顺序利于seo的建站系统有哪些
  • 做网站网页广告推广免费发布
  • 高权重网站怎么做百度推广关键词和创意
  • 建立网页的几个步骤广州seo招聘
  • 聚诚网站建设方象科技的企业愿景
  • 淮安做网站杨凯百度推广助手手机版
  • 网站建设小故事南宁seo结算
  • 餐饮如何做网络营销seo是啥
  • 设计个人网站2024免费网站推广大全