栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

ActiveMq使用

ActiveMq使用

pom

        
            org.springframework.boot
            spring-boot-starter-activemq
        
        
            org.apache.activemq
            activemq-pool
            
        
        
        
            org.messaginghub
            pooled-jms
        

配置:

spring:
  activemq:
    broker-url: tcp://localhost:61616
    in-memory: false
    pool:
      enabled: true
      max-connections: 10
      time-between-expiration-check: 60000ms

使用:

private final OrderNewService orderNewService;
    private final Queue sendCardQueue;
    private final JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    public OSSPayController(@Qualifier("sendCard") Queue sendCardQueue, JmsMessagingTemplate jmsMessagingTemplate) {
        this.sendCardQueue = sendCardQueue;
        this.jmsMessagingTemplate = jmsMessagingTemplate;
    }




    private void sendCard(String orderSn, Integer merge) {
        try {
            SendCardDto sendCardDto = new SendCardDto(orderSn, merge);
            jmsMessagingTemplate.convertAndSend(sendCardQueue, JSON.toJSonString(sendCardDto));
        } catch (Exception e) {
            log.error("发送APK类型卡密", e);
        }
    }

import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.jms.Queue;

@Configuration
@Slf4j
public class ActiveMQConfig {
  
    public final static String ORDER_SEND_CARD_MQ_DESTINATION = MQ_PREFIX + "SendCard";
    

    @Bean("sendCard")
    public Queue sendCard() {
        return new ActiveMQQueue(ORDER_SEND_CARD_MQ_DESTINATION);
    }

    
   
}

监听:


import com.alibaba.fastjson.JSON;
import com.beust.jcommander.internal.Lists;
import xxxx.configure.ActiveMQConfig;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.beans.IntrospectionException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Component
@Slf4j
public class SendCardMQListener {

    @JmsListener(destination = ActiveMQConfig.ORDER_SEND_CARD_MQ_DESTINATION)
    public void receivedMessage(String message) {
        log.info("【发送APK类型卡密】"+message);
        
    }

  
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/752566.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号