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)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享2. jsp文件下載功能實(shí)現(xiàn)代碼3. asp.net core項(xiàng)目授權(quán)流程詳解4. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法5. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫(huà)特效6. XMLHTTP資料7. ASP常用日期格式化函數(shù) FormatDate()8. html中的form不提交(排除)某些input 原創(chuàng)9. CSS3中Transition屬性詳解以及示例分享10. ASP基礎(chǔ)入門(mén)第八篇(ASP內(nèi)建對(duì)象Application和Session)
