Home > front end >  Ssm&redis & kafka&es steps
Ssm&redis & kafka&es steps

Time:09-23

1. The SSM integrate redis
1. Import dependence
2. Write the configuration file, modify the configuration files of the IP and port



3. Let the spring configuration file loaded redis configuration


4. Can directly use redis. Code anywhere again, inject RedisTemplate'll ok




2. Redis as caching ideas

1. The first query do you have any data from redis
2. If no hot spots in the redis data, out of the mysql query, query out after to redis save a return
3. If there is data in redis, direct return on ok

` ` ` Java
//redis optimization:
//1. The first to see if there are any from redis
List RedisPlans=redisTemplate. OpsForList (). The range (" zhunneng_plans ", 0, 1);
If (redisPlans==null | | redisPlans. The size ()==0) {
//in the redis don't have the figures, from the mysql query, and add a redis, returned to the front desk
PageInfo Info=planService. The.findall (pageNum, pageSize);
System. Out.println (" query the data from mysql!!!!!!!!!!!!!!!!!!!!!!!!!!! ");
//to deposit a
in redisRedisTemplate. OpsForList (.) rightPushAll (" zhunneng_plans "info. GetList (). The toArray ());
Model. The addAttribute (" info ", the info).

} else {
//redis data not empty
System. Out.println (" query from redis data!!!!!!!!!!!!!!!!!!!!!!!!!!! ");
Model. The addAttribute (" info ", new PageInfo<> (redisPlans));
}

` ` `

note: don't forget to start redis service

3. Integration of kafka in SSM (producers)

1. Import dependence (with the dependence of pom)
2. Write the configuration file producer. XML, modify the theme, IP, port
3. Let the spring loaded producer. XML



4. Can be in the position of the injection Kafkatemplate is required to use the



4. Integration of kafka in SSM (consumer)

1. Import dependence
2. Write the configuration file (consumer. XML), modify the configuration files of the IP, themes, listeners are fully qualified class name
3. Let the spring configuration file loaded consumer. XML



4. Can according to the configuration file, write the listener



5. If you want to test, receive messages, be sure to start the kafka in kafka's service (start the zk), to test whether messages are received on the server, and start a customer, listening to the news

5. SSM in the integration of es

1. Import dependence
2. Write the configuration file, modify IP and port, warehouse interface package scan location specified



3. According to the location of the configuration file bag, can create the interface (inheritance: ElasticsearchRepository), at this time the interface has the function of the CRUD



4. * * indexes specified in the entity class library with the name of the * * * * must be lowercase (* *), and the name of the table, the id, the specified primary key corresponding to the specified storage properties of a search field



5. Then we'll write a test class, can be injected XXXRepository this interface, realize the data import, because we have not data index of es repository, you want to search the data, have to query the data from mysql, then imported into the library es index, can ensure that mysql data, and es index data consistency



6. We can call directly to our HLUtils tools, realize highlighting the

` ` ` Java
PageInfo Info=(PageInfo) HLUtils. FindByHighLight (elasticsearchTemplate, Plan. Class, pageNum, pageSize, new String [] {" manager ", "name", "content"}, "id", keyword).
` ` `

6. The project is deployed to the Linux

1. Modify the db. The properties








note: Linux doesn't identify \ only identify/

2. The relevant import table of mysql on Windows to Linux in mysql





3. Then can pack



4. Log in to find out the corresponding war



5. Find the location of the war, copied to the desktop, rename called ROOT. War



6. Open the CRT, upload ROOT. The war under the tomcat webapps, note: be sure to turn off before * * upload a tomcat, and then delete the ROOT directory * *
Dynamic view log
7.


8. Start tomcat (* * note: before you start tomcat, guarantee the redis, es, kafka service startup * *)




9. In the browser to access the project



10. The simulation of a domain name to access, to: C: \ Windows \ system32 \ drivers \ etc \

Looking for a hosts file. Modify the content in the hosts file:


After successfully saved, can direct access!!

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related