最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring-boot JMS 發(fā)送消息慢的解決方法

 更新時(shí)間:2017年08月04日 08:39:19   作者:YSHY  
這篇文章主要為大家詳細(xì)介紹了Spring-boot JMS 發(fā)送消息慢的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Spring-boot JMS 發(fā)送消息慢的問題解決

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

@Service
public class Producer {

 @Autowired
 private JmsMessagingTemplate jmsTemplate;

 public void sendMessage(Destination destination, final String message){
  jmsTemplate.convertAndSend(destination, message);
 }
}

經(jīng)使用JMeter進(jìn)行壓力測試,發(fā)現(xiàn)JMS的發(fā)送消息特別慢。

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

(1)SenderConfig.java

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

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

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

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

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

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

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java設(shè)計(jì)模式中的建造者(Builder)模式解讀

    Java設(shè)計(jì)模式中的建造者(Builder)模式解讀

    這篇文章主要介紹了Java設(shè)計(jì)模式中的建造者(Builder)模式解讀, 建造者模式是一種創(chuàng)建對(duì)象的設(shè)計(jì)模式,它通過將對(duì)象的構(gòu)建過程分解為多個(gè)步驟,并使用一個(gè)建造者類來封裝這些步驟,從而使得對(duì)象的構(gòu)建過程更加靈活和可擴(kuò)展,需要的朋友可以參考下
    2023-10-10
  • 解析Java圖形化編程中的文本框和文本區(qū)

    解析Java圖形化編程中的文本框和文本區(qū)

    這篇文章主要介紹了Java圖形化編程中的文本框和文本區(qū),是Java入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-10-10
  • springboot單文件下載和多文件壓縮zip下載的實(shí)現(xiàn)

    springboot單文件下載和多文件壓縮zip下載的實(shí)現(xiàn)

    這篇文章主要介紹了springboot單文件下載和多文件壓縮zip下載的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • SpringBoot實(shí)現(xiàn)Md5對(duì)數(shù)據(jù)庫數(shù)據(jù)加密的示例

    SpringBoot實(shí)現(xiàn)Md5對(duì)數(shù)據(jù)庫數(shù)據(jù)加密的示例

    本文主要介紹了SpringBoot實(shí)現(xiàn)Md5對(duì)數(shù)據(jù)庫數(shù)據(jù)加密的示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • 詳解如何使用Java編寫圖形化的窗口

    詳解如何使用Java編寫圖形化的窗口

    這篇文章主要介紹了如何使用Java編寫圖形化的窗口,是Java的本地GUI軟件開發(fā)的基礎(chǔ),需要的朋友可以參考下
    2015-10-10
  • Spring IOC原理補(bǔ)充說明(循環(huán)依賴、Bean作用域等)

    Spring IOC原理補(bǔ)充說明(循環(huán)依賴、Bean作用域等)

    這篇文章主要介紹了Spring IOC原理補(bǔ)充說明(循環(huán)依賴、Bean作用域等),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Spring Boot Actuator入門指南

    Spring Boot Actuator入門指南

    SpringBootActuator是SpringBoot提供的一系列產(chǎn)品級(jí)特性,用于監(jiān)控應(yīng)用程序、收集元數(shù)據(jù)和運(yùn)行情況,通過添加依賴,可以通過HTTP或JMX與外界交互,本文介紹Spring Boot Actuator的相關(guān)知識(shí),感興趣的朋友一起看看吧
    2025-02-02
  • springboot實(shí)現(xiàn)獲取客戶端IP地址的示例代碼

    springboot實(shí)現(xiàn)獲取客戶端IP地址的示例代碼

    本文介紹了在SpringBoot中獲取客戶端IP地址的幾種方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-11-11
  • 一名Java高級(jí)工程師需要學(xué)什么?

    一名Java高級(jí)工程師需要學(xué)什么?

    作為一名Java高級(jí)工程師需要學(xué)什么?如何成為一名合格的工程師,這篇文章給了你較為詳細(xì)的答案,需要的朋友可以參考下
    2017-08-08
  • 詳解在spring中使用JdbcTemplate操作數(shù)據(jù)庫的幾種方式

    詳解在spring中使用JdbcTemplate操作數(shù)據(jù)庫的幾種方式

    這篇文章主要介紹了詳解在spring中使用JdbcTemplate操作數(shù)據(jù)庫的幾種方式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07

最新評(píng)論

会东县| 卢氏县| 庆城县| 镇安县| 贺州市| 安化县| 民丰县| 北辰区| 砀山县| 泽库县| 册亨县| 东阳市| 云林县| 钦州市| 大庆市| 皮山县| 德安县| 乾安县| 门头沟区| 新闻| 曲靖市| 岱山县| 金川县| 秦皇岛市| 浦县| 利津县| 千阳县| 论坛| 泸定县| 广平县| 泗阳县| 尉犁县| 通河县| 长丰县| 桓台县| 石城县| 民权县| 杂多县| 陇南市| 神农架林区| 榕江县|