Java调用Http/Https接口(5)--HttpAsyncClient调用Http/Https接口
HttpAsyncClient是HttpClient的异步版本,提供异步调用的api。文中所使用到的软件版本:Java 1.8.0_191、HttpClient 4.1.4。
1、服务端
2、调用Http接口
2.1、GET请求
- public static void get() {
- String requestPath = "http://localhost:8080/demo/httptest/getUser?userId=1000&userName=李白";
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- HttpGet get = new HttpGet(requestPath);
- Future<HttpResponse> future = httpClient.execute(get, null);
- HttpResponse response = future.get();
- System.out.println("GET返回状态:" + response.getStatusLine());
- HttpEntity responseEntity = response.getEntity();
- System.out.println("GET返回结果:" + EntityUtils.toString(responseEntity));
- //回调方式调用
- final CountDownLatch latch = new CountDownLatch(1);
- final HttpGet get2 = new HttpGet(requestPath);
- httpClient.execute(get2, new FutureCallback<HttpResponse>() {
- public void completed(final HttpResponse response) {
- latch.countDown();
- System.out.println("GET(回调方式)返回状态:" + response.getStatusLine());
- try {
- System.out.println("GET(回调方式)返回结果:" + EntityUtils.toString(response.getEntity()));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void failed(final Exception e) {
- latch.countDown();
- e.printStackTrace();
- }
- public void cancelled() {
- latch.countDown();
- System.out.println("cancelled");
- }
- });
- latch.await();
- //流方式调用
- final CountDownLatch latch2 = new CountDownLatch(1);
- final HttpGet get3 = new HttpGet(requestPath);
- HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(get3);
- AsyncCharConsumer<HttpResponse> consumer3 = new AsyncCharConsumer<HttpResponse>() {
- HttpResponse response;
- @Override
- protected void onResponseReceived(final HttpResponse response) {
- this.response = response;
- }
- @Override
- protected void releaseResources() {
- }
- @Override
- protected HttpResponse buildResult(final HttpContext context) {
- return this.response;
- }
- @Override
- protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
- System.out.println("GET(流方式)返回结果:" + buf.toString());
- }
- };
- httpClient.execute(producer3, consumer3, new FutureCallback<HttpResponse>() {
- public void completed(final HttpResponse response) {
- latch2.countDown();
- System.out.println("GET(流方式)返回状态:" + response.getStatusLine());
- }
- public void failed(final Exception e) {
- latch2.countDown();
- e.printStackTrace();
- }
- public void cancelled() {
- latch2.countDown();
- System.out.println("cancelled");
- }
- });
- latch2.await();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
2.2、POST请求(发送键值对数据)
- public static void post() {
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- String requestPath = "http://localhost:8080/demo/httptest/getUser";
- HttpPost post = new HttpPost(requestPath);
- List<NameValuePair> list = new ArrayList<NameValuePair>();
- list.add(new BasicNameValuePair("userId", "1000"));
- list.add(new BasicNameValuePair("userName", "李白"));
- post.setEntity(new UrlEncodedFormEntity(list, "utf-8"));
- Future<HttpResponse> future = httpClient.execute(post, null);
- HttpResponse response = future.get();
- System.out.println("POST返回状态:" + response.getStatusLine());
- HttpEntity responseEntity = response.getEntity();
- System.out.println("POST返回结果:" + EntityUtils.toString(responseEntity));
- //回调方式和流方式调用类似
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
2.3、POST请求(发送JSON数据)
- public static void post2() {
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- String requestPath = "http://localhost:8080/demo/httptest/addUser";
- HttpPost post = new HttpPost(requestPath);
- post.setHeader("Content-type", "application/json");
- String param = "{\"userId\": \"1001\",\"userName\":\"杜甫\"}";
- post.setEntity(new StringEntity(param, "utf-8"));
- Future<HttpResponse> future = httpClient.execute(post, null);
- HttpResponse response = future.get();
- System.out.println("POST json返回状态:" + response.getStatusLine());
- HttpEntity responseEntity = response.getEntity();
- System.out.println("POST josn返回结果:" + EntityUtils.toString(responseEntity));
- //回调方式和流方式调用类似
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
2.4、上传文件
- public static void upload() {
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- String requestPath = "http://localhost:8080/demo/httptest/upload";
- ZeroCopyPost producer = new ZeroCopyPost(requestPath, new File("d:/a.jpg"), ContentType.create("text/plain"));
- AsyncCharConsumer<HttpResponse> consumer = new AsyncCharConsumer<HttpResponse>() {
- HttpResponse response;
- @Override
- protected void onResponseReceived(final HttpResponse response) {
- this.response = response;
- }
- @Override
- protected void releaseResources() {
- }
- @Override
- protected HttpResponse buildResult(final HttpContext context) {
- return this.response;
- }
- @Override
- protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
- System.out.println("upload返回结果:" + buf.toString());
- }
- };
- Future<HttpResponse> future = httpClient.execute(producer, consumer, null);
- HttpResponse response = future.get();
- System.out.println("upload返回状态:" + response.getStatusLine());
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
2.5、下载文件
- public static void download() {
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- String requestPath = "http://localhost:8080/demo/httptest/download";
- HttpGet get = new HttpGet(requestPath);
- HttpAsyncRequestProducer producer = HttpAsyncMethods.create(get);
- File download = new File("d:/temp/download_" + System.currentTimeMillis() + ".jpg");
- ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
- @Override
- protected File process(final HttpResponse response, final File file, final ContentType contentType) throws Exception {
- if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
- }
- return file;
- }
- };
- Future<File> future = httpClient.execute(producer, consumer, null);
- System.out.println("download文件大小:" + future.get().length());
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
2.6、完整例子
- package com.inspur.demo.http.client;
- import java.io.File;
- import java.io.IOException;
- import java.nio.CharBuffer;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.CountDownLatch;
- import java.util.concurrent.Future;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.HttpStatus;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.concurrent.FutureCallback;
- import org.apache.http.entity.ContentType;
- import org.apache.http.entity.StringEntity;
- import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
- import org.apache.http.impl.nio.client.HttpAsyncClients;
- import org.apache.http.message.BasicNameValuePair;
- import org.apache.http.nio.IOControl;
- import org.apache.http.nio.client.methods.AsyncCharConsumer;
- import org.apache.http.nio.client.methods.HttpAsyncMethods;
- import org.apache.http.nio.client.methods.ZeroCopyConsumer;
- import org.apache.http.nio.client.methods.ZeroCopyPost;
- import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
- import org.apache.http.protocol.HttpContext;
- import org.apache.http.util.EntityUtils;
- /**
- * 通过HttpClient调用Http接口
- */
- public class HttpAsyncClientCase {
- /**
- * GET请求
- */
- public static void get() {
- String requestPath = "http://localhost:8080/demo/httptest/getUser?userId=1000&userName=李白";
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- HttpGet get = new HttpGet(requestPath);
- Future<HttpResponse> future = httpClient.execute(get, null);
- HttpResponse response = future.get();
- System.out.println("GET返回状态:" + response.getStatusLine());
- HttpEntity responseEntity = response.getEntity();
- System.out.println("GET返回结果:" + EntityUtils.toString(responseEntity));
- //回调方式调用
- final CountDownLatch latch = new CountDownLatch(1);
- final HttpGet get2 = new HttpGet(requestPath);
- httpClient.execute(get2, new FutureCallback<HttpResponse>() {
- public void completed(final HttpResponse response) {
- latch.countDown();
- System.out.println("GET(回调方式)返回状态:" + response.getStatusLine());
- try {
- System.out.println("GET(回调方式)返回结果:" + EntityUtils.toString(response.getEntity()));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void failed(final Exception e) {
- latch.countDown();
- e.printStackTrace();
- }
- public void cancelled() {
- latch.countDown();
- System.out.println("cancelled");
- }
- });
- latch.await();
- //流方式调用
- final CountDownLatch latch2 = new CountDownLatch(1);
- final HttpGet get3 = new HttpGet(requestPath);
- HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(get3);
- AsyncCharConsumer<HttpResponse> consumer3 = new AsyncCharConsumer<HttpResponse>() {
- HttpResponse response;
- @Override
- protected void onResponseReceived(final HttpResponse response) {
- this.response = response;
- }
- @Override
- protected void releaseResources() {
- }
- @Override
- protected HttpResponse buildResult(final HttpContext context) {
- return this.response;
- }
- @Override
- protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
- System.out.println("GET(流方式)返回结果:" + buf.toString());
- }
- };
- httpClient.execute(producer3, consumer3, new FutureCallback<HttpResponse>() {
- public void completed(final HttpResponse response) {
- latch2.countDown();
- System.out.println("GET(流方式)返回状态:" + response.getStatusLine());
- }
- public void failed(final Exception e) {
- latch2.countDown();
- e.printStackTrace();
- }
- public void cancelled() {
- latch2.countDown();
- System.out.println("cancelled");
- }
- });
- latch2.await();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
- /**
- * POST请求(发送键值对数据)
- */
- public static void post() {
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- String requestPath = "http://localhost:8080/demo/httptest/getUser";
- HttpPost post = new HttpPost(requestPath);
- List<NameValuePair> list = new ArrayList<NameValuePair>();
- list.add(new BasicNameValuePair("userId", "1000"));
- list.add(new BasicNameValuePair("userName", "李白"));
- post.setEntity(new UrlEncodedFormEntity(list, "utf-8"));
- Future<HttpResponse> future = httpClient.execute(post, null);
- HttpResponse response = future.get();
- System.out.println("POST返回状态:" + response.getStatusLine());
- HttpEntity responseEntity = response.getEntity();
- System.out.println("POST返回结果:" + EntityUtils.toString(responseEntity));
- //回调方式和流方式调用类似
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
- /**
- * POST请求(发送json数据)
- */
- public static void post2() {
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- String requestPath = "http://localhost:8080/demo/httptest/addUser";
- HttpPost post = new HttpPost(requestPath);
- post.setHeader("Content-type", "application/json");
- String param = "{\"userId\": \"1001\",\"userName\":\"杜甫\"}";
- post.setEntity(new StringEntity(param, "utf-8"));
- Future<HttpResponse> future = httpClient.execute(post, null);
- HttpResponse response = future.get();
- System.out.println("POST json返回状态:" + response.getStatusLine());
- HttpEntity responseEntity = response.getEntity();
- System.out.println("POST josn返回结果:" + EntityUtils.toString(responseEntity));
- //回调方式和流方式调用类似
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
- /**
- * 上传文件
- */
- public static void upload() {
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- String requestPath = "http://localhost:8080/demo/httptest/upload";
- ZeroCopyPost producer = new ZeroCopyPost(requestPath, new File("d:/a.jpg"), ContentType.create("text/plain"));
- AsyncCharConsumer<HttpResponse> consumer = new AsyncCharConsumer<HttpResponse>() {
- HttpResponse response;
- @Override
- protected void onResponseReceived(final HttpResponse response) {
- this.response = response;
- }
- @Override
- protected void releaseResources() {
- }
- @Override
- protected HttpResponse buildResult(final HttpContext context) {
- return this.response;
- }
- @Override
- protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
- System.out.println("upload返回结果:" + buf.toString());
- }
- };
- Future<HttpResponse> future = httpClient.execute(producer, consumer, null);
- HttpResponse response = future.get();
- System.out.println("upload返回状态:" + response.getStatusLine());
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
- /**
- * 下载文件
- */
- public static void download() {
- CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
- try {
- httpClient.start();
- String requestPath = "http://localhost:8080/demo/httptest/download";
- HttpGet get = new HttpGet(requestPath);
- HttpAsyncRequestProducer producer = HttpAsyncMethods.create(get);
- File download = new File("d:/temp/download_" + System.currentTimeMillis() + ".jpg");
- ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
- @Override
- protected File process(final HttpResponse response, final File file, final ContentType contentType) throws Exception {
- if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
- }
- return file;
- }
- };
- Future<File> future = httpClient.execute(producer, consumer, null);
- System.out.println("download文件大小:" + future.get().length());
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpClient);
- }
- }
- private static void close(CloseableHttpAsyncClient httpClient) {
- try {
- if (httpClient != null) {
- httpClient.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- get();
- post();
- post2();
- upload();
- download();
- }
- }
3、调用Https接口
与调用Http接口不一样的部分主要在设置ssl部分,其ssl的设置与HttpsURLConnection很相似(参见Java调用Http/Https接口(2)--HttpURLConnection/HttpsURLConnection调用Http/Https接口);下面用GET请求来演示ssl的设置,其他调用方式类似。
- package com.inspur.demo.http.client;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.security.KeyStore;
- import java.util.concurrent.Future;
- import javax.net.ssl.HostnameVerifier;
- import javax.net.ssl.SSLContext;
- import javax.net.ssl.SSLSession;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
- import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
- import org.apache.http.impl.nio.client.HttpAsyncClients;
- import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
- import org.apache.http.ssl.SSLContextBuilder;
- import org.apache.http.ssl.SSLContexts;
- import org.apache.http.util.EntityUtils;
- import com.inspur.demo.common.util.FileUtil;
- /**
- * 通过HttpAsyncClient调用Https接口
- */
- public class HttpAsyncClientHttpsCase {
- public static void main(String[] args) {
- CloseableHttpAsyncClient httpAsyncClient = null;
- CloseableHttpAsyncClient httpAsyncClient2 = null;
- CloseableHttpAsyncClient httpAsyncClient3 = null;
- try {
- /*
- * 请求有权威证书的地址
- */
- String requestPath = "https://www.12306.cn/index/";
- httpAsyncClient = HttpAsyncClients.createDefault();
- httpAsyncClient.start();
- HttpGet get = new HttpGet(requestPath);
- Future<HttpResponse> future = httpAsyncClient.execute(get, null);
- HttpResponse response = future.get();
- System.out.println(response.getStatusLine());
- System.out.println("GET1返回结果:" + EntityUtils.toString(response.getEntity(), "utf-8"));
- /*
- * 请求自定义证书的地址
- */
- //获取信任证书库
- KeyStore trustStore = getkeyStore("jks", "d:/temp/cacerts", "123456");
- //不需要客户端证书
- requestPath = "https://10.40.x.x:9010/zsywservice";
- httpAsyncClient2 = HttpAsyncClients.custom().setSSLStrategy(getSSLIOSessionStrategy(trustStore)).build();
- httpAsyncClient2.start();
- get = new HttpGet(requestPath);
- future = httpAsyncClient2.execute(get, null);
- response = future.get();
- System.out.println("GET2:" + EntityUtils.toString(response.getEntity()));
- //需要客户端证书
- requestPath = "https://10.40.x.x:9016/zsywservice";
- KeyStore keyStore = getkeyStore("pkcs12", "d:/client.p12", "123456");
- httpAsyncClient3 = HttpAsyncClients.custom().setSSLStrategy(getSSLIOSessionStrategy(keyStore, "123456", trustStore)).build();
- httpAsyncClient3.start();
- get = new HttpGet(requestPath);
- future = httpAsyncClient3.execute(get, null);
- response = future.get();
- System.out.println("GET3返回结果:" + EntityUtils.toString(response.getEntity()));
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(httpAsyncClient);
- close(httpAsyncClient2);
- close(httpAsyncClient3);
- }
- }
- public static SSLIOSessionStrategy getSSLIOSessionStrategy(KeyStore keyStore, String keyPassword, KeyStore trustStore) throws Exception {
- SSLContextBuilder bulider = SSLContexts.custom();
- if (keyStore != null) {
- bulider.loadKeyMaterial(keyStore, keyPassword.toCharArray());
- }
- if (keyStore != null) {
- bulider.loadTrustMaterial(trustStore, null);
- } else {
- bulider.loadTrustMaterial(new TrustSelfSignedStrategy());
- }
- SSLContext sslContext = bulider.build();
- // 验证URL的主机名和服务器的标识主机名是否匹配
- HostnameVerifier hostnameVerifier = new HostnameVerifier() {
- @Override
- public boolean verify(String hostname, SSLSession session) {
- // if ("xxx".equals(hostname)) {
- // return true;
- // } else {
- // return false;
- // }
- return true;
- }
- };
- SSLIOSessionStrategy strategy = new SSLIOSessionStrategy(sslContext, new String[] { "TLSv1", "TLSv1.2" }, null,
- hostnameVerifier);
- return strategy;
- }
- public static SSLIOSessionStrategy getSSLIOSessionStrategy(KeyStore trustStore) throws Exception {
- return getSSLIOSessionStrategy(null, null, trustStore);
- }
- private static KeyStore getkeyStore(String type, String filePath, String password) {
- KeyStore keySotre = null;
- FileInputStream in = null;
- try {
- keySotre = KeyStore.getInstance(type);
- in = new FileInputStream(new File(filePath));
- keySotre.load(in, password.toCharArray());
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- FileUtil.close(in);
- }
- return keySotre;
- }
- private static void close(CloseableHttpAsyncClient httpClient) {
- try {
- if (httpClient != null) {
- httpClient.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Java调用Http/Https接口(5)--HttpAsyncClient调用Http/Https接口的更多相关文章
- Java WebService接口生成和调用 图文详解>【转】【待调整】
webservice简介: Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间 ...
- c#代码 天气接口 一分钟搞懂你的博客为什么没人看 看完python这段爬虫代码,java流泪了c#沉默了 图片二进制转换与存入数据库相关 C#7.0--引用返回值和引用局部变量 JS直接调用C#后台方法(ajax调用) Linq To Json SqlServer 递归查询
天气预报的程序.程序并不难. 看到这个需求第一个想法就是只要找到合适天气预报接口一切都是小意思,说干就干,立马跟学生沟通价格. 不过谈报价的过程中,差点没让我一口老血喷键盘上,话说我们程序猿的人 ...
- java接口对接——别人调用我们接口获取数据
java接口对接——别人调用我们接口获取数据,我们需要在我们系统中开发几个接口,给对方接口规范文档,包括访问我们的接口地址,以及入参名称和格式,还有我们的返回的状态的情况, 接口代码: package ...
- .net WebServer示例及调用(接口WSDL动态调用 JAVA)
新建.asmx页面 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- 使用Socket&反射&Java流操作进行方法的远程调用(模拟RPC远程调用)
写在前面 阅读本文首先得具备基本的Socket.反射.Java流操作的基本API使用知识:否则本文你可能看不懂... 服务端的端口监听 进行远程调用,那就必须得有客户端和服务端.服务端负责提供服务,客 ...
- java多态的实现原理(JVM调用过程)(综合多篇文章,参考见文末)
一个对象变量可以指示多种实际类型的现象称为多态 允许不同类的对象对同一消息做出响应.方法的重载.类的覆盖正体现了多态. 1.多态的机制 1.1 本质上多态分两种 1.编译时多态(又称静态多态) 2.运 ...
- 从Java future 到 Guava ListenableFuture实现异步调用
从Java future 到 Guava ListenableFuture实现异步调用 置顶 2016年04月24日 09:11:14 皮斯特劳沃 阅读数:17570 标签: java异步调用线程非阻 ...
- Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结
Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结 1.1. 边缘检测的基本方法Canny最常用了1 1.2. 编写matlab边缘检测代码, ...
- 【Java EE 学习 80 下】【调用WebService服务的四种方式】【WebService中的注解】
不考虑第三方框架,如果只使用JDK提供的API,那么可以使用三种方式调用WebService服务:另外还可以使用Ajax调用WebService服务. 预备工作:开启WebService服务,使用jd ...
随机推荐
- Oracle 日期各个部分常用写法
--1.日期的各部分的常用的的写法 --- --1) 取时间点的年份的写法: SELECT TO_CHAR(SYSDATE,'YYYY') FROM DUAL; --结果:2019 --2) 取时间点 ...
- mvn命令修改pom打包的版本号
在java项目中打包经常需要修改镜像的版本号.可以使用如下命令 mvn versions: // 如果要打包使用人如下命令,打印详细信息使用 -X mvn clean deploy -e -Dskip ...
- python开发笔记-str转字典
后台接收到post请求数据格式为json格式的字符串,不能直接用字典的get方法 909090909090909090909090909090909 Internal Server Error: /g ...
- kafka window环境下使用(内置zookeeper)
下载 kafka 官网下载最新版本(已集成 zookeeper) 解压到 D 盘的 kafka_2.12-2.3.0 运行 zookeeper 执行 zookeeper 运行命令 D:\kafka_2 ...
- linux 结束某个进程,并且结束子进程
pid=49184 childid=`ps -ef|grep $pid|grep -v grep|awk '{printf " %s",$2 }'` kill -9 $childi ...
- JS调用onBackPressed
需求: 安卓页面webview加载H5页面,H5页面能能返回到安卓页面 import android.os.Bundle; import android.support.v7.app.AppCompa ...
- Django的分页器 paginator
导入 from django.core.paginator import Paginator,EmptyPage,PageNotAnInteger Page对象 Paginator.page()将返回 ...
- Flask自动刷新前端页面(方便调试)livereload
是不是每次调整模板文件,就要停止flask服务器,重启flask服务器,再去浏览器刷新页面? 有没有办法自动完成这3步呢? 安装livereload即可, 仅仅把app.run() 改为下面的例子就可 ...
- 【Maven学习】定制库到Maven本地资源库
目标:手工操作将一个jar安装到本地仓库 第一步:首先获取到jar包,可以是第三方的 也可以是自己创建的,放到本地任意目录 比如:joda-time-2.10.3,放到C:\jar\ 目录下面 第二 ...
- Vue父子组件相互传值及调用方法的方案
Vue父子组件相互传值及调用方法的方案 一.调用方法: 1.父组件调用子组件方法: 2.子组件调用父组件方法: 参考:https://www.cnblogs.com/jin-zhe/p/9523782 ...