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

制作网站商城商家商城小程序

制作网站商城,商家商城小程序,网站开发的接口文档,网站连接如何做二维码rpc框架搭建 consumer 消费者应用 provider 提供的服务 Provider-common 公共类模块 rpc 架构 service-Registration 服务发现 nacos nacos配置中心 load-balancing 负载均衡 redis-trench 手写redis实现和链接 package com.trench.protocol;import com.trench.enumUtil.Redis…rpc框架搭建 consumer 消费者应用 provider 提供的服务 Provider-common 公共类模块 rpc 架构 service-Registration 服务发现 nacos nacos配置中心 load-balancing 负载均衡 redis-trench 手写redis实现和链接 package com.trench.protocol;import com.trench.enumUtil.RedisRepEnum; import redis.clients.jedis.util.SafeEncoder;import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.Arrays;public class Protocol {public static final String DOLLAR$;public static final String STAR*;public static final String BLANK\r\n;public static void sendCommand(OutputStream outputStream, RedisRepEnum redisRepEnum,byte [] ... args){StringBuffer strnew StringBuffer();str.append(STAR).append(args.length-1).append(BLANK);str.append(DOLLAR).append(redisRepEnum.name().length()).append(BLANK);str.append(redisRepEnum).append(BLANK);Arrays.stream(args).forEach(arg-{str.append(DOLLAR).append(arg.length).append(BLANK);str.append(new String(arg)).append(BLANK);});try {outputStream.write(str.toString().getBytes(StandardCharsets.UTF_8));} catch (IOException e) {e.printStackTrace();}}public static final byte[] toByteArray(long value) {return SafeEncoder.encode(String.valueOf(value));} } package com.trench.api;import com.trench.connection.Connetion; import com.trench.enumUtil.RedisRepEnum; import com.trench.protocol.Protocol; import com.trench.util.SerializeUtils; import redis.clients.jedis.BuilderFactory;import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Set;public class Client {Connetion connetion;public Client(String host,Integer port){connetionnew Connetion(port,host);}public void set(final String key, final String values){connetion.sendCommand( RedisRepEnum.SET,key.getBytes(StandardCharsets.UTF_8), SerializeUtils.serialize(values));}public Object get(final String key){connetion.sendCommand(RedisRepEnum.GET,key.getBytes(StandardCharsets.UTF_8));return connetion.getData();}public void delete(final String key){connetion.sendCommand(RedisRepEnum.GETDEL,key.getBytes(StandardCharsets.UTF_8));}//封装redis的过期时间public void expire(String key, long seconds){connetion.sendCommand(RedisRepEnum.EXISTS, key.getBytes(StandardCharsets.UTF_8), Protocol.toByteArray(seconds));}//是否存在keypublic boolean exists(final String key) {connetion.sendCommand(RedisRepEnum.EXISTS, key.getBytes(StandardCharsets.UTF_8));return (Long)connetion.getData()1L;}//查找key中set包含public SetString keys(final String key){connetion.sendCommand(RedisRepEnum.KEYS,key.getBytes(StandardCharsets.UTF_8));return (Set) BuilderFactory.STRING_SET.build((List)connetion.getData());} } rpc框架核心代码 package com.trench.protocol;import com.trench.SerializeUtils; import com.trench.frawork.Invocation; import com.trench.nacos.dome.NacosHttp; import org.apache.commons.io.IOUtils;import java.io.*; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets;public class HttpClient {public String send(String hostName, Integer port, Invocation invocation) throws IOException {//读取nacos中的配置用户的请求方式。如http POST get等NacosHttp nacosHttpnew NacosHttp();try {URL urlnew URL(nacosHttp.getHttp(),hostName,port,nacosHttp.getFile());HttpURLConnection httpURLConnection (HttpURLConnection)url.openConnection();httpURLConnection.setRequestMethod(nacosHttp.getRequestMethod());httpURLConnection.setDoOutput(true);//配置OutputStream outputStreamhttpURLConnection.getOutputStream();ObjectOutputStream oss new ObjectOutputStream(outputStream);oss.writeObject(SerializeUtils.serialize(invocation));oss.flush();oss.close();InputStream inputStream httpURLConnection.getInputStream();return (String) SerializeUtils.deSerialize(IOUtils.toString(inputStream).getBytes(StandardCharsets.UTF_8));} catch (MalformedURLException e) {throw e;} catch (IOException e) {throw e;}} } 启动tomcat package com.trench.protocol;import org.apache.catalina.*; import org.apache.catalina.connector.Connector; import org.apache.catalina.core.StandardContext; import org.apache.catalina.core.StandardEngine; import org.apache.catalina.core.StandardHost; import org.apache.catalina.startup.Tomcat;public class HttpServer {public void start(String hostname,Integer port){//读取用户配置Tomcat tomcatnew Tomcat();Server server tomcat.getServer();Service service server.findService(Tomcat);Connector connectornew Connector();connector.setPort(port);Engine enginenew StandardEngine();engine.setDefaultHost(hostname);Host hostnew StandardHost();host.setName(hostname);String contextPash;Context contextnew StandardContext();context.setPath(contextPash);context.addLifecycleListener(new Tomcat.FixContextListener());host.addChild(context);engine.addChild(host);service.setContainer(engine);service.addConnector(connector);tomcat.addServlet(contextPash,dispatcher,new DispatcherServlet());context.addServletMappingDecoded(/*,dispatcher);try {tomcat.start();tomcat.getServer().await();}catch (LifecycleException e){e.printStackTrace();}} } package com.trench.protocol;import com.trench.frawork.Invocation; import com.trench.register.LocalRegister; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils;import java.io.IOException; import java.io.ObjectInputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets;public class HttpServerHandler extends HttpServer {public void handler(HttpServletRequest request, HttpServletResponse response){//可自行添加为心跳监听等操作//处理请求try {Invocation invocation (Invocation)new ObjectInputStream(request.getInputStream()).readObject();String interfaceName invocation.getInterfaceName();//接口名称Class aClass LocalRegister.get(interfaceName,invocation.getVersion());Method method aClass.getMethod(invocation.getMethodName(), invocation.getParameterTypes());String invoke (String) method.invoke(aClass.newInstance(), invocation.getParameter());IOUtils.write(invoke.getBytes(StandardCharsets.UTF_8),response.getOutputStream());} catch (IOException e) {e.printStackTrace();}catch (ClassNotFoundException e){e.printStackTrace();} catch (NoSuchMethodException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (InstantiationException e) {e.printStackTrace();}} } 相关的gitub仓库地址(https://github.com/zhaoyiwen-wuxian/RpcTrench.git) master分支进行切换分支到master
http://www.pierceye.com/news/613466/

相关文章:

  • 上海做网站搜索一下马来西亚的网站建设的竞争对手的分析
  • 建站优化易下拉系统163邮箱登录注册
  • c 做网站电子商务平台中搜索词拆解包括
  • 腾讯云10g数字盘做网站够么四川省建设人才网
  • 批量 网站标题中海园林建设有限公司网站
  • 鲜花网站数据库建设免费律师咨询
  • 团队网站建设哪家便宜制作公司网站流程
  • 青龙桥网站建设企业网页是什么
  • 上海网站建设备案号怎么恢复法律咨询网站开发
  • 烟台做网站价格动力网站建设
  • 北戴河网站建设墨刀制作网页教程
  • 成都网站设计开发做得好微信商城怎么开发
  • 江西省城乡建设培训网-官方网站上海建设集团有限公司
  • 凡科网站设计模板grimhelm wordpress
  • 自己做的网站不备案行吗建筑工程集团有限公司
  • 网站初期 权重怎么做彩票类网站开发
  • 南通网站定制公司服务器网站建设维护合同
  • 亳州做商标网站的公司免费的网站模板
  • 西南城乡建设部网站首页python3做网站教程
  • 网站首页设计欣赏个人电影网站建设
  • 导航网站建设怎么给网站图片加alt
  • 备案成功后怎么建设网站宠物喂养网页设计模板以及代码
  • 东莞哪家网站建设比较好wordpress更改语言设置
  • 如何找做网站的客户wordpress适合视频网站吗
  • 网站建设的业务流程图拔萝卜视频播放在线观看免费
  • 建个网站要多少钱高安网站制作
  • dw设计模板百度ocpc如何优化
  • 苏宁网站优化与推广html教程网站
  • 怎么做网站网页免费高清屏幕录像
  • 网络推广哪个网站好亚马逊网站开发使用的什么方式