netty 网关 http请求 请求转发
https://netty.io/4.1/xref/io/netty/example/proxy/package-summary.html
https://netty.io/4.1/xref/io/netty/example/proxy/HexDumpProxy.html
package com.test; import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; public class HexDumpProxyInitializer extends ChannelInitializer<SocketChannel> {
private final String remoteHost;
private final int remotePort; public HexDumpProxyInitializer(String remoteHost, int remotePort) {
this.remoteHost = remoteHost;
this.remotePort = remotePort;
} @Override
public void initChannel(SocketChannel ch) {
// 获取当前类名;
System.out.println(this.getClass());
ch.pipeline().addLast(
new LoggingHandler(LogLevel.INFO),
new HexDumpProxyInitializer(remoteHost, remotePort)
);
}
}
package com.test; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; public class HexDumpProxy {
static final int LOCAL_PORT = Integer.parseInt(System.getProperty("localPort", "8443"));
static final String REMOTE_HOST = System.getProperty("remoteHost", "11.21.1.2");
static final int REMOTE_PORT = Integer.parseInt(System.getProperty("remotePort", "50000")); public static void main(String[] args) throws Exception {
System.err.println("Proxying *:" + LOCAL_PORT + " to " + REMOTE_HOST + ":" + REMOTE_PORT + "...");
// Configure the bootstrap
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new HexDumpProxyInitializer(REMOTE_HOST, REMOTE_PORT))
.childOption(ChannelOption.AUTO_READ, false)
.bind(LOCAL_PORT).sync().channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
}
netty 网关 http请求 请求转发的更多相关文章
- selector.select(500); EventLoop及事件循环机制 netty 在半透明做代理网关下 对请求的批处理
Netty框架学习之路(五)—— EventLoop及事件循环机制 - 懋懋之为 - CSDN博客 https://blog.csdn.net/tjreal/article/details/79751 ...
- jsp:和属性相关的方法,请求的转发,重定向
jsp中与属性相关的方法: 方法: void setAttribute(String name, Object o): 设置属性 Object getAttribute(String name):获取 ...
- 技巧集:nginx作代理时,查看请求被转发到哪台服务器
使用Nginx代理多台服务器实行负载的时候,如何查看某一个请求被转发到哪台服务器上呢? upstream demo { server 127.0.0.1:8781; server 127.0.0.1: ...
- javaWEB总结(14):请求的转发和重定向
通俗理解请求转发与重定向的流程 通俗的来讲:我们可以把请求转发和重定向当成是一种借钱的情景模式. (1)请求的转发:A向B借钱,B自己没有钱,但是向C借到了钱,并且把钱借给了A.A只向B请求了一次. ...
- javaweb之请求的转发和重定向
1.什么是请求转发和请求重定向? 请求转发: xxServlet收到请求,然后直接转发给yyServlet,然后yyServlet返回给客户端.整个过程中,客户端发出一个请求,收到一个响应. 重定向: ...
- 域对象的作用范围 & 请求的转发和重定向
1. 和属性相关的方法: ①. 方法 void setAttribute(String name, Object o): 设置属性 Object getAttribute(String name): ...
- 基于Servlet体系的HTTP请求代理转发Spring Boot组件
背景概述 两个项目组原本都是各自负责两个产品线(产品A.产品B),由于公司业务的发展,目前需要将两个产品合并成一个大产品(功能整合,部分做取舍,最终产出产品C),前后端代码必然也需要整合,包括两个产品 ...
- AJAX - 向服务器发送请求请求
AJAX - 向服务器发送请求请求 XMLHttpRequest 对象用于和服务器交换数据.直线电机生产厂家 向服务器发送请求 如需将请求发送到服务器,我们使用 XMLHttpRequest 对象的 ...
- Bumblebee服务网关之统一请求验证
对于微服务网关来说,统一请求验证是一个比较重要和常用的功能,通过网关验证后台服务就无须关注请求验证:对于多语言平台的服务而言制定验证方式和变更验证配置都是一件比较繁琐和工作量大的事情.Bumblebe ...
随机推荐
- swift 单例模式
class ca{ ; static var instance:ca = ca(); class func GetInstance()->ca{ return instance; } } var ...
- OGNL表达式的基本语法和用法
首先我们一起来看一下OGNL中的#.%和$符号. 关于OGNL各种用法总结参看:http://blog.163.com/seara520@126/blog/static/720693042010320 ...
- pip install read time-out
Problem ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. 1 S ...
- poj2082单调栈
本来实在做后缀数组的题目的,不巧,碰到了pku3415这题,需要用到单调栈来维护,但是之前又没有学习过单调栈这方面的知识,于是水了几题....... 题意:给你一些连续的小矩形,高宽不定,求最大的矩形 ...
- rsync详解之exclude排除文件
rsync详解之exclude排除文件 问题:如何避开同步指定的文件夹? --excludersync --exclude files and folders http://articles.sl ...
- Hadoop环境搭载
官网安装教程:[http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.13.0/hadoop-project-dist/hadoop-com ...
- Cookie js 操作
从事web开发也有些日子了,cookie 是个啥差不多能说明白,可是实际自己一上手操作就是得去搜索(你们懂的),结果被鄙视了...所以就写一篇博文做为自己的学习笔记,嘿嘿,博客的好处在此体现出来了. ...
- Entity Framework(五):使用配置伙伴创建数据库
在上一篇文章中讲了如何使用fluent API来创建数据表,不知道你有没有注意到一个问题.上面的OnModelCreating方法中,我们只配置了一个类Product,也许代码不是很多,但也不算很少, ...
- java中不用BigInteger实现超大整数的乘法操作
昨天看到一个题目:计算1234!,不能用BigInteger类 众所周知阶乘的数据会非常大,经常使用的int和long型根本不够用.一般想到的仅仅有BigInteger类,可是题目中明白说了不能用,所 ...
- git chekout分支遇到问题:need merge
解决步骤: 在master上, 1.git add . 2.git commit 3.新建分支,并且checkout到此分支,重新提交