In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to achieve high concurrency in the Hystrix request merge, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Implement merging of Hystrix requests in SpringCloud under high concurrency
1. Introduce maven package into pom.xml
Org.springframework.cloud
Spring-cloud-starter-netflix-hystrix
2.1.6.RELEASE
The spring Boot package is introduced, and the version must be consistent, otherwise an error message will be started.
Org.springframework.boot
Spring-boot-starter-parent
2.1.12.RELEASE
2. Add startup comments
@ EnableCircuitBreaker the annotation starts hystrix, otherwise it will not take effect.
@ SpringBootApplication
@ EnableScheduling
@ EnableSwagger2
@ EnableCaching
@ EnableAsync
@ ServletComponentScan
@ EnableMqHandlerScan (packages = {"com.sxgw.pcops.im.client.mq.handler"})
/ / use of hystrix must be increased
@ EnableCircuitBreaker
Public class ClientApplication {
Public static void main (String [] args) {
SpringApplication.run (ClientApplication.class, args)
}
}
3. Request API Controller
@ Api (value = "test")
@ RestController
@ RequestMapping ("/ test")
@ Slf4j
Public class TestController {
@ Autowired
Private UserBatchServiceImpl userBatchServiceImpl
ApiOperation ("Test request merge")
@ PostMapping (value = "/ userbyMerge/ {id}")
Public String userbyMerge (@ PathVariable Long id) {
String ids = ""
Try {
Future userFu = this.userBatchServiceImpl.getUserById (id)
Ids = userFu.get ()
} catch (Exception e) {
E.printStackTrace ()
}
Return ids
}
}
4. Write request merge logic
TimerDelayInMilliseconds this parameter sets the interval time between thread pools. For example, interval 5000ms means that a thread pool waits for 5 seconds before execution.
/ * *
*
* @ author
*
, /
@ Component
Public class UserBatchServiceImpl {
@ HystrixCollapser (batchMethod = "getUserBatchById", scope= com.netflix.hystrix.HystrixCollapser.Scope.GLOBAL
CollapserProperties = {@ HystrixProperty (name = "timerDelayInMilliseconds", value = "5000")})
Public Future getUserById (Long id) {
Throw new RuntimeException ("This method body should not be executed")
}
@ HystrixCommand
Public List getUserBatchById (List ids) {
System.out.println ("enter batch processing method" + ids)
List ps = new ArrayList ()
For (Long id: ids) {
Ps.add (id+ "")
}
Return ps
}
}
5. During the test, you can see the effect through the jmeter test tool.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.