Sanmen Meituan finally got the offer and shared the interview questions: Spring+Dubbo+Redis+microservices...

Foreword:

The first-tier manufacturers have always been the dream companies of Internet people, including programmers, who suffer from the high barriers to entry of BAT manufacturers, and they can only look at the door and sigh, so they can only have the opportunity to knock on the door of BAT by practicing their skills. The following is the personal experience of a Java programmer who won the offer from Sanmenmei Group and presents the real interview questions for reference and learning.

image.png

Part 1. Spring topic

1. How does Spring define the scope of a class

It is defined by the scope attribute in the bean definition.

2. The scope of several beans supported by Spring

The scope of the following five types of beans is supported:

  • singleton: The bean has only one instance in each Spring ioc container. (Default default)
  • Prototype: A bean definition can have multiple instances.
  • request: Each http request will create a bean, and the scope is only valid in the context of a web-based Spring ApplicationContext.
  • Session: In an HTTP Session, a bean definition corresponds to an instance. This scope is only valid in the context of a web-based Spring ApplicationContext.
  • global-session: In a global HTTP Session, a bean definition corresponds to an instance. This scope is only valid in the context of a web-based Spring ApplicationContext.

3. Types of transaction management supported by Spring

  • Programmatic transaction management: This means that you manage transactions programmatically, which brings you great flexibility, but it is difficult to maintain.
  • Declarative transaction management: This means that you can separate business code and transaction management, and you only need to use annotations and XML configuration to manage transactions.

4. What is inversion of control (IOC)? What is dependency injection?

  • Inversion of Control (IOC): Traditional applications are actively controlled by ourselves in the object to directly obtain dependent objects. Now the container helps us find and inject dependent objects. Objects only passively accept dependent objects, so it is an inversion of control.
  • Dependency injection: The dependency between components is determined by the container at runtime. To put it more vividly, the container dynamically injects a certain dependency into the component. Through the dependency injection mechanism, we only need to specify the resources required by the target through simple configuration without any code, and complete our own business logic, without caring about where the specific resources come from and by whom.
  • Implementation methods: Constructor injection, Setter method injection, and interface injection. Annotation assembly is not enabled by default. In order to use annotation assembly, we must configure the context:annotation-config/ element in the Spring configuration file.

5. How many core components does Spring consist of?

  • Bean component
  • Context component
  • Core component

6. The core workflow of Spring MVC?

  • The user sends a request request to the server, and the request is captured by the SpringMVC central controller DispatcherServlet;
  • DispatcherServlet parses the request URL to obtain the requested resource identifier (URI). Then, according to the URI, call the HandlerMapping mapping processor to send the request to the specified Controller.
  • After the Controller executes, it encapsulates the returned data information into the ModelAndView object, and finally selects a suitable View rendering view to return to the interface through the ViewResolver view resolver.

7. Spring transaction isolation level (it is best to say all five interviews)

  • DEFAULT This is the default isolation level of a PlatfromTransactionManager, using the database default transaction isolation level.
  • Read uncommited: Dirty reads, non-repeatable reads, and virtual reads may occur. Is the lowest transaction isolation level, which allows another transaction to see the uncommitted data of this transaction.
  • Read commited: Avoid dirty reads. However, non-repeatable reading and virtual reading may occur. Ensure that a transaction can only be read by another transaction after it is submitted. Another transaction cannot read the uncommitted data of the transaction. Oracle default
  • Repeatable read: This transaction isolation level can prevent dirty reads and non-repeatable reads. However, phantom reading may occur. In addition to ensuring that one transaction cannot be read by another transaction, it also avoids the following situations (non-repeatable read). Mysql default
  • Serializable: This is the most expensive, inefficient, but most reliable transaction isolation level. Transactions are processed as sequential execution. In addition to preventing dirty reads and non-repeatable reads, phantom reads are also avoided (avoid three types).

8. Spring transaction features (it is best to say all four interviews)

  • Atomicity (atomicity): All operations on the database in a transaction are an indivisible sequence of operations, either all or nothing.
  • Consistency: The integrity of the data before and after the execution of the transaction remains consistent.
  • Isolation (isolation): During the execution of a transaction, it should not be interfered by other transactions
  • Durability: Once a thing is submitted, its changes to the database are permanent

9. Seven propagation characteristics of Spring transactions (seven interviews say one or two)

  • Propagation.REQUIRED (default) The interview must say this. The caller already has a transaction, it will join the same transaction to run, otherwise, start a transaction automatically
  • Propagation.REQUIRES_NEW. Whenever I start a new business
  • Propagation.SUPPORTS. If the caller has a transaction, it will join the same transaction to run, if there is no transaction, it will run in a non-transactional manner
  • Propagation.NOT_SUPPORTED. If the caller has a transaction, it will be suspended until the callee finishes running, and the transaction resumes.
  • Propagation.MANDATORY. If the caller has a transaction, it will join the same transaction and run, if it does not exist, an exception will be thrown
  • Propagation.NEVER. If the caller has a transaction, an exception is thrown
  • Propagation.NESTED. If the caller has a transaction, run a nested transaction, if the caller does not have a transaction, run in the way of Propagation.REQUIRED, that is, start a new transaction

10. Briefly describe the life cycle of Spring Bean

Instantiate, initialize, use, and destroy.

Keywords: BeanFactoryPostProcessor, BeanPostProcessor, init-method/destroy-method

[Image upload failed...(image-b401f-1611732924344)]

Part Two. Dubbo Interview Topic

1. What are the fault tolerance mechanisms of Dubbo?

Dubbo official website proposes a total of six fault tolerance strategies

  • Failover Cluster mode : automatic switching on failure, when failure occurs, retry other servers. (default)
  • Failfast Cluster : fail fast, only initiate a call, and immediately report an error if it fails. Usually used for non-idempotent write operations, such as adding records.
  • Failsafe Cluster : Fail safe, when an exception occurs, simply ignore it. Usually used for operations such as writing to the audit log.
  • Failback Cluster : Failure automatic recovery, background recording of failed requests, and regular retransmission. Usually used for message notification operations.
  • Forking Cluster : Call multiple servers in parallel, and return as long as one succeeds. It is usually used for read operations with high real-time requirements, but more service resources need to be wasted. The maximum number of parallels can be set by forks=”2”.
  • Broadcast Cluster : Broadcast calls all providers, call them one by one, and report an error if any one reports an error. (Supported from 2.1.0) Usually used to notify all providers to update local resource information such as cache or log.

Summary : In actual applications, it is recommended to use the default Failover Cluster for the query statement fault tolerance strategy, and for additions, deletions and changes, it is recommended to use Failfast Cluster or use the Failover Cluster (retries="0") strategy to prevent duplicate data additions and other problems. It is recommended that the query interface method be used as a separate interface to provide query when designing the interface.

2. What problems have you encountered when using dubbo?

Increase the version number of the service provided and the version number of the consumer service

Specifically, this is not a problem, but a solution to the problem. In our actual work, we will face the shortage of various environmental resources. It is also a very practical problem. At the beginning, we can also provide a service for related Development and testing, but when there are multiple environments, multiple versions and multiple tasks, it does not meet our needs. At this time, we can differentiate by adding versions to the provider. This leaves a lot of physical resources At the same time, when the interface definition is released online in the future, it can be released without stopping, using the version number. The reference will only find the service of the corresponding version, for example:

<pre style="box-sizing: border-box; font-family: inherit; font-size: 16px; margin: 1em 0px; padding: 12px 10px; white-space: pre-wrap; border: 1px solid rgb(232, 232, 232); position: relative; line-height: 1.5; color: rgb(153, 153, 153); background: rgb(244, 245, 246); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><dubbo:serviceinterface="com.xxx.XxxService" ref="xxxService" version="1.0"/>
<dubbo:referenceid="xxxService" interface="com.xxx.XxxService" version="1.0"/>

3. Dubbo reference annotation problem?

@Reference can only be used in the current class corresponding to the SpringBean instance, and cannot be used in the parent class for the time being; if you really want to declare a reference in the parent class, you can configure dubbo:reference through the configuration file, and then use the same reference as SpringBean in the place where you need to reference That's it.

4. What should I do if RpcException: No provider available for remote service is abnormal?

  • Check whether the connected registry is correct
  • Go to the registration center to check whether the corresponding service provider exists
  • Check if the service provider is operating normally

5. The service provider has not registered, but can't see it in the registration center?

First, confirm whether the service provider is connected to the correct registry. Not only check the registry address in the configuration, but also check the actual network connection.

Secondly, look at whether the service provider is very busy, such as a stress test, so that there is no CPU fragment to send a heartbeat to the registry. In this case, the pressure will be reduced and the pressure will be automatically restored.

6. What are the connection methods of Dubbo?

Dubbo's client and server have three connection methods, namely: broadcast, direct connection and use zookeeper registration center.

7. Dubbo broadcast

This method is the connection method used by dubbo's official entry program, but this method has many problems. In enterprise development, broadcasting is not used. taotao-manager server configuration:

<pre style="box-sizing: border-box; font-family: inherit; font-size: 16px; margin: 1em 0px; padding: 12px 10px; white-space: pre-wrap; border: 1px solid rgb(232, 232, 232); position: relative; line-height: 1.5; color: rgb(153, 153, 153); background: rgb(244, 245, 246); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">!-- applicationContext-service.xml 文件中 -->
<!-- 提供方应用信息,用于计算机依赖关系 -->
<dubbo:application name="taotao-manager-service” />
<!-- 使用 multicast 广播暴露服务地址 -->
<dubbo:registry address="multicast://224.5.6.7:1234" />
<!-- 使用 dubbo 协议在 20880 协议暴露服务 -->
<dubboprotocol name="dubbo" port="20880" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.taotao.manager.service.TestService" ref="testServiceImpl" />
</pre>

image.png

Part Three. Redis Topics

1. What is Redis?

Answer: Remote Dictionary Server (Redis) is an open source log-based, Key-Value database written in ANSI C language, supporting the network, memory-based or persistent, and providing APIs in multiple languages.

It is usually called a data structure server because the value can be of string (String), hash (Map), list (list), set (sets) and sorted sets (sorted sets) and other types.

2. What are the characteristics of Redis?

  • Support a variety of data structures, such as string (string), list (doubly linked list), dict (hash table), set (collection), zset (sorted set), hyperloglog (cardinality estimation)
  • Support persistence operation, can carry out AOF and RDB data persistence to disk, so as to perform operations such as data backup or data recovery, which is a better means to prevent data loss.
  • Supports data replication through Replication. Through the master-slave mechanism, data can be replicated synchronously in real time, and multi-level replication and incremental replication are supported. The master-slave mechanism is an important means for Redis to perform HA.
  • Single-process request, all commands are executed serially, and data consistency issues do not need to be considered in the case of concurrent.

3. What are the Redis data types?

answer:

  • String
  • Hash(hash表)
  • List (linked list)
  • Set
  • SortedSet (ordered set zset)

4. What are the configuration and persistence schemes of Redis?

Answer: The following two

  • RDB way
  • AOF method

Part 4. Zookeeper topic

1. What is the framework of Zookeeper

Distributed and open source distributed application coordination service was originally an important component of Hadoop and HBase.

Application scenarios: Zookeeper is very powerful and has many application scenarios. Combined with the use of the Dubbo framework in my actual work, Zookeeper is mainly used as a registry.

Providers and consumers developed based on the Dubbo framework register their own URL with Zookeeper. Consumers can also get and subscribe to the provider's registration URL, so that they can be called in the execution of subsequent programs. If the provider changes, it will also send notifications to subscribed consumers through Zookeeper.

2. What kind of node types does Zookeeper have

  • Persistence: It always exists after creation. Unless there is a delete operation, the failure of the client session that created the node will not affect the node.
  • Persistence order: Same as persistence, that is, when the parent node creates the next level of child nodes, it records the order in which each child node is created, and adds a numeric suffix to the name of each child node.
  • Temporary: The creation of a client session fails (note that the session fails, not the connection is broken), and the node is gone. Cannot create child nodes.
  • Temporary sequence: No need to explain.

3. Is Zookeeper's watch monitoring notification to the node permanent?

It's not.

Official statement: A Watch event is a one-time trigger. When the data set with Watch changes, the server will send the change to the client set with Watch to notify them.

Why is it not permanent? For example, if the server changes frequently and the listening client is in many cases, all clients must be notified of each change, which consumes performance too much.

Generally, the client executes getData("/node A", true). If node A is changed or deleted, the client will get its watch event, but after the node A is changed again, and the client has not set it The watch event is no longer sent to the client.

In practical applications, in many cases, our client does not need to know every change of the server, I only need the latest data.

4. If the Zookeeper cluster has 3 machines, can one cluster still work? How about hanging up two?

Remember one principle: more than half alive can be used.

Does the cluster support dynamically adding machines ?

In fact, it is horizontal expansion, Zookeeper is not very good in this respect. Two ways:

  • Restart all: Turn off all Zookeeper services and start them after modifying the configuration. Does not affect the previous client session.
  • Restart one by one: as the name suggests. This is the more common way.

Part 5. Topics on Microservices

1. Why use microservice tracking? What problem does it solve?

1. What is the status of microservice invocation ?

  • The status quo of microservices: With the development of business, the monolithic architecture has become a microservice architecture, and the scale of the system has become larger and larger, and the call relationship between microservices has become more and more complex.
  • Multi-service collaborative work: In a micro-service application, a request initiated by a client will go through multiple different micro-service calls in the back-end system to collaboratively produce the final request result.
  • Complicated call chains are prone to errors: In a complex microservice architecture system, almost every front-end request will form a complex distributed service call link, and any dependent service in each link will have a delay timeout or error It may cause the final failure of the entire request.

2. What problem does the microservice tracking solve ?

Microservice tracking is actually a tool that can track the process of a user request (including data collection, data transmission, data storage, data analysis, and data visualization) in the entire distributed system. By capturing these tracking data, you can build microservices. View of the entire call chain, which is a key tool for debugging and monitoring microservices.

Spring Cloud S1euth has 4 characteristics:

  • Provide link tracking: Through sleuth, it is clear which services a request has passed. It is very convenient to sort out the calling relationship between services.
  • Performance analysis: Through sleuth, you can easily see the time-consuming of each sampling request, and analyze which service calls are more time-consuming. When the time-consuming of service invocation increases with the increase in the amount of requests, it can also provide a fixed reminder for the expansion of the service.
  • Data analysis and link optimization: For frequently calling a service or calling in parallel, some optimization measures can be taken for the business.
  • Visualization errors: The exceptions that are not caught by the program can be seen on the zipkin interface.

Written at the end:

Due to space limitations, only part of the interview questions are shown in the article. The author has compiled the complete interview questions into a PDF file, and friends who need it can help forward it;

Then click here to receive the complete interview documents for free!

The following is a screenshot of some interview questions

Sanmen Meituan finally got the offer and shared the interview questions: Spring+Dubbo+Redis+microservices...

Guess you like

Origin blog.csdn.net/weixin_47066028/article/details/113250316