国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Spring-boot JMS 發送消息慢的解決方法

Spring-boot JMS 發送消息慢的解決方法

2020-12-10 14:23YSHY Java教程

這篇文章主要為大家詳細介紹了Spring-boot JMS 發送消息慢的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Spring-boot JMS 發送消息慢的問題解決

1、在《ActiveMQ 基于zookeeper的主從(levelDB Master/Slave)搭建以及Spring-boot下使用》中,采用以下代碼進行JMS消息發送:

?
1
2
3
4
5
6
7
8
9
10
@Service
public class Producer {
 
 @Autowired
 private JmsMessagingTemplate jmsTemplate;
 
 public void sendMessage(Destination destination, final String message){
  jmsTemplate.convertAndSend(destination, message);
 }
}

經使用JMeter進行壓力測試,發現JMS的發送消息特別慢。

2、下面通過自定義CachingConnectionFactory解決。

(1)SenderConfig.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.example.springbootactivemq.jms;
 
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
 
/**
 * Created by yan on 2017/8/3.
 */
@Configuration
public class SenderConfig {
 
 @Value("${spring.activemq.broker-url}")
 private String brokerUrl;
 
 @Bean
 public ActiveMQConnectionFactory activeMQConnectionFactory() {
  ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
  activeMQConnectionFactory.setBrokerURL(brokerUrl);
 
  return activeMQConnectionFactory;
 }
 
 @Bean
 public CachingConnectionFactory cachingConnectionFactory() {
  return new CachingConnectionFactory(activeMQConnectionFactory());
 }
 
 @Bean
 public JmsTemplate jmsTemplate() {
  return new JmsTemplate(cachingConnectionFactory());
 }
 
 @Bean
 public Sender sender() {
  return new Sender();
 }
}

(2)Sender.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.example.springbootactivemq.jms;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
 
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
 
/**
 * Created by yan on 2017/8/3.
 */
public class Sender {
 
 @Autowired
 private JmsTemplate jmsTemplate;
 
 public void send(final String destination, final String message){
  this.jmsTemplate.convertAndSend(destination, message);
 }
}

(3)Receiver.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.example.springbootactivemq.jms;
 
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.listener.SessionAwareMessageListener;
import org.springframework.jms.support.JmsUtils;
 
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
 
/**
 * Created by yan on 2017/8/3.
 */
public class Receiver implements SessionAwareMessageListener<TextMessage> {
 
 @JmsListener(destination = "${queue.destination}")
 public void receive(String message) {
  try {
   Thread.sleep(2000);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
 
 }
}

(4)ReceiverConfig.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.example.springbootactivemq.jms;
 
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
 
/**
 * Created by yan on 2017/8/3.
 */
@Configuration
@EnableJms
public class ReceiverConfig {
 @Value("${spring.activemq.broker-url}")
 private String brokerUrl;
 
 @Bean
 public ActiveMQConnectionFactory activeMQConnectionFactory() {
  ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
  activeMQConnectionFactory.setBrokerURL(brokerUrl);
 
  return activeMQConnectionFactory;
 }
 
 @Bean
 public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
  DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
  factory.setConnectionFactory(activeMQConnectionFactory());
  factory.setConcurrency("3-10");
 
  return factory;
 }
 
 @Bean
 public Receiver receiver() {
  return new Receiver();
 }
}

(5)TestCtrl.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.example.springbootactivemq.test;
 
import com.example.springbootactivemq.jms.Sender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * Created by yan on 2017/8/2.
 */
@RestController
@RequestMapping(
  value = "/test",
  headers = "Accept=application/json",
  produces = "application/json;charset=utf-8"
)
public class TestCtrl {
 @Autowired
 private Sender sender;
 
 @Value("${queue.destination}")
 private String destination;
 
 @RequestMapping(
   value = "/say/{msg}/to/{name}",
   method = RequestMethod.GET
 )
 public Map<String, Object> say(@PathVariable String msg, @PathVariable String name){
  Map<String, Object> map = new HashMap<>();
  map.put("msg", msg);
  map.put("name", name);
 
  sender.send(destination, msg);
 
  return map;
 }
}

(6)application.properties

?
1
2
3
4
5
6
7
8
spring.activemq.broker-url=failover:(tcp://192.168.3.10:61616,tcp://192.168.3.11:61616,tcp://192.168.3.12:61616)
spring.activemq.in-memory=true
spring.activemq.pool.enabled=false
spring.activemq.user=admin
spring.activemq.password=admin
 
queue.destination=test.queue
queue.concurrency=3-10

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 免费在线观看黄色av | 日韩福利在线 | 国产色在线 | 欧美日韩一级视频 | 色精品 | a级性生活| 山岸逢花在线观看 | 黄色电影天堂 | 91色视频在线观看 | 国产精品美女久久久久久久网站 | av在线官网 | 中文字幕在线视频观看 | 国产精品成人3p一区二区三区 | 国产伦精品一区二区三区四区视频 | 日本在线观看网址 | 日韩精品一区二区在线视频 | 国产一区久久 | 亚洲视频一区 | 欧美视频网站 | 看毛片网| 成人综合激情 | 男女视频在线 | 日韩欧美在| 一级黄色a毛片 | 精品国产乱码久久久久久影片 | 欧美精品一区二区三区在线四季 | 国产丝袜一区 | 在线播放中文字幕 | 国产激情精品视频 | 欧美色影院 | 亚洲精品乱码 | 少妇精品久久久久久久久久 | 91视频在线 | jizzjizzjizz亚洲女 | 久操视频在线 | 色视频网 | 在线观看 亚洲 | 日本久久久久久 | 亚洲五码在线 | 久久国产精品久久久久久电车 | 一区二区三区久久 |