springboot集成activemq(消費(fèi)者開(kāi)發(fā))

開(kāi)發(fā)步驟

gradle新增配置

compile('org.springframework.boot:spring-boot-starter-activemq')

配置文件配置

  • 包括jms和activemq
spring:
  jms:
    pub-sub-domain: true
  activemq:
    in-memory: true
    pool:
      enabled: false
    user: admin
    password: admin
    broker-url: tcp://127.0.0.1:61616
    concurrency: 10-100

代碼配置

  • 配置topic
package com.wonders.webservice.mq;

import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;

import javax.jms.Topic;


/**
 * 定義主題
 */
@Configuration
@EnableJms
public class ActiveMQConfiguration {

    @Bean
    public Topic topic1() {
        return new ActiveMQTopic("CDA_EHR_CSZM");
    }

    @Bean
    public Topic topic2() {
        return new ActiveMQTopic("JSZA_ZXDA");
    }

    @Bean
    public Topic topic3() {
        return new ActiveMQTopic("JSZA_SFJL");
    }


}
  • 具體接收處理
package com.wonders.webservice.mq;

import com.wonders.webservice.Thread.CszmConsumeThread;
import com.wonders.webservice.Thread.ExecutorProcessPool;
import com.wonders.webservice.repository.TbCdaEhr02Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

/**
 * 出生證明接收
 */
@Service
public class CszmConsumer {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    private static ExecutorProcessPool pool ;

    @Autowired
    private TbCdaEhr02Repository repository;


    @JmsListener(destination = "CDA_EHR_CSZM")
    public void receiveQueue(String text){

        pool = ExecutorProcessPool.getInstance();
        pool.execute(new CszmConsumeThread(text,repository));

    }

}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容