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



