springboot集成activemq(消费者开发)

开发步骤

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));

    }

}

你可能感兴趣的:(springboot集成activemq(消费者开发))