Springboot Episode 43: I know you are very strong but you don’t understand Kafka. You still can’t afford the 79 eyebrow pencil.

In Spring Boot, “bean” is a very important concept, which represents an object instance managed by the Spring container. These objects are typically used to make up various parts of an application, and can be shared and reused throughout the application. Spring Boot’s bean management is built based on the Spring framework’s IoC (Inversion of Control) and DI (Dependency Injection) principles.

Here are some key features and uses of Beans in Spring Boot:

  1. Component Management: Bean management allows you to create, configure and manage various components in your application, such as services, data access objects (DAO), controllers, etc. These components can be instantiated and initialized through the Spring container and then injected where needed.

  2. Dependency injection: The Spring Boot container is responsible for managing dependencies between beans. Through dependency injection, a Bean can inject other Beans it depends on into its own properties or constructors, thereby achieving decoupling and loose coupling between components.

  3. Singleton Management: By default, Spring Boot configures Beans as singletons. This means that the container will only create one instance of the bean and reuse it when needed. This helps reduce resource consumption and improve performance.

  4. Configuration Management: Spring Boot allows you to use annotations or XML configuration files to define beans and their dependencies. You declare which classes should be instantiated as beans in your application’s configuration file, and you can configure their properties and behavior.

  5. Life cycle management: Spring container manages the life cycle of beans, including instantiation, initialization, use and destruction. You can define initialization and destruction methods to perform custom logic during the bean’s life cycle.

  6. AOP (Aspect-Oriented Programming): Spring Boot supports AOP, allowing you to define cross-cutting concerns, such as logging, performance monitoring, etc., and apply them to Bean methods.

  7. Testing: Spring Boot’s bean management makes unit and integration testing easier because you can easily mock or replace a bean’s dependencies.

In short, beans in Spring Boot are a flexible and powerful mechanism for organizing and managing various components of an application, making the application easier to maintain, test, and extend. With the help of the Spring container, beans can be managed in a highly configurable way, thus achieving loose coupling, maintainability, and testability.

DruidDataSource dataSource = new DruidDataSource(): Here, a Druid data source object is created. Druid is a popular database connection pool for managing database connections.

cd26e74c734cd596bbe8eaa181351984.png

image.png
4a2ab2e014246a8b1fca5855205f9918.png
image.png
d265d984da76ffb1936f16989f4dd30a.png
image.png
a57a7628ff8137c31f3c00bba2c9c324.png
image.png

kubectl kubelet kubeadm version: 1.23.1 Operating system version: CentOS 8.2 64-bit

Open the 30000 port on the external network, and use subsequent browsers to log in to the k8s dashboard. And check whether the ssh service port 22 is opened normally.

eed9a888f5cae82fc33d1a7253178179.jpeg

Install common tools:

yum install -y yum-utils device-mapper-persistent-data lvm2 iproute-tc

There is a wall problem in China, add Ali source acceleration:

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

To create a scheduled task, you can use the @Scheduled annotation to mark a method and specify the trigger time of the task. Here is an example:

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTask {

    @Scheduled(fixedRate = 5000) // Execute every 5 seconds
    public void performScheduledTask() {
        // Logic for executing scheduled tasks
        // This can be any code you need to execute regularly
    }
}

In the above example, the performScheduledTask method is marked as a scheduled task using the @Scheduled annotation, and the fixedRate parameter specifies the trigger time of the task. Here is the Executed every 5 seconds.

4. Configure asynchronous tasks and scheduled tasks

Make sure to add the @EnableAsync and @EnableScheduling annotations to your Spring Boot application’s configuration class to enable support for asynchronous tasks and scheduled tasks. For example:

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableAsync
@EnableScheduling
public class TaskConfig {
    //Configuration class
}

Text search can generally be divided into three types: fuzzy search, precise search, and word segmentation search.

  • Fuzzy search: such as the like query statement in SQL, which matches content containing search keywords.

  • Precise search: The text content is consistent with the search keywords.

  • Word segmentation search: segment the text first, including search keyword segmentation and search content segmentation, and then match related content.

#!/bin/bash

# Define the name of the application to be closed
APP_NAME=""

# Find the process ID (PID) of the application
PID=$(ps -ef | grep "$APP_NAME" | grep -v grep | awk '{ print $2 }')

if [ -z "$PID" ]; then
  echo "The application has stopped"
else
  echo "Close application $APP_NAME (PID: $PID) ..."
  kill -9 "$PID"
  echo "Application closed successfully"
fi

30c85e1f2482e4c72170559f55b5ddf7.png

image.png

/ect/profile is used to set environment variables. The content sample is as follows

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
export JAVA_HOME=/usr/share/jdk1.8.0_14
export PATH=$JAVA_HOME/bin:.....

5c9f84044abd3fc24a7ef859bd0e79b6.png

image.png
71b8b4294df094a06602db118590de07.png
image.png

A MySQL index is a data structure used to improve database query performance. They speed up retrieval and query operations by creating copies of the data stored in tables. The main purpose of an index is to reduce the amount of data that the database system needs to scan, thereby speeding up data retrieval.

The following is a sample database and sample code that illustrates what MySQL indexes do and how to use them:

Example database:

Suppose we have a simple student information database, which contains a table named students that stores student information, including student ID, name, age, and course. Here is an example database table structure:

CREATE TABLE students (
    student_id INT PRIMARY KEY,
    name VARCHAR(50),
    age INT,
    course VARCHAR(50)
);

The table contains the following sample data:

Sample code:

Here is some sample code that demonstrates how to use MySQL indexes to optimize query operations.

  1. Create index:

    Create an index on the name column of the students table:

    CREATE INDEX idx_name ON students (name);
  2. Query Optimization:

    Find all students age 22:

    SELECT * FROM students WHERE age = 22;

    With the index, the query is more efficient because MySQL can quickly target students who are 22 years old.

  3. Covering Index:

    If you only need to query the student’s name and no other information, you can use a covering index:

    SELECT name FROM students WHERE age = 22;

    This will reduce the amount of data read since only the index needs to be accessed and not the actual data rows.

  4. Union index:

    Create a joint index to optimize queries on multiple columns:

    CREATE INDEX idx_age_course ON students (age, course);

    Find students who are 22 years old and whose course is “Math”:

    SELECT * FROM students WHERE age = 22 AND course = 'Math';

    Joint indexes can speed up queries with compound conditions.

In short, MySQL indexes are an important tool used to improve database query performance. By creating appropriate indexes, you can speed up common query operations and reduce data scanning time, thereby improving database response speed. However, indexes need to be used with caution as improper use of indexes can lead to performance degradation. When designing a database, you need to choose which indexes to create based on specific query requirements and data distribution.

In MySQL, there are many types and methods of indexes to choose from, each type and method has its applicable scenarios and characteristics. Here are some common MySQL index types and methods and examples of how to use them:

1. B-Tree index: B-Tree (balanced tree) index is the most common index type and is used to support equality queries, range queries and sorting operations.

Example: Create a B-Tree index to optimize the student_id column in the students table:

CREATE INDEX idx_student_id ON students (student_id);

2. Hash index: Hash index is a special index type used for equivalent queries, suitable for situations where only exact matching is required.

Example: Create a hash index to optimize the user_id column in the users table:

CREATE INDEX idx_user_id ON users (user_id) USING HASH;

3. Full-text index: Full-text index is used to support full-text search, usually on text columns.

Example: Create a full-text index to optimize the content column in the articles table:

CREATE FULLTEXT INDEX idx_content ON articles (content);

4. Spatial index: Spatial index is used for geospatial data and supports geospatial queries.

Example: Create a spatial index to optimize the coordinates column in the locations table:

CREATE SPATIAL INDEX idx_coordinates ON locations (coordinates);

5. Joint index: A joint index is an index created on multiple columns and is used to optimize queries with multiple conditions.

Example: Create a union index to optimize the customer_id and order_date columns in the orders table:

CREATE INDEX idx_customer_order ON orders (customer_id, order_date);

6. Prefix index: A prefix index is an index created on a portion of a column to reduce the index size.

Example: Create a prefix index to optimize the first 5 characters of the product_name column in the products table:

CREATE INDEX idx_product_name ON products (product_name(5));

7. Custom index methods: MySQL allows you to create custom index methods to meet specific query needs.

sudo rm /usr/local/mysql

sudo rm -rf /usr/local/mysql*

sudo rm -rf /Library/StartupItems/MySQLCOM

sudo rm -rf /Library/PreferencePanes/My*

sudo rm -rf /Library/Receipts/mysql*

sudo rm -rf /Library/Receipts/MySQL*

sudo rm -rf /var/db/receipts/com.mysql.*

cd4e1dab2abc2f66c66837577bdfd297.png
49d4bda6d51aa071a1948475d39ee964.png
7f63a666198a67029071da39c030f5af.png
fc89639e780df46934ec58d16ccfb321.png
f6ca280612223bad8d4664fab0b7fa7d.png
76cfcd4bb252cb6886f3f6da978f4bd3.png
c38b9ceff5122d8f37cfe88e816a63eb.png
7bcb1e8ced832e9cdb8cee0fb5459f81.png
e19f163f413a24b561a166096baa8171.png
2ae519607d35801839fe8020b643ee46.png
c84e69f62c7858d18077104b41eed036.png
a09b1630210b9a8cb06d615c1124dcaf.png
40c2ff4e1efe82f4c002295010744a0b.png
9ef396927e2ee8f5e64208c028c7eb7d.png
cbe97796b5f9539b3c699fc03408b73e.png
d887a88978bea272e8f3f7f44972778a.png
5729b0c0356d7225995cf2cef9d1024b.png
03eb63a6d485d34f7e4ed9618ee689e4.png
25dea76df78a0c4e56c0134a94b2f05f.png
c21a4093086f9b6b7782d66c3570655b.png
af3d82c75023576a3ce8829725a2f0c7.png
3f8f227c632af149186c262c32981288.png
a04bc91dff780e64b82ea37a7184113b.png
585decf3d1e855f9413c1875217dfe1b.png
7b31b8c418d04730cc48b96987417e71.png
0afe2dbec4dd58a7075ee2b2abd74f32.png
516f5b6dd5d6a0ed0e59e1a387002f17.png
515d975c8b1fdf92e9333f6d6bbb5655.png
1638c088914f56c8640c323b361c24aa.png

Zookeeper must be started before starting kafka

zookeeper cluster, view the process

60e8622576dd2059a2b57ac9b3cf9d48.png

Start kafka

da8f47b14a19109a8bf9619979634829.png
69f0d9512e84b02f4dd58bc3c67b517d.png
4245c75dc18529851016f94296bdef36.png

startup script

6f5024c5ba7b56643ce28b316b956041.png
a17b28809abd69001938cc28973c09af.png
9ad191c73bc94c1bf57111dfc8cd981e.png
c4e1b46f4e00e9c8c3a0f58233dd47e3.png
85aea72bc24f04e3393084ce1bb181c9.png
a3c3d786f89f36bf713ec3fe085cca2f.png
83f4c13f12ebc3be5d2417e9f965aac3.png
8eab5c6515ee384119b39e0ba9d52df6.png
996e529ca678adcd4db18e7ec538ba27.png
3634e79716de3bf8b7c21dd281daa39e.png
e8edee94b3fa1668f400d6fec2308cc5.png
ffcda37bc29f18e15b27d0d30830b288.png

The copy cannot be modified through the command line.

ed09a771d2a4f88e3c7cde962a9b3532.png
ced7274f709c4aa529e233a79bc47993.png
2df15c2bbef69edd7dfdc91cceba725d.png
2f381a39fd345392eecc792fd2acd406.png

0: The data sent by the producer does not need to wait for the data to be sent to the disk for a response.

1: The data sent by the producer, the leader responds after receiving the data.

-1(all): The data sent by the producer, Leader and all nodes in the ISR queue receive the data and respond. -1 is equivalent to all.

49d7d736120730c5c81a229e1a8b361d.png
0d554210bce353b14d8282f435d1d44a.png
c3f20f4b14c5ddcf11223b41822e11e9.png

deque

a7dc4dabb035000be7ccdf1efb0af283.png
cfdb36751257b9f0d43514f1550fe431.png
a694a313b2e7b96dc7db38758e108f1f.png

Send process

4bf7e9c70a904728c73379b59e1ed07c.png
fa3d3dad94b8884896b359b9d15a4e40.png
663d9cf2997d83758912567b77b8373f.png
eb262773f65ff2d055559056adddaed2.png
a3d6d72367bf449ba6d8e25acbfded74.png
0a6dfbe8e2715ad9fd6e1eccb3c6f259.png
64de9e4576234f4ea710cc4cbe0233d6.png
4533fe7bbd78f42592aaa1131f50501e.png
eeaec9d07995c7549622e4d89e18cdf6.png
c4ddf665544109802d196d5895ccd845.png
51195077acce21f7fc89f0516203bfec.png
0e3bcce1cf812dbc89a2c9df79e8d246.png

SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
String dateTime=sdf.format(new Date());
sysRole.setUpdateT(dateTime);

4bb63ef906401ce7eb8fc8ac5497bbd1.png
e53cfe10d545be173b2b8fc1ced54289.png
e3a73a63629b35caedcf1d524b217473.png
9da59726bc281738ffe06357548a9559.png
9541faae8475d18e0d57e8cb34f64c15.png
c662645565fc6847e1973b5b7c0cb4f3.png
a21b65f7fd7ceba88f206344caa24274.png
8bf9ac54f842c83307e83abdf90e7e85.png
b522621facb28b8060263d4f01562983.png
aa485c3f8cd745dfb54a956f48ad1a8f.png
303bbe0d9ff0eb78127cbf3baa008381.png
2eb4d4a333372e843faefbf0f8acb396.png
85023c5340f1227547dda5fd931bcc98.png
051d3ab7a6a712e740698d867b432a78.png
57c391971c551215c076cf2de17a8991.png
19a557a085cef31784c7697ef617d904.png
7ecad87f4bc919001189959253ac950f.png

Production experience, data in order

2dca45990051f7e0e4e339c10eec2e58.png
6bb36544c0e3e771f921a4ea529fb766.png
3924e89a45b098628ddc04c02b096bd9.png
2aa8045c09c08c847dcb4d97caf76a5e.png
bb9b10ac068fb387d416269d4c591d5e.png
b62c9a18ee7b3388eaeb308ec0c00ce4.png
f613a63b174aaa7651d26bb32caa6946.png
46d3792ddd345493ea97c8268ebf413b.png
37b62e958515b78e37451748f64c8504.png
fd9a96f8ecfdd33cb4e2f8eeb7bcdc6e.png
c12022177caf8e7f35b152d81ef8cbb7.png
833afec02251d3300e784d9bca0392ef.png
438151e8e1b817d67ffb7a1382f1904d.png
77f371dfcb6f931e84280ac56865e1df.png
76568b06ef10ed9f30e15d1d7905a95d.png
fe73a7f3a6869c55cd12855808395b2d.png
a7d24ffe50d04d26dcc251b3db79aa6a.png

#!/bin/bash

# Define the name of the application to be closed
APP_NAME="admin-gateway-1.0-SNAPSHOT.jar"

# Find the process ID (PID) of the application
PID=$(ps -ef | grep "$APP_NAME" | grep -v grep | awk '{ print $2 }')

if [ -z "$PID" ]; then
  echo "The application has stopped"
else
  echo "Close application $APP_NAME (PID: $PID) ..."
  kill -9 "$PID"
  echo "Application closed successfully"
fi

25754d4854b0ecaa84d43f940a2b135b.png
457dc312bebcc4ca9c7ebc55d25e047c.png
af399edd8854297821ca77edcaf015ce.png
650a5b3338a04d5a764eb014fa4bfdfd.png
f1664f5017d73bc1c39306ad3b3195aa.png

Join the group and contact the author vx: xiaoda0423

Warehouse address: https://github.com/webVueBlog/JavaGuideInterview

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Java Skill TreeHomepageOverview 136843 people are learning the system

syntaxbug.com © 2021 All Rights Reserved.
student_id name age course
1 John 20 Math
2 Alice 22 History
3 Bob 21 Chemistry
4 Sarah 23 Biology
5 Michael 22 Math