zoukankan      html  css  js  c++  java
  • 消息队列理解笔记

    消息队列解决的是将突发大量请求转换为后端能承受的队列请求,比如你的服务器一秒能处理100个订单,但秒杀活动1秒进来1000个订单,持续10秒,在后端能力无法增加的情况下,你可以用消息队列将总共10000个请求压在队列里,后台consumer按原有能力处理,100秒后处理完所有请求(而不是直接宕机丢失订单数据)

    所谓队列,就是按照队首先出的规则建立的数据结构,消息队列就是根据消息到来后按照一定的规则进行排序,但一定是队首的消息先得到应答的队列。
    比如:

    public static String do_post(String url, List<NameValuePair> name_value_pair) throws IOException {
    String body = "{}";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
    HttpPost httpost = new HttpPost(url);
    httpost.setEntity(new UrlEncodedFormEntity(name_value_pair, StandardCharsets.UTF_8));
    HttpResponse response = httpclient.execute(httpost);
    HttpEntity entity = response.getEntity();
    body = EntityUtils.toString(entity);
    } finally {
    httpclient.getConnectionManager().shutdown();
    }
    return body;
    }
    public static String do_get(String url) throws ClientProtocolException, IOException {
    String body = "{}";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
    HttpGet httpget = new HttpGet(url);
    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();
    body = EntityUtils.toString(entity);
    } finally {
    httpclient.getConnectionManager().shutdown();
    }
    return body;
    }

  • 相关阅读:
    P4343 [SHOI2015]自动刷题机
    P1083 [NOIP2012 提高组] 借教室
    [AGC记录] AGC003题解
    [做题记录-乱做] [AGC003E] Sequential operations on Sequence
    [AGC记录] AGC002题解
    [AGC记录] AGC001题解
    [做题记录-乱做] [AGC001F] Wide Swap
    [做题记录-计数] [ARC087D] Squirrel Migration
    [做题记录-计数] [九省联考2018]秘密袭击coat
    [做题记录-计数][AGC024E] Sequence Growing Hard
  • 原文地址:https://www.cnblogs.com/huangwentian/p/6896990.html
Copyright © 2011-2022 走看看