记得上下班打卡 | git大法好,push需谨慎

Commit 35a8f441 authored by 胡佳晨's avatar 胡佳晨

stone 消费迁移

parent 37503dba
package com.liquidnet.service.consumer.base.config.stone;
import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.consumer.base.receiver.ConsumerCommonSQL0Receiver;
import com.liquidnet.service.consumer.base.receiver.stone.RedisInsertLogReceiver;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
import java.util.ArrayList;
import java.util.List;
@Configuration
public class ConsumerStoneLogsRedisStreamConfig extends RedisStreamConfig {
@Autowired
RedisInsertLogReceiver redisInsertLogReceiver;
@Autowired
StringRedisTemplate stringRedisTemplate;
@Bean
public List<Subscription> insertLogs(RedisConnectionFactory factory) {
List<Subscription> subscriptionList = new ArrayList<>();
MQConst.StoneQueue stream = MQConst.StoneQueue.STONE_INSERT_LOGS;
this.initStream(stringRedisTemplate, stream.getKey(), stream.getGroup());
for (int i = 0; i < 5; i++) {
StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer = this.buildStreamMessageListenerContainer(factory);
subscriptionList.add(listenerContainer.receiveAutoAck(
Consumer.from(stream.getGroup(), getConsumerName(stream.name() + i)),
StreamOffset.create(stream.getKey(), ReadOffset.lastConsumed()), redisInsertLogReceiver
));
listenerContainer.start();
}
return subscriptionList;
}
/* -------------------------------------------------------- | */
}
package com.liquidnet.service.consumer.base.config.stone;
import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.consumer.base.receiver.stone.RedisInsertOrderReceiver;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
import java.util.ArrayList;
import java.util.List;
@Configuration
public class ConsumerStoneOrderRedisStreamConfig extends RedisStreamConfig {
@Autowired
RedisInsertOrderReceiver redisInsertOrderReceiver;
@Autowired
StringRedisTemplate stringRedisTemplate;
@Bean
public List<Subscription> insertOrder(RedisConnectionFactory factory) {
List<Subscription> subscriptionList = new ArrayList<>();
MQConst.StoneQueue stream = MQConst.StoneQueue.STONE_ORDER_COUPON;
this.initStream(stringRedisTemplate, stream.getKey(), stream.getGroup());
for (int i = 0; i < 5; i++) {
StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer = this.buildStreamMessageListenerContainer(factory);
subscriptionList.add(listenerContainer.receiveAutoAck(
Consumer.from(stream.getGroup(), getConsumerName(stream.name() + i)),
StreamOffset.create(stream.getKey(), ReadOffset.lastConsumed()), redisInsertOrderReceiver
));
listenerContainer.start();
}
return subscriptionList;
}
/* -------------------------------------------------------- | */
}
package com.liquidnet.service.consumer.base.config.stone;
import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.consumer.base.receiver.stone.RedisInsertUserReceiver;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
import java.util.ArrayList;
import java.util.List;
@Configuration
public class ConsumerStoneUserRedisStreamConfig extends RedisStreamConfig {
@Autowired
RedisInsertUserReceiver redisInsertUserReceiver;
@Autowired
StringRedisTemplate stringRedisTemplate;
@Bean
public List<Subscription> insertUser(RedisConnectionFactory factory) {
List<Subscription> subscriptionList = new ArrayList<>();
MQConst.StoneQueue stream = MQConst.StoneQueue.STONE_INSERT_USER;
this.initStream(stringRedisTemplate, stream.getKey(), stream.getGroup());
for (int i = 0; i < 5; i++) {
StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer = this.buildStreamMessageListenerContainer(factory);
subscriptionList.add(listenerContainer.receiveAutoAck(
Consumer.from(stream.getGroup(), getConsumerName(stream.name() + i)),
StreamOffset.create(stream.getKey(), ReadOffset.lastConsumed()), redisInsertUserReceiver
));
listenerContainer.start();
}
return subscriptionList;
}
/* -------------------------------------------------------- | */
}
package com.liquidnet.service.consumer.base.receiver.stone;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.consumer.base.receiver.AbstractSqlRedisReceiver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class RedisInsertLogReceiver extends AbstractSqlRedisReceiver {
@Override
protected String getRedisStreamKey() {
return MQConst.StoneQueue.STONE_INSERT_LOGS.getKey();
}
@Override
protected String getRedisStreamGroup() {
return MQConst.StoneQueue.STONE_INSERT_LOGS.getGroup();
}
}
package com.liquidnet.service.consumer.base.receiver.stone;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.consumer.base.receiver.AbstractSqlRedisReceiver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class RedisInsertOrderReceiver extends AbstractSqlRedisReceiver {
@Override
protected String getRedisStreamKey() {
return MQConst.StoneQueue.STONE_ORDER_COUPON.getKey();
}
@Override
protected String getRedisStreamGroup() {
return MQConst.StoneQueue.STONE_ORDER_COUPON.getGroup();
}
}
package com.liquidnet.service.consumer.base.receiver.stone;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.consumer.base.receiver.AbstractSqlRedisReceiver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class RedisInsertUserReceiver extends AbstractSqlRedisReceiver {
@Override
protected String getRedisStreamKey() {
return MQConst.StoneQueue.STONE_INSERT_USER.getKey();
}
@Override
protected String getRedisStreamGroup() {
return MQConst.StoneQueue.STONE_INSERT_USER.getGroup();
}
}
package com.liquidnet.servce.consumer.stone.service.config;
import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
import com.liquidnet.servce.consumer.stone.service.receiver.RedisInsertLogReceiver;
import com.liquidnet.service.base.constant.MQConst;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
@Configuration
public class ConsumerStoneLogsRedisStreamConfig extends RedisStreamConfig {
@Autowired
RedisInsertLogReceiver redisInsertLogReceiver;
/**
* 缺票登记
*
* @param listenerContainer
* @param t
* @return
*/
private Subscription receiveSqlStoneInsertLog(StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer, int t) {
return listenerContainer.receiveAutoAck(Consumer.from(MQConst.StoneQueue.STONE_INSERT_LOGS.getGroup(), getConsumerName(MQConst.StoneQueue.STONE_INSERT_LOGS.name() + t)),
StreamOffset.create(MQConst.StoneQueue.STONE_INSERT_LOGS.getKey(), ReadOffset.lastConsumed()), redisInsertLogReceiver);
}
/* —————————————————————————— | —————————————————————————— | —————————————————————————— */
/* -------------------------------------------------------- | 缺票登记 */
@Bean
public Subscription subscriptionSqlStoneInsertLog0(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlStoneInsertLog(listenerContainer, 0);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionSqlStoneInsertLog1(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlStoneInsertLog(listenerContainer, 1);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionSqlStoneInsertLog2(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlStoneInsertLog(listenerContainer, 2);
listenerContainer.start();
return subscription;
}
/* -------------------------------------------------------- | */
}
//package com.liquidnet.servce.consumer.stone.service.config;
//
//import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
//import com.liquidnet.servce.consumer.stone.service.receiver.RedisInsertLogReceiver;
//import com.liquidnet.service.base.constant.MQConst;
//import lombok.var;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.connection.stream.Consumer;
//import org.springframework.data.redis.connection.stream.MapRecord;
//import org.springframework.data.redis.connection.stream.ReadOffset;
//import org.springframework.data.redis.connection.stream.StreamOffset;
//import org.springframework.data.redis.stream.StreamMessageListenerContainer;
//import org.springframework.data.redis.stream.Subscription;
//
//@Configuration
//public class ConsumerStoneLogsRedisStreamConfig extends RedisStreamConfig {
// @Autowired
// RedisInsertLogReceiver redisInsertLogReceiver;
//
// /**
// * 缺票登记
// *
// * @param listenerContainer
// * @param t
// * @return
// */
// private Subscription receiveSqlStoneInsertLog(StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer, int t) {
// return listenerContainer.receiveAutoAck(Consumer.from(MQConst.StoneQueue.STONE_INSERT_LOGS.getGroup(), getConsumerName(MQConst.StoneQueue.STONE_INSERT_LOGS.name() + t)),
// StreamOffset.create(MQConst.StoneQueue.STONE_INSERT_LOGS.getKey(), ReadOffset.lastConsumed()), redisInsertLogReceiver);
// }
//
// /* —————————————————————————— | —————————————————————————— | —————————————————————————— */
//
// /* -------------------------------------------------------- | 缺票登记 */
//
// @Bean
// public Subscription subscriptionSqlStoneInsertLog0(RedisConnectionFactory factory) {
// var listenerContainer = this.buildStreamMessageListenerContainer(factory);
// var subscription = receiveSqlStoneInsertLog(listenerContainer, 0);
// listenerContainer.start();
// return subscription;
// }
//
// @Bean
// public Subscription subscriptionSqlStoneInsertLog1(RedisConnectionFactory factory) {
// var listenerContainer = this.buildStreamMessageListenerContainer(factory);
// var subscription = receiveSqlStoneInsertLog(listenerContainer, 1);
// listenerContainer.start();
// return subscription;
// }
//
// @Bean
// public Subscription subscriptionSqlStoneInsertLog2(RedisConnectionFactory factory) {
// var listenerContainer = this.buildStreamMessageListenerContainer(factory);
// var subscription = receiveSqlStoneInsertLog(listenerContainer, 2);
// listenerContainer.start();
// return subscription;
// }
//
// /* -------------------------------------------------------- | */
//}
package com.liquidnet.servce.consumer.stone.service.config;
import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
import com.liquidnet.servce.consumer.stone.service.receiver.RedisInsertOrderReceiver;
import com.liquidnet.service.base.constant.MQConst;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
@Configuration
public class ConsumerStoneOrderRedisStreamConfig extends RedisStreamConfig {
@Autowired
RedisInsertOrderReceiver redisInsertOrderReceiver;
/**
* 缺票登记
*
* @param listenerContainer
* @param t
* @return
*/
private Subscription receiveSqlStoneInsertOrder(StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer, int t) {
return listenerContainer.receiveAutoAck(Consumer.from(MQConst.StoneQueue.STONE_ORDER_COUPON.getGroup(), getConsumerName(MQConst.StoneQueue.STONE_ORDER_COUPON.name() + t)),
StreamOffset.create(MQConst.StoneQueue.STONE_ORDER_COUPON.getKey(), ReadOffset.lastConsumed()), redisInsertOrderReceiver);
}
/* —————————————————————————— | —————————————————————————— | —————————————————————————— */
/* -------------------------------------------------------- | 缺票登记 */
@Bean
public Subscription subscriptionSqlStoneInsertOrder0(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlStoneInsertOrder(listenerContainer, 0);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionSqlStoneInsertOrder1(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlStoneInsertOrder(listenerContainer, 1);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionSqlStoneInsertOrder2(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlStoneInsertOrder(listenerContainer, 2);
listenerContainer.start();
return subscription;
}
/* -------------------------------------------------------- | */
}
//package com.liquidnet.servce.consumer.stone.service.config;
//
//import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
//import com.liquidnet.servce.consumer.stone.service.receiver.RedisInsertOrderReceiver;
//import com.liquidnet.service.base.constant.MQConst;
//import lombok.var;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.connection.stream.Consumer;
//import org.springframework.data.redis.connection.stream.MapRecord;
//import org.springframework.data.redis.connection.stream.ReadOffset;
//import org.springframework.data.redis.connection.stream.StreamOffset;
//import org.springframework.data.redis.stream.StreamMessageListenerContainer;
//import org.springframework.data.redis.stream.Subscription;
//
//@Configuration
//public class ConsumerStoneOrderRedisStreamConfig extends RedisStreamConfig {
// @Autowired
// RedisInsertOrderReceiver redisInsertOrderReceiver;
//
// /**
// * 缺票登记
// *
// * @param listenerContainer
// * @param t
// * @return
// */
// private Subscription receiveSqlStoneInsertOrder(StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer, int t) {
// return listenerContainer.receiveAutoAck(Consumer.from(MQConst.StoneQueue.STONE_ORDER_COUPON.getGroup(), getConsumerName(MQConst.StoneQueue.STONE_ORDER_COUPON.name() + t)),
// StreamOffset.create(MQConst.StoneQueue.STONE_ORDER_COUPON.getKey(), ReadOffset.lastConsumed()), redisInsertOrderReceiver);
// }
//
// /* —————————————————————————— | —————————————————————————— | —————————————————————————— */
//
// /* -------------------------------------------------------- | 缺票登记 */
//
// @Bean
// public Subscription subscriptionSqlStoneInsertOrder0(RedisConnectionFactory factory) {
// var listenerContainer = this.buildStreamMessageListenerContainer(factory);
// var subscription = receiveSqlStoneInsertOrder(listenerContainer, 0);
// listenerContainer.start();
// return subscription;
// }
//
// @Bean
// public Subscription subscriptionSqlStoneInsertOrder1(RedisConnectionFactory factory) {
// var listenerContainer = this.buildStreamMessageListenerContainer(factory);
// var subscription = receiveSqlStoneInsertOrder(listenerContainer, 1);
// listenerContainer.start();
// return subscription;
// }
//
// @Bean
// public Subscription subscriptionSqlStoneInsertOrder2(RedisConnectionFactory factory) {
// var listenerContainer = this.buildStreamMessageListenerContainer(factory);
// var subscription = receiveSqlStoneInsertOrder(listenerContainer, 2);
// listenerContainer.start();
// return subscription;
// }
//
// /* -------------------------------------------------------- | */
//}
package com.liquidnet.servce.consumer.stone.service.config;
import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
import com.liquidnet.servce.consumer.stone.service.receiver.RedisInsertUserReceiver;
import com.liquidnet.service.base.constant.MQConst;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.data.redis.stream.Subscription;
@Configuration
public class ConsumerStoneUserRedisStreamConfig extends RedisStreamConfig {
@Autowired
RedisInsertUserReceiver redisInsertUserReceiver;
/**
* 缺票登记
*
* @param listenerContainer
* @param t
* @return
*/
private Subscription receiveSqlStoneInsertUser(StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer, int t) {
return listenerContainer.receiveAutoAck(Consumer.from(MQConst.StoneQueue.STONE_INSERT_USER.getGroup(), getConsumerName(MQConst.StoneQueue.STONE_INSERT_USER.name() + t)),
StreamOffset.create(MQConst.StoneQueue.STONE_INSERT_USER.getKey(), ReadOffset.lastConsumed()), redisInsertUserReceiver);
}
/* —————————————————————————— | —————————————————————————— | —————————————————————————— */
/* -------------------------------------------------------- | 缺票登记 */
@Bean
public Subscription subscriptionSqlStoneInsertUser0(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlStoneInsertUser(listenerContainer, 0);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionSqlStoneInsertUser1(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlStoneInsertUser(listenerContainer, 1);
listenerContainer.start();
return subscription;
}
@Bean
public Subscription subscriptionSqlStoneInsertUser2(RedisConnectionFactory factory) {
var listenerContainer = this.buildStreamMessageListenerContainer(factory);
var subscription = receiveSqlStoneInsertUser(listenerContainer, 2);
listenerContainer.start();
return subscription;
}
/* -------------------------------------------------------- | */
}
//package com.liquidnet.servce.consumer.stone.service.config;
//
//import com.liquidnet.common.cache.redis.config.RedisStreamConfig;
//import com.liquidnet.servce.consumer.stone.service.receiver.RedisInsertUserReceiver;
//import com.liquidnet.service.base.constant.MQConst;
//import lombok.var;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.connection.stream.Consumer;
//import org.springframework.data.redis.connection.stream.MapRecord;
//import org.springframework.data.redis.connection.stream.ReadOffset;
//import org.springframework.data.redis.connection.stream.StreamOffset;
//import org.springframework.data.redis.stream.StreamMessageListenerContainer;
//import org.springframework.data.redis.stream.Subscription;
//
//@Configuration
//public class ConsumerStoneUserRedisStreamConfig extends RedisStreamConfig {
// @Autowired
// RedisInsertUserReceiver redisInsertUserReceiver;
//
// /**
// * 缺票登记
// *
// * @param listenerContainer
// * @param t
// * @return
// */
// private Subscription receiveSqlStoneInsertUser(StreamMessageListenerContainer<String, MapRecord<String, String, String>> listenerContainer, int t) {
// return listenerContainer.receiveAutoAck(Consumer.from(MQConst.StoneQueue.STONE_INSERT_USER.getGroup(), getConsumerName(MQConst.StoneQueue.STONE_INSERT_USER.name() + t)),
// StreamOffset.create(MQConst.StoneQueue.STONE_INSERT_USER.getKey(), ReadOffset.lastConsumed()), redisInsertUserReceiver);
// }
//
// /* —————————————————————————— | —————————————————————————— | —————————————————————————— */
//
// /* -------------------------------------------------------- | 缺票登记 */
//
// @Bean
// public Subscription subscriptionSqlStoneInsertUser0(RedisConnectionFactory factory) {
// var listenerContainer = this.buildStreamMessageListenerContainer(factory);
// var subscription = receiveSqlStoneInsertUser(listenerContainer, 0);
// listenerContainer.start();
// return subscription;
// }
//
// @Bean
// public Subscription subscriptionSqlStoneInsertUser1(RedisConnectionFactory factory) {
// var listenerContainer = this.buildStreamMessageListenerContainer(factory);
// var subscription = receiveSqlStoneInsertUser(listenerContainer, 1);
// listenerContainer.start();
// return subscription;
// }
//
// @Bean
// public Subscription subscriptionSqlStoneInsertUser2(RedisConnectionFactory factory) {
// var listenerContainer = this.buildStreamMessageListenerContainer(factory);
// var subscription = receiveSqlStoneInsertUser(listenerContainer, 2);
// listenerContainer.start();
// return subscription;
// }
//
// /* -------------------------------------------------------- | */
//}
package com.liquidnet.servce.consumer.stone.service.receiver;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.servce.consumer.stone.service.IBaseDao;
import com.liquidnet.service.base.SqlMapping;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.stream.StreamListener;
import java.util.HashMap;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @class: AbstractRedisReceiver
* @Package com.liquidnet.service.consumer.dragon.receiver
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/22 20:28
*/
@Slf4j
public abstract class AbstractRedisReceiver implements StreamListener<String, MapRecord<String, String, String>> {
@Autowired
private IBaseDao baseDao;
@Autowired
StringRedisTemplate stringRedisTemplate;
@Override
public void onMessage(MapRecord<String, String, String> message) {
String redisStreamKey = this.getRedisStreamKey();
log.debug("CONSUMER MSG[streamKey:{},messageId:{},stream:{},body:{}]", redisStreamKey, message.getId(), message.getStream(), message.getValue());
boolean result = this.consumerMessageHandler(message.getValue().get("message"));
log.info("CONSUMER MSG RESULT:{} ==> [{}]MESSAGE_ID:{}", result, redisStreamKey, message.getId());
try {
stringRedisTemplate.opsForStream().acknowledge(getRedisStreamGroup(), message);
} catch (Exception e) {
log.error("#CONSUMER MSG EX_ACK ==> [{}]RESULT:{},MESSAGE:{}", this.getRedisStreamKey(), result, message.getValue(), e);
}
try {
stringRedisTemplate.opsForStream().delete(this.getRedisStreamKey(), message.getId());
} catch (Exception e) {
log.error("#CONSUMER MSG EX_DEL ==> [{}]RESULT:{},MESSAGE:{}", this.getRedisStreamKey(), result, message.getValue(), e);
}
}
private boolean consumerMessageHandler(String msg) {
boolean aBoolean = false;
try {
SqlMapping.SqlMessage sqlMessage = JsonUtils.fromJson(msg, SqlMapping.SqlMessage.class);
aBoolean = null == sqlMessage || baseDao.batchSqls(sqlMessage.getSqls(), sqlMessage.getArgs());
} catch (Exception e) {
log.error("CONSUMER MSG EX_HANDLE ==> [{}]:{}", this.getRedisStreamKey(), msg, e);
} finally {
if (!aBoolean) {
HashMap<String, String> map = CollectionUtil.mapStringString();
map.put("message", msg);
stringRedisTemplate.opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(this.getRedisStreamKey()));
}
}
return aBoolean;
}
//package com.liquidnet.servce.consumer.stone.service.receiver;
//
//import com.liquidnet.commons.lang.util.CollectionUtil;
//import com.liquidnet.commons.lang.util.JsonUtils;
//import com.liquidnet.servce.consumer.stone.service.IBaseDao;
//import com.liquidnet.service.base.SqlMapping;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.connection.stream.MapRecord;
//import org.springframework.data.redis.connection.stream.StreamRecords;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.data.redis.stream.StreamListener;
//
//import java.util.HashMap;
//
///**
// * @author AnJiabin <anjiabin@zhengzai.tv>
// * @version V1.0
// * @class: AbstractRedisReceiver
// * @Package com.liquidnet.service.consumer.dragon.receiver
// * @Copyright: LightNet @ Copyright (c) 2021
// * @date 2021/7/22 20:28
// */
//@Slf4j
//public abstract class AbstractRedisReceiver implements StreamListener<String, MapRecord<String, String, String>> {
// @Autowired
// private IBaseDao baseDao;
// @Autowired
// StringRedisTemplate stringRedisTemplate;
//
// @Override
// public void onMessage(MapRecord<String, String, String> message) {
// log.info("接受到来自redis PAY key:{} 的消息",getRedisStreamKey());
// log.info("message id " + message.getId());
// log.info("stream " + message.getStream());
// log.info("body " + message.getValue());
// boolean result = this.consumerSqlDaoHandler(message.getValue().get("message"));
// String redisStreamKey = this.getRedisStreamKey();
// log.debug("CONSUMER MSG[streamKey:{},messageId:{},stream:{},body:{}]", redisStreamKey, message.getId(), message.getStream(), message.getValue());
// boolean result = this.consumerMessageHandler(message.getValue().get("message"));
// log.info("CONSUMER MSG RESULT:{} ==> [{}]MESSAGE_ID:{}", result, redisStreamKey, message.getId());
//
//// if(result){
// // 消费成功确认,消息删除和消息确认是一个事务
// log.info("consumer success delete message messageId:{} ",message.getId());
// try {
//// stringRedisTemplate.multi();
// stringRedisTemplate.opsForStream().acknowledge(getRedisStreamGroup(), message);
// stringRedisTemplate.opsForStream().delete(this.getRedisStreamKey(), message.getId());
//// stringRedisTemplate.exec();
// } catch (Exception e) {
// e.printStackTrace();
// log.error("delete redis queue message error messageId:{} errMsg:{}",message.getId(),e.getMessage());
// }finally {
// log.error("#CONSUMER MSG EX_ACK ==> [{}]RESULT:{},MESSAGE:{}", this.getRedisStreamKey(), result, message.getValue(), e);
// }
// try {
// stringRedisTemplate.opsForStream().acknowledge(getRedisStreamGroup(), message);
// stringRedisTemplate.opsForStream().delete(this.getRedisStreamKey(), message.getId());
// } catch (Exception e) {
// log.error("error: {}",e);
// log.error("#CONSUMER MSG EX_DEL ==> [{}]RESULT:{},MESSAGE:{}", this.getRedisStreamKey(), result, message.getValue(), e);
// }
// }
//// }
// }
//
// private boolean consumerSqlDaoHandler(String msg) {
// private boolean consumerMessageHandler(String msg) {
// boolean aBoolean = false;
// try {
// SqlMapping.SqlMessage sqlMessage = JsonUtils.fromJson(msg, SqlMapping.SqlMessage.class);
// log.debug("CONSUMER SQL ==> Preparing:{}", JsonUtils.toJson(sqlMessage.getSqls()));
// log.debug("CONSUMER SQL ==> Parameters:{}", JsonUtils.toJson(sqlMessage.getArgs()));
// Boolean rstBatchSqls = baseDao.batchSqls(sqlMessage.getSqls(), sqlMessage.getArgs());
// log.debug("CONSUMER SQL result of execution:{}", rstBatchSqls);
// if (rstBatchSqls) {
// return true;
// }else{
// sendMySqlRedis(msg);
// }
// aBoolean = null == sqlMessage || baseDao.batchSqls(sqlMessage.getSqls(), sqlMessage.getArgs());
// } catch (Exception e) {
// e.printStackTrace();
// log.error("CONSUMER SQL Exception error:{}", e);
// }
// return false;
// }
//
// /**
// * 给 REDIS 队列发送消息 数据库相关
// *
// * @param msg 接收到的内容
// * @return
// */
// private boolean sendMySqlRedis(String msg) {
// try {
// HashMap<String, String> map = new HashMap<>();
// log.error("CONSUMER MSG EX_HANDLE ==> [{}]:{}", this.getRedisStreamKey(), msg, e);
// } finally {
// if (!aBoolean) {
// HashMap<String, String> map = CollectionUtil.mapStringString();
// map.put("message", msg);
// MapRecord<String, String, String> record = StreamRecords.mapBacked(map).withStreamKey(getRedisStreamKey());
// stringRedisTemplate.opsForStream().add(record);
// return true;
// } catch (Exception e) {
// e.printStackTrace();
// return false;
// stringRedisTemplate.opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(this.getRedisStreamKey()));
// }
// }
protected abstract String getRedisStreamKey();
protected abstract String getRedisStreamGroup();
}
// return aBoolean;
// }
//
//// @Override
//// public void onMessage(MapRecord<String, String, String> message) {
//// log.info("接受到来自redis PAY key:{} 的消息",getRedisStreamKey());
//// log.info("message id " + message.getId());
//// log.info("stream " + message.getStream());
//// log.info("body " + message.getValue());
//// boolean result = this.consumerSqlDaoHandler(message.getValue().get("message"));
////
////// if(result){
//// // 消费成功确认,消息删除和消息确认是一个事务
//// log.info("consumer success delete message messageId:{} ",message.getId());
//// try {
////// stringRedisTemplate.multi();
//// stringRedisTemplate.opsForStream().acknowledge(getRedisStreamGroup(), message);
//// stringRedisTemplate.opsForStream().delete(this.getRedisStreamKey(), message.getId());
////// stringRedisTemplate.exec();
//// } catch (Exception e) {
//// e.printStackTrace();
//// log.error("delete redis queue message error messageId:{} errMsg:{}",message.getId(),e.getMessage());
//// }finally {
//// try {
//// stringRedisTemplate.opsForStream().acknowledge(getRedisStreamGroup(), message);
//// stringRedisTemplate.opsForStream().delete(this.getRedisStreamKey(), message.getId());
//// } catch (Exception e) {
//// log.error("error: {}",e);
//// }
//// }
////// }
//// }
////
//// private boolean consumerSqlDaoHandler(String msg) {
//// try {
//// SqlMapping.SqlMessage sqlMessage = JsonUtils.fromJson(msg, SqlMapping.SqlMessage.class);
//// log.debug("CONSUMER SQL ==> Preparing:{}", JsonUtils.toJson(sqlMessage.getSqls()));
//// log.debug("CONSUMER SQL ==> Parameters:{}", JsonUtils.toJson(sqlMessage.getArgs()));
//// Boolean rstBatchSqls = baseDao.batchSqls(sqlMessage.getSqls(), sqlMessage.getArgs());
//// log.debug("CONSUMER SQL result of execution:{}", rstBatchSqls);
//// if (rstBatchSqls) {
//// return true;
//// }else{
//// sendMySqlRedis(msg);
//// }
//// } catch (Exception e) {
//// e.printStackTrace();
//// log.error("CONSUMER SQL Exception error:{}", e);
//// }
//// return false;
//// }
////
//// /**
//// * 给 REDIS 队列发送消息 数据库相关
//// *
//// * @param msg 接收到的内容
//// * @return
//// */
//// private boolean sendMySqlRedis(String msg) {
//// try {
//// HashMap<String, String> map = new HashMap<>();
//// map.put("message", msg);
//// MapRecord<String, String, String> record = StreamRecords.mapBacked(map).withStreamKey(getRedisStreamKey());
//// stringRedisTemplate.opsForStream().add(record);
//// return true;
//// } catch (Exception e) {
//// e.printStackTrace();
//// return false;
//// }
//// }
//
// protected abstract String getRedisStreamKey();
//
// protected abstract String getRedisStreamGroup();
//}
package com.liquidnet.servce.consumer.stone.service.receiver;
import com.liquidnet.service.base.constant.MQConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class RedisInsertLogReceiver extends AbstractRedisReceiver {
@Override
protected String getRedisStreamKey() {
return MQConst.StoneQueue.STONE_INSERT_LOGS.getKey();
}
@Override
protected String getRedisStreamGroup() {
return MQConst.StoneQueue.STONE_INSERT_LOGS.getGroup();
}
}
//package com.liquidnet.servce.consumer.stone.service.receiver;
//
//import com.liquidnet.service.base.constant.MQConst;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//@Slf4j
//@Component
//public class RedisInsertLogReceiver extends AbstractRedisReceiver {
//
// @Override
// protected String getRedisStreamKey() {
// return MQConst.StoneQueue.STONE_INSERT_LOGS.getKey();
// }
//
// @Override
// protected String getRedisStreamGroup() {
// return MQConst.StoneQueue.STONE_INSERT_LOGS.getGroup();
// }
//}
package com.liquidnet.servce.consumer.stone.service.receiver;
import com.liquidnet.service.base.constant.MQConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class RedisInsertOrderReceiver extends AbstractRedisReceiver {
@Override
protected String getRedisStreamKey() {
return MQConst.StoneQueue.STONE_ORDER_COUPON.getKey();
}
@Override
protected String getRedisStreamGroup() {
return MQConst.StoneQueue.STONE_ORDER_COUPON.getGroup();
}
}
//package com.liquidnet.servce.consumer.stone.service.receiver;
//
//import com.liquidnet.service.base.constant.MQConst;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//@Slf4j
//@Component
//public class RedisInsertOrderReceiver extends AbstractRedisReceiver {
//
// @Override
// protected String getRedisStreamKey() {
// return MQConst.StoneQueue.STONE_ORDER_COUPON.getKey();
// }
//
// @Override
// protected String getRedisStreamGroup() {
// return MQConst.StoneQueue.STONE_ORDER_COUPON.getGroup();
// }
//}
package com.liquidnet.servce.consumer.stone.service.receiver;
import com.liquidnet.service.base.constant.MQConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class RedisInsertUserReceiver extends AbstractRedisReceiver {
@Override
protected String getRedisStreamKey() {
return MQConst.StoneQueue.STONE_INSERT_USER.getKey();
}
@Override
protected String getRedisStreamGroup() {
return MQConst.StoneQueue.STONE_INSERT_USER.getGroup();
}
}
//package com.liquidnet.servce.consumer.stone.service.receiver;
//
//import com.liquidnet.service.base.constant.MQConst;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//@Slf4j
//@Component
//public class RedisInsertUserReceiver extends AbstractRedisReceiver {
//
// @Override
// protected String getRedisStreamKey() {
// return MQConst.StoneQueue.STONE_INSERT_USER.getKey();
// }
//
// @Override
// protected String getRedisStreamGroup() {
// return MQConst.StoneQueue.STONE_INSERT_USER.getGroup();
// }
//}
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