activemq整合springboot使用(个人微信小程序用)(代码片段)

zhangsansan zhangsansan     2022-12-02     560

关键词:

1.引入依赖

<parent>
<groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

2.修改配置文件(其实配置也是默认值,不配置也可以)

spring.activemq.in-memory=true
spring.activemq.pool.enabled=false

3.添加ActiveMq连接池(如果不开启连接池,则每发送一条数据创建一个连接)

①.添加依赖
<dependency>
     <groupId>org.apache.activemq</groupId>
     <artifactId>activemq-pool</artifactId>
</dependency>
②.修改配置文件
#服务端口,8080被另一服务占用
server.port=9090
spring.activemq.broker-url=tcp://127.0.0.1:61616
# 在考虑结束之前等待的时间
#spring.activemq.close-timeout=15s
# 默认代理URL是否应该在内存中。如果指定了显式代理,则忽略此值。
spring.activemq.in-memory=true 
# 是否在回滚回滚消息之前停止消息传递。这意味着当启用此命令时,消息顺序不会被保留。
spring.activemq.non-blocking-redelivery=false
# 等待消息发送响应的时间。设置为0等待永远。
spring.activemq.send-timeout=0
#默认情况下activemq提供的是queue模式,若要使用topic模式需要配置下面配置
spring.jms.pub-sub-domain=true
#账号
spring.activemq.user=admin
# 密码
spring.activemq.password=admin
# 是否信任所有包
#spring.activemq.packages.trust-all=
# 要信任的特定包的逗号分隔列表(当不信任所有包时)
#spring.activemq.packages.trusted=
# 当连接请求和池满时是否阻塞。设置false会抛“JMSException异常”。
#spring.activemq.pool.block-if-full=true
# 如果池仍然满,则在抛出异常前阻塞时间。
#spring.activemq.pool.block-if-full-timeout=-1ms
# 是否在启动时创建连接。可以在启动时用于加热池。
#spring.activemq.pool.create-connection-on-startup=true
# 是否用Pooledconnectionfactory代替普通的ConnectionFactory。
#spring.activemq.pool.enabled=false
# 连接过期超时。
#spring.activemq.pool.expiry-timeout=0ms
# 连接空闲超时
#spring.activemq.pool.idle-timeout=30s
# 连接池最大连接数
#spring.activemq.pool.max-connections=1
# 每个连接的有效会话的最大数目。
#spring.activemq.pool.maximum-active-session-per-connection=500
# 当有"JMSException"时尝试重新连接
#spring.activemq.pool.reconnect-on-exception=true
# 在空闲连接清除线程之间运行的时间。当为负数时,没有空闲连接驱逐线程运行。
#spring.activemq.pool.time-between-expiration-check=-1ms
# 是否只使用一个MessageProducer
#spring.activemq.pool.use-anonymous-producers=true

4.添加JMS相关配置

①.开启JMS扫描注解:@EnableJms 相当于application.xml中的<jms:annotation-d riven/>
②.配置Queue类:
@Bean
public Queue queue() 
    return new ActiveMQQueue("queueName1");

③.创建生产者:
@Resource
JmsMessagingTemplate jmsMessagingTemplate;
public void sendMessage(Destination destination, String message) 
    jmsMessagingTemplate.convertAndSend(destination, message);

④.创建消费者:
@JmsListener(destination = "queueName1")
public void receiveQueue(String message) 
    log.info("=========接受到了消息:" + message);
    grabService.addSearchContent(message, mainConfig.getCharset());

ps:@JmsListener(destination = "queueName1")注解用于监听指定名称的消息
参数message代表具体的消息

springboot整合activemq1(基本使用)(代码片段)

基本使用,https://www.tapme.top/blog/detail/2018-09-05-10-38主备模式,https://www.tapme.top/blog/detail/2018-09-06-10-38说明:acitveMQ版本为:5.9.1,springboot版本为2.0.3一.下载安装(windows)??官方下载地址:点我跳转,选择windows安装包下载,然后解压,解压 查看详情

springboot1.5.10整合activemq5.14

此篇文章介绍springboot集成activemq,使用的版本为:springboot1.5.10,activemq5.13首先安装Windows版的activeMq,本机安装的是为5.15.4。在安装路径apache-activemq-5.15.4-bininwin64,双击activemq.bat启动服务。我们知道queue的消息发送有两种,一种... 查看详情

springboot+activemq整合

Springboot+Activemq整合1导入整合所需要的依赖:<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId></dependency>2创建 a 查看详情

activemq学习系列activemq与springboot整合

activemq与springboot整合1、添加依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId><exclusions><exclusion> 查看详情

springboot整合activemq

一、添加依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId></dependency>二、添加配置#activemqspring.activemq.broker 查看详情

springboot整合activemq

1.maven依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId></dependency>2.properties.yml配置spring:activemq: 查看详情

springboot整合activemq

1、配置连接信息  引入maven信息<!--整合消息队列ActiveMQ--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId></d 查看详情

springboot整合activemq

一、创建项目并导入依赖??<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId> </dependency> <dependency> & 查看详情

springboot整合activemq

(1)、添加starter依赖1<dependency>2<groupId>org.springframework.boot</groupId>3<artifactId>spring-boot-starter-activemq</artifactId>4</dependency>(2)、配置相关信息1spring.active 查看详情

springboot整合activemq(代码片段)

  消息队列,用来处理开发中的高并发问题,通过线程池、多线程高效的处理并发任务。  首先,需要下载一个ActiveMQ的管理端:我本地的版本是activemq5.15.8,打开activemq5.15.8\\bin\\win64\\wrapper.exe客户端,可以根据localhost:端口... 查看详情

springboot整合activemq配置文件

application.properties文件配置:#服务端口,8080被另一服务占用server.port=9090spring.activemq.broker-url=tcp://127.0.0.1:61616#在考虑结束之前等待的时间#spring.activemq.close-timeout=15s#默认代理URL是否应该在内存中。如果指定了显式代理,则忽略此... 查看详情

springboot整合activemq

1.生产者1.1导入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><!--springbootweb支持:mvc,aop...- 查看详情

springboot整合jms(activemq实现)

一、安装ActiveMQ具体的安装步骤,请参考我的另一篇博文:http://blog.csdn.net/liuchuanhong1/article/details/52057711二、新建spring boot工程,并加入JMS(ActiveMQ)依赖三、工程结构pom依赖如下: [html] viewplain copy <?xml&nbs 查看详情

springboot整合activemq实现持久化

点对点(P2P)  结构    创建生产者和消费者两个springboot工程       导入依赖    <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-activemq</artifactId>< 查看详情

springboot整合activemq开启持久化

1.开启队列持久化只需要添加三行代码jmsTemplate.setDeliveryMode(2);jmsTemplate.setExplicitQosEnabled(true);jmsTemplate.setDeliveryPersistent(true);   2.开启主题持久化,启动类添加如下配置@Bean(name="topicListenerFactory") 查看详情

web项目容器集成activemq&springboot整合activemq

  集成tomcat就是随项目启动而启动tomcat,最简单的方法就是监听器监听容器创建之后以Broker的方式启动ActiveMQ。1.web项目中Broker启动的方式进行集成  在这里采用Listener监听ServletContext创建和销毁进行Broker的启动和销毁。0.需... 查看详情

springboot入门andspringboot与activemq整合

1.SpringBoot入门1.1什么是SpringBootSpring诞生时是Java企业版(JavaEnterpriseEdition,JEE,也称J2EE)的轻量级代替品。无需开发重量级的EnterpriseJavaBean(EJB),Spring为企业级Java开发提供了一种相对简单的方法,通过依赖注入和面向切面编... 查看详情

springboot整合activemq,消费均匀分析

问题分析:当如果多个消费者是什么情况呢topic消费是友多个消费者的,是支持的,但是queue是支持,但是不能保证多个消费均匀消费,在分布式环境下怎么操作呢: 看案例:在前面整合代码执行:浏览器输入  http://localhost:8080/pu... 查看详情