notes
5, the abnormality alarm notification fuse downgrade the actual
profile: improve service fusing process, improve alarm system
1, added redis dependent
<dependency>
<the groupId> org.springframework.boot </ the groupId>
<the artifactId> Starter-Spring-Boot-DATA- redis </ the artifactId>
</ dependency>
2, link configuration information redis
redis:
Database: 0
Host: 127.0.0.1
Port: 6379
timeout: 2000
. 3, using
@ alarm monitoring
String saveOrderKye = "Save-Order";
String = sendValue redisTemplate.opsForValue () GET (saveOrderKye);.
Final IP = request.getRemoteAddr String ();
new new the Thread (() -> {
IF (StringUtils.isBlank (sendValue)) {
System.out.println ( "urgent message, the user single failure, please find out the reasons to leave, ip address =" + ip);
// send a http request, call the SMS service TODO
redisTemplate.opsForValue () SET (saveOrderKye, "Fail-Save-Order", 20 is, TimeUnit.SECONDS);.
} the else {
System.out.println ( "has sent a message, the transmission will not be repeated within 20 seconds");
}
.}) start ();
Start
Send the message key stored in the inside Redis, automatically expire after 5 minutes. After the failure to continue to send text messages.
Redis is no longer here to explain the installation steps, the machine has been installed by default.
FIG pressurized pack that is already off the redis
mac service native promoter redis
After a successful start, spring boot link redis
1, redis dependent added
<dependency>
<the groupId> org.springframework.boot </ the groupId>
<the artifactId> Starter-Spring-Boot-Data-redis </ the artifactId>
</ dependency>
2, link configuration information redis
redis:
Database: 0
host: 127.0.0.1
Port: 6379
timeout: 2000
relies on the addition of maven
add comments
specified Redis link information
below we have to configure the application
will prompt the shortcut key
to select this
generates the code
input h go to select host
generating host.
Enter por selection
generated port is the default port 6379
Finally, there is a timeout
final configuration
inject redis
finished writing the code above found that this is a synchronous call, the call will be finished and then continue to go down. So we need to create a thread to do it.
With a lamada expression to do it.
Open a sub-thread to send text messages. It does not affect our whole process
to restart the service for testing. The productService service closed
several times to refresh the page to access
high concurrent situation can lock the mechanism of redis, own search
one more parameter in method
we can output ip address, so you can determine which server a problem