SpringBoot 整合 JMSTemplate的示例代碼
1.1 添加依賴
可以手動(dòng)在 SpringBoot 項(xiàng)目添加依賴,也可以在項(xiàng)目創(chuàng)建時(shí)選擇使用 ActiveMQ 5 自動(dòng)添加依賴。高版本 SpringBoot (2.0 以上) 在添加 activemq 連接池依賴啟動(dòng)時(shí)會(huì)報(bào) Error creating bean with name 'xxx': Unsatisfied dependency expressed through field 'jmsTemplate';
可以將 activemq 連接池?fù)Q成 jms 連接池解決。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId> </dependency> <!-- activemq 連接池 --> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> </dependency> <!-- jms 連接池 --> <dependency> <groupId>org.messaginghub</groupId> <artifactId>pooled-jms</artifactId> </dependency>
1.2 添加配置
spring: activemq: broker-url: tcp://127.0.0.1:61616 # 是否是內(nèi)存模式 in-memory: false pool: # 是否用 PooledConnectionFactory 代替普通的 ConnectionFactory enabled: true # 最大連接數(shù) max-connections: 10 # 連接空閑超時(shí) idle-timeout: 30000
1.3 測(cè)試類
/** * Created with IntelliJ IDEA. * * @author Demo_Null * @date 2020/8/5 * @description MQ 測(cè)試 */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest() public class MyMQTest { @Autowired private JmsTemplate jmsTemplate; @Test public void jms() { jmsTemplate.convertAndSend(new ActiveMQQueue("myTest"), "測(cè)試消息"); } }
1.4 運(yùn)行結(jié)果
到此這篇關(guān)于SpringBoot 整合 JMSTemplate的示例代碼的文章就介紹到這了,更多相關(guān)SpringBoot 整合 JMSTemplate內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 基于SpringBoot中activeMq的JmsTemplate的實(shí)例
- SpringBoot集成JmsTemplate(隊(duì)列模式和主題模式)及xml和JavaConfig配置詳解
- Spring Boot基于Active MQ實(shí)現(xiàn)整合JMS
- Spring整合Weblogic jms實(shí)例詳解
- 詳解spring boot整合JMS(ActiveMQ實(shí)現(xiàn))
- spring整合JMS實(shí)現(xiàn)同步收發(fā)消息(基于ActiveMQ的實(shí)現(xiàn))
- Spring-boot JMS 發(fā)送消息慢的解決方法
- Spring Jms 模塊案例講解
相關(guān)文章
springboot+Oauth2實(shí)現(xiàn)自定義AuthenticationManager和認(rèn)證path
本篇文章主要介紹了springboot+Oauth2實(shí)現(xiàn)自定義AuthenticationManager和認(rèn)證path,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09Java中Spock框架Mock對(duì)象的方法經(jīng)驗(yàn)總結(jié)
這篇文章主要分享了Spock框架Mock對(duì)象的方法經(jīng)驗(yàn)總結(jié),下文分享一些常用項(xiàng)目實(shí)戰(zhàn)說明以及代碼,供大家項(xiàng)目中參考,也具有一的的參考價(jià)值,需要的小伙伴可以參考一下2022-02-02IntelliJ IDEA本地代碼覆蓋后恢復(fù)原來的代碼圖解
今天小編就為大家分享一篇關(guān)于IntelliJ IDEA本地代碼覆蓋后恢復(fù)原來的代碼圖解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-10-10java統(tǒng)計(jì)字符串中指定元素出現(xiàn)次數(shù)方法
這篇文章主要介紹了java統(tǒng)計(jì)字符串中指定元素出現(xiàn)次數(shù)方法,需要的朋友可以參考下2015-12-12教你怎么用Java數(shù)組和鏈表實(shí)現(xiàn)棧
本篇文章為大家詳細(xì)介紹了怎么用Java數(shù)組和鏈表實(shí)現(xiàn)棧,文中有非常詳細(xì)的代碼示例及注釋,對(duì)正在學(xué)習(xí)java的小伙伴們很有幫助,需要的朋友可以參考下2021-05-05使用webmagic實(shí)現(xiàn)爬蟲程序示例分享
這篇文章主要介紹了使用webmagic實(shí)現(xiàn)爬蟲程序示例,需要的朋友可以參考下2014-04-04