activemq整合springboot使用方法(个人微信小程序用)

这篇文章主要介绍了activemq整合springboot使用(个人微信小程序用),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

主题 ActiveMQ Spring Boot 小程序开发

1.引入依赖

org.springframework.bootspring-boot-starter-parent1.5.3.RELEASEOrg.springframework.bootspring-boot-starter-activemq

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

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

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

①.添加依赖

org.apache.activemqactivemq-pool

②.修改配置文件

#服务端口,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中的

②.配置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代表具体的消息

相关文章

HashMap是Java中最常用的集合类框架,也是Java语言中非常典型...
在EffectiveJava中的第 36条中建议 用 EnumSet 替代位字段,...
介绍 注解是JDK1.5版本开始引入的一个特性,用于对代码进行说...
介绍 LinkedList同时实现了List接口和Deque接口,也就是说它...
介绍 TreeSet和TreeMap在Java里有着相同的实现,前者仅仅是对...
HashMap为什么线程不安全 put的不安全 由于多线程对HashMap进...