修改保证mq好使

parent 8cc4932c
......@@ -17,10 +17,12 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
/**
* //马甲包 xuran
*/
@Primary
@Configuration
public class LoanVestMQConfig {
@Value("${loanvest.rabbitmq.queue}")
......@@ -41,7 +43,7 @@ public class LoanVestMQConfig {
//@Value("${loanvest.rabbitmq.stateMsgQueue}")
//private String stateQueueName;
@Primary
@Bean(name = "vestFactory")
public ConnectionFactory vestFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
......@@ -56,30 +58,30 @@ public class LoanVestMQConfig {
connectionFactory.setPublisherConfirms(false);
return connectionFactory;
}
@Primary
@Bean(name= "loanVestAmqpAdmin")
public AmqpAdmin loanVestAdmin(@Qualifier("vestFactory") ConnectionFactory vestFactory) {
return new RabbitAdmin(vestFactory);
}
@Primary
@Bean(name = "loanVestExchange")
public FanoutExchange loanVestExchange() {
return new FanoutExchange(loanVestExchange);
}
@Primary
@Bean(name = "loanVestQueue")
public Queue loanVestQueue() {
return new Queue(queueName);
}
@Primary
@Bean(name = "loanVestBinding")
public Binding bindingLoanVest(@Qualifier("loanVestAmqpAdmin")AmqpAdmin loanVestAdmin, @Qualifier("loanVestQueue")Queue loanVestQueue, @Qualifier("loanVestExchange")FanoutExchange loanVestExchange) {
Binding binding = BindingBuilder.bind(loanVestQueue).to(loanVestExchange);
loanVestAdmin.declareBinding(binding);
return binding;
}
@Bean(name = "loanVestRabbitTemplate")
@Primary
@Bean(name = "rabbitTemplate")
public RabbitTemplate loanVestTemplate(@Qualifier("vestFactory") ConnectionFactory vestFactory) {
RabbitTemplate template = new RabbitTemplate(vestFactory);
template.setExchange(loanVestExchange);
......
......@@ -13,16 +13,17 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
/**
* Created by xuran on 2017/9/7.
*/
@Configuration
public class IRegisterMqConfig {
public class RegisterMqConfig {
@Value("${register.rabbitmq.queue}")
private String queueName;
@Value("${register.rabbitmq.exchange}")
private String loanVestExchange;
private String registerMqExchange;
@Value("${register.rabbitmq.connection.host}")
private String host;
......@@ -34,12 +35,11 @@ public class IRegisterMqConfig {
private String password;
@Value("${register.rabbitmq.connection.virtual-host}")
private String virtualHost;
//@Value("${loanvest.rabbitmq.stateMsgQueue}")
//private String stateQueueName;
@Bean(name = "registerMqFactory")
public ConnectionFactory vestFactory() {
public ConnectionFactory registerMqFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
connectionFactory.setChannelCacheSize(1024);
connectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CONNECTION);
......@@ -54,31 +54,32 @@ public class IRegisterMqConfig {
}
@Bean(name= "registerMqAmqpAdmin")
public AmqpAdmin loanVestAdmin(@Qualifier("registerMqFactory") ConnectionFactory vestFactory) {
return new RabbitAdmin(vestFactory);
public AmqpAdmin registerMqAmqpAdmin(@Qualifier("registerMqFactory") ConnectionFactory registerMqFactory) {
return new RabbitAdmin(registerMqFactory);
}
@Bean(name = "registerMqExchange")
public FanoutExchange loanVestExchange() {
return new FanoutExchange(loanVestExchange);
public FanoutExchange registerMqExchange() {
return new FanoutExchange(registerMqExchange);
}
@Bean(name = "registerMqQueue")
public Queue loanVestQueue() {
public Queue registerMqQueue() {
return new Queue(queueName);
}
@Bean(name = "registerMqBinding")
public Binding bindingLoanVest(@Qualifier("registerMqAmqpAdmin")AmqpAdmin loanVestAdmin, @Qualifier("registerMqQueue")Queue loanVestQueue, @Qualifier("registerMqExchange")FanoutExchange loanVestExchange) {
Binding binding = BindingBuilder.bind(loanVestQueue).to(loanVestExchange);
loanVestAdmin.declareBinding(binding);
public Binding registerMqBinding(@Qualifier("registerMqAmqpAdmin")AmqpAdmin registerMqAmqpAdmin, @Qualifier("registerMqQueue")Queue registerMqQueue, @Qualifier("registerMqExchange")FanoutExchange registerMqExchange) {
Binding binding = BindingBuilder.bind(registerMqQueue).to(registerMqExchange);
registerMqAmqpAdmin.declareBinding(binding);
return binding;
}
@Bean(name = "registerRabbitTemplate")
public RabbitTemplate loanVestTemplate(@Qualifier("registerMqFactory") ConnectionFactory vestFactory) {
RabbitTemplate template = new RabbitTemplate(vestFactory);
template.setExchange(loanVestExchange);
public RabbitTemplate registerTemplate(@Qualifier("registerMqFactory") ConnectionFactory registerMqFactory) {
RabbitTemplate template = new RabbitTemplate(registerMqFactory);
template.setExchange(registerMqExchange);
return template;
}
}
package cn.quantgroup.xyqb.service.mq.Impl;
import cn.quantgroup.xyqb.model.UserRegisterMqMessage;
import cn.quantgroup.xyqb.model.UserStatistics;
import cn.quantgroup.xyqb.service.mq.IRegisterMqService;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
......@@ -21,12 +20,12 @@ public class IRegisterMqServiceImpl implements IRegisterMqService {
private static final Logger LOGGER = LoggerFactory.getLogger(IRegisterMqServiceImpl.class);
@Autowired
@Qualifier(value = "registerRabbitTemplate")
RabbitTemplate registerRabbitTemplate;
@Qualifier("registerRabbitTemplate")
RabbitTemplate registerRabTemplate;
@Autowired
@Qualifier(value = "registerMqQueue")
Queue loanVestQueue;
Queue registerMqQueue;
......@@ -47,7 +46,7 @@ public class IRegisterMqServiceImpl implements IRegisterMqService {
LOGGER.info("广播用户注册消息,message={}",message);
String msg = JSONObject.toJSONString(message);
registerRabbitTemplate.convertAndSend(msg);
registerRabTemplate.convertAndSend(msg);
LOGGER.info("广播用户注册消息,message={}",msg);
}
......
package cn.quantgroup.xyqb.service.mq.Impl;
import cn.quantgroup.xyqb.Constants;;
import cn.quantgroup.xyqb.model.UserStatistics;
import cn.quantgroup.xyqb.service.mq.IVestService;
import com.alibaba.fastjson.JSONObject;
......@@ -13,6 +12,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
;
/**
* Created by xuran on 2017/6/21.
* 用户统计信息
......@@ -22,7 +23,7 @@ public class LoanVestMQServiceImpl implements IVestService {
private static final Logger LOGGER = LoggerFactory.getLogger(LoanVestMQServiceImpl.class);
@Autowired
@Qualifier(value = "loanVestRabbitTemplate")
@Qualifier("rabbitTemplate")
RabbitTemplate loanVestRabbitTemplate;
@Autowired
......
......@@ -30,8 +30,8 @@ public class MqUtils {
*/
public static void sendRegisterMessage(UserRegisterMqMessage message){
try {
IRegisterMqService mqService = ApplicationContextHolder.getBean("registerMqService");
mqService.send(message);
IRegisterMqService rService = ApplicationContextHolder.getBean("registerMqService");
rService.send(message);
} catch (Exception e) {
log.error("[MQUtils][MQUtils_exception]发送用户注册广播信息,message={},error={}",
message, e);
......
......@@ -110,7 +110,7 @@ loanvest.rabbitmq.connection.password=qatest
register.rabbitmq.connection.virtual-host=/user_register
register.rabbitmq.queue=user_register_queue
register.rabbitmq.exchange=user_register_exchange
register.rabbitmq.connection.host=192.168.4.46
register.rabbitmq.connection.host=192.168.4.153
register.rabbitmq.connection.port=5672
register.rabbitmq.connection.user=qa
register.rabbitmq.connection.password=qatest
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment