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

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

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

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

1、在《ActiveMQ 基于zookeeper的主從(levelDB Master/Slave)搭建以及Spring-boot下使用》中,采用以下代碼進行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進行壓力測試,發(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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

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

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

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

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

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

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

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

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

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

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

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

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

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

    Spring Boot Actuator入門指南

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

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

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

    一名Java高級工程師需要學什么?

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

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

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

最新評論

蕲春县| 涡阳县| 怀远县| 饶平县| 上虞市| 慈溪市| 浮梁县| 江北区| 宜君县| 中阳县| 拜泉县| 万安县| 青神县| 毕节市| 富蕴县| 门源| 疏勒县| 隆子县| 菏泽市| 鄯善县| 信宜市| 宜昌市| 屯留县| 墨玉县| 胶州市| 龙海市| 朔州市| 虞城县| 闵行区| 乌海市| 沾化县| 昆明市| 新巴尔虎左旗| 荃湾区| 团风县| 台中县| 松江区| 信阳市| 石泉县| 永安市| 恩施市|