kafka actual combat and kafka authoritative guide, [Spring Boot 8]

Posted by chads2k2 on Wed, 29 Dec 2021 11:34:10 +0100

        </exclusion>

    </exclusions>

</dependency>



<!--HTTPClient-->

<dependency>

    <groupId>com.squareup.okhttp3</groupId>

    <artifactId>okhttp</artifactId>

    <version>4.3.1</version>

</dependency>

<dependency>

    <groupId>com.squareup.okhttp3</groupId>

    <artifactId>mockwebserver</artifactId>

    <version>4.3.1</version>

</dependency>

<!--JSON-->

<dependency>

    <groupId>com.alibaba</groupId>

    <artifactId>fastjson</artifactId>

    <version>1.2.58</version>

</dependency>


 5, Code example

=======



![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9vc2NpbWcub3NjaGluYS5uZXQvb3NjbmV0L3VwLWQ0MGQ1ZjAzMzUxODdiOGM5Njg4M2I0NjEwMDM1NjA3ZWZiLnBuZw?x-oss-process=image/format,png)



1,application.properties

------------------------



server.port=8080

github.client.id=27dda83xxxxxx36043d4

github.client.secret=01f948axxxxxxef10d9132cfe6083dxxxxxx5f3503

github.redirect.uri=http://localhost:8080/callback



2,GitHubProvider.java

---------------------



package life.majiang.community.provider;

import life.majiang.community.dto.AccessTokenDTO;

import life.majiang.community.dto.GitHubUser;

import com.alibaba.fastjson.JSON;

import okhttp3.*;

import org.springframework.stereotype.Component;

import java.io.IOException;

@Component

public class GitHubProvider {

private static final MediaType MediaType_JSON

        = MediaType.get("application/json; charset=utf-8");

public String getAccessToken(AccessTokenDTO accessTokenDTO){



    OkHttpClient client = new OkHttpClient();

    RequestBody body = RequestBody.create(JSON.toJSONString(accessTokenDTO), MediaType_JSON);

    Request request = new Request.Builder()

            .url("https://github.com/login/oauth/access_token")

            .post(body)

            .build();

    try (Response response = client.newCall(request).execute()) {

        String resstring = response.body().string();

        String token =resstring.split("&")[0]

                .split("=")[1];

        return token;

    }catch (IOException e) {

        e.printStackTrace();

    }

    return null;

}

public GitHubUser getUser(String AccessToken){

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder()

            .url("https://api.github.com/user?access_token="+AccessToken)

            .build();

    try{

        Response response = client.newCall(request).execute();

        String res = response.body().string();

        GitHubUser gitHubUser = JSON.parseObject(res, GitHubUser.class);

        return gitHubUser;

    } catch (IOException e) {

        e.printStackTrace();

    }

    return null;

}

}



3,AuthorizeController.java 

---------------------------



package life.majiang.community.controller;

import life.majiang.community.dto.AccessTokenDTO;

import life.majiang.community.dto.GitHubUser;

import life.majiang.community.provider.GitHubProvider;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**

*/

@Controller

public class AuthorizeController {

@Autowired

private GitHubProvider gitHubProvider;

@Value("${github.client.id}")

private String clientId;

@Value("${github.client.secret}")

private String clientSecret;

@Value("${github.redirect.uri}")

private String redirectURI;



@GetMapping("/callback")

public String callBack(@RequestParam(name = "code")String code,

                       @RequestParam(name = "state") String state,

                       HttpServletRequest request){

    AccessTokenDTO accessTokenDTO = new AccessTokenDTO();

    accessTokenDTO.setClient_id(clientId);

    accessTokenDTO.setClient_secret(clientSecret);

    accessTokenDTO.setCode(code);

How to quickly update your technology accumulation?

  • In the existing projects, deep excavation technology, such as using netty, can make the relevant underlying code and key points appear.
  • If you don't know the current direction, it depends on what your leaders or skilled people in the company are learning.
  • After knowing the direction of effort, I don't know how to learn, so I look for relevant materials everywhere and practice.
  • If you don't know whether you have achieved anything after study, you can test it through the interview.

Personally, I think the interview is also like a new journey. Failure and victory are common things. Therefore, I advise you not to lose heart and morale because of the failure of the interview. Don't be complacent because you passed the interview. What's waiting for you will be a better future. Keep going!

The answers to the above interview topics have been compiled into interview documents. There are detailed answers in the documents, as well as some other interview questions of large factories. Friends in need Click here to get it for free

Personally, I think the interview is also like a new journey. Failure and victory are common things. Therefore, I advise you not to lose heart and morale because of the failure of the interview. Don't be complacent because you passed the interview. What's waiting for you will be a better future. Keep going!

The answers to the above interview topics have been compiled into interview documents. There are detailed answers in the documents, as well as some other interview questions of large factories. Friends in need Click here to get it for free

[external chain picture transferring... (img-2ZwNrDZT-1628297755283)]

[external chain picture transferring... (img-76yczqyJ-1628297755285)]

Topics: Java Back-end Interview Programmer