Commit ffc1f607 by 共享中心代码生成

Merge branch 'new-strut' into 'master'

New strut

See merge request !3
parents 8ceb3696 1f9b3cfb
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-hbase-starter</artifactId> <artifactId>matrix-bigdata-hbase-starter</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
......
package com.secoo.mall;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@Slf4j
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
log.info("matrix-bigdata-demo SpringBoot Start Success");
}
}
package com.secoo.mall.hbase;
import com.secoo.mall.hbase.spring.boot.autoconfigure.HbaseTemplate;
import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 简单 HBase 操作
*
* @author zhanghao
* @date 2020-03-1719:20
*/
@Component
@Slf4j
public class SimpleHBase implements InitializingBean {
@Resource
private HbaseTemplate hbaseTemplate;
private static final String TABLE_NAME = "mytable";
private static final String CF_DEFAULT = "cf";
public static final byte[] QUALIFIER = "col1".getBytes();
private static final byte[] ROWKEY = "rowkey1".getBytes();
/**
* 建表
*
* @throws IOException
*/
public void createTable() throws IOException {
List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<ColumnFamilyDescriptor>();
columnFamilyDescriptors.add(ColumnFamilyDescriptorBuilder.of(CF_DEFAULT));
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TableName.valueOf(TABLE_NAME))
.setColumnFamilies(columnFamilyDescriptors).build();
log.info("Creating table. ");
Admin admin = hbaseTemplate.getConnection().getAdmin();
if(!admin.tableExists(TableName.valueOf(TABLE_NAME))){
admin.createTable(tableDescriptor);
}
log.info(" Done.");
}
/**
* 保存更新
*/
public void put() {
Put put = new Put(ROWKEY);
put.addColumn(CF_DEFAULT.getBytes(), QUALIFIER, "this is value".getBytes());
hbaseTemplate.saveOrUpdate(TABLE_NAME, put);
}
/**
* 查询
*/
public void get() {
hbaseTemplate.get(TABLE_NAME, "rowkey1", CF_DEFAULT, (result, rowNum) -> {
Map<String, String> map = new HashMap();
for (Cell cell : result.rawCells()) {
log.info("行健: " + new String(CellUtil.cloneRow(cell)));
log.info("列簇: " + new String(CellUtil.cloneFamily(cell)));
log.info("列: " + new String(CellUtil.cloneQualifier(cell)));
log.info("值: " + new String(CellUtil.cloneValue(cell)));
log.info("时间戳: " + cell.getTimestamp());
map.put(new String(CellUtil.cloneQualifier(cell)), new String(CellUtil.cloneValue(cell)));
}
return map;
});
}
@Override
public void afterPropertiesSet() throws Exception {
// createTable();
// put();
get();
}
}
spring:
application:
name: matrix-bigdata-demo
server:
port: 6080
hbase:
zookeeper:
quorum: 10.4.3.236:2181,10.4.3.237:2181,10.4.3.235:2181
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample-redis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-redis-biz</artifactId>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample-redis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-redis-starter</artifactId>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-redis</artifactId>
<packaging>pom</packaging>
<modules>
<module>matrix-sample-redis-starter</module>
<module>matrix-sample-redis-biz</module>
</modules>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample-rocketmq</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-rocketmq-biz</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-util</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.secoo.rocketmq.bean;
import lombok.Data;
import java.io.Serializable;
@Data
public class User implements Serializable {
private Long id;
private String name;
}
package com.secoo.rocketmq.service;
import com.secoo.rocketmq.bean.User;
import org.springframework.stereotype.Service;
@Service
public class UserService {
public User create(User user) {
//实际业务操作
return user;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample-rocketmq</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-rocketmq-spring</artifactId>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mq-rocketmq-client</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-rocketmq-biz</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.secoo.mall.rocketmq;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring/*.xml" })
public class Main {
public static void main(String[] args) {
}
}
package com.secoo.mall.rocketmq.config;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ConsumerConfig {
}
package com.secoo.mall.rocketmq.consumer;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.secoo.mall.rocketmq.PushRocketMQConsumer;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.common.message.MessageExt;
import java.util.List;
/**
*1.PushRocketMQConsumer 默认消费模式都是集群消费模式,即一条消息只能被一个消费者消费。
*2.push是broker主动去向consumer推送消息,他们之间只需要保持长连接即可。pull是consumer主动去向broker拉取消息。
* 相对来讲push更便于操作,pull控制比较繁琐,不再提供示例。推荐使用push模式。
*
*/
@Slf4j
public class SimplePushConsumer extends PushRocketMQConsumer {
@Override
public ConsumeConcurrentlyStatus doService(List<MessageExt> msgs) {
for(MessageExt msg : msgs){
try {
JSONObject jsonObject = JSON.parseObject(new String(msg.getBody(), "UTF-8"));
log.info("OrderStatusChangeConsumer jsonObject:{} ", jsonObject);
}catch (Exception e){
log.error("Consumer fail:" + msg + "," + e.getMessage(), e);
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
}
package com.secoo.mall.rocketmq.producer;
import com.secoo.mall.rocketmq.PushRocketMQProducer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
@Component
public class SimplePushProducer extends PushRocketMQProducer {
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<bean id="simplePushConsumer" class="com.secoo.mall.rocketmq.consumer.SimplePushConsumer">
<property name="namesrvAddr" value="${rocketmq.namesrvAddr}"/>
<property name="topic" value="simple-push-topic"></property>
<property name="consumerGroup" value="simple-group"/>
<property name="messageModel" value="CLUSTERING"/>
</bean>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<bean id="promotionPriceConcumer" class="com.secoo.mall.rocketmq.producer.SimplePushProducer">
<property name="namesrvAddr" value="${rocketmq.namesrvAddr}"/>
<property name="topic" value="simple-push-topic"/>
</bean>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample-rocketmq</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-rocketmq-springboot</artifactId>
<version>1.0.1</version>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mq-rocketmq-starter</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-rocketmq-biz</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.secoo.rocketmq;
import com.secoo.rocketmq.bean.User;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.messaging.support.MessageBuilder;
import javax.annotation.Resource;
@SpringBootApplication
public class RoketMqSampleApplication implements ApplicationRunner {
@Resource
private RocketMQTemplate template;
private String topicName= "roketmq-simple-springboot";
public static void main(String[] args) {
new SpringApplicationBuilder(RoketMqSampleApplication.class).run(args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
User user = new User();
user.setId(1L);
user.setName("zhangsan");
String destination2 = topicName+":create2";
String destination3 = topicName+":createTagName3";
//1.没有指定tag,单项发送消息
template.sendOneWay(topicName, user);
/* 注意:org.springframework.messaging.Message为默认对象,此对象是spring对所有消息体的抽象,
* 而MessageExt为RoketMq自身对象,包含更细节信息,如msgId
* */
//2.指定tag,并同步发送消息
//指定tag为create发送到topic。topic和name之间用“:”分割
template.syncSend(destination2, user, 10000);
}
}
\ No newline at end of file
package com.secoo.rocketmq.consumer;
import com.secoo.rocketmq.bean.User;
import com.secoo.rocketmq.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Slf4j
@Component
@RocketMQMessageListener(topic = "roketmq-simple-springboot", consumerGroup = "message-consumer",selectorExpression="create")
public class MassageConsumer implements RocketMQListener<User> {
@Resource
private UserService service;
@Override
public void onMessage(User user) {
log.info("create user.name:{}",user.getName());
//完成具体业务
service.create(user);
}
}
package com.secoo.rocketmq.consumer;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.common.UtilAll;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Slf4j
@Component
@RocketMQMessageListener(topic = "roketmq-simple-springboot", selectorExpression = "create", consumerGroup = "message-ext-consumer")
public class MessageExtConsumer implements RocketMQListener<MessageExt>, RocketMQPushConsumerLifecycleListener {
@Override
public void onMessage(MessageExt message) {
log.info("------- MessageExtConsumer received message, msgId:{}, body:{} ", message.getMsgId(), new String(message.getBody()));
}
@Override
/**
* 可以从指定的位置进行消费
*/
public void prepareStart(DefaultMQPushConsumer consumer) {
// set consumer consume message from now
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_TIMESTAMP);
consumer.setConsumeTimestamp(UtilAll.timeMillisToHumanString3(System.currentTimeMillis()));
}
}
\ No newline at end of file
rocketmq:
name-server: dev01-mq-mall1.secoolocal.com:9876;dev01-mq-mall2.secoolocal.com:9876
producer:
group: simple-group
server:
port: 9090
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-rocketmq</artifactId>
<packaging>pom</packaging>
<modules>
<module>matrix-sample-rocketmq-spring</module>
<module>matrix-sample-rocketmq-springboot</module>
<module>matrix-sample-rocketmq-biz</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-rocketmq-biz</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
\ No newline at end of file
...@@ -4,11 +4,7 @@ ...@@ -4,11 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules>
<module>matrix-sample-xxl</module>
<module>matrix-sample-dubbo</module>
<module>matrix-sample-hbase</module>
</modules>
<parent> <parent>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
...@@ -16,6 +12,14 @@ ...@@ -16,6 +12,14 @@
</parent> </parent>
<artifactId>matrix-sample</artifactId> <artifactId>matrix-sample</artifactId>
<modules>
<module>matrix-sample-xxl</module>
<module>matrix-sample-dubbo</module>
<module>matrix-sample-hbase</module>
<module>matrix-sample-rocketmq</module>
<module>matrix-sample-redis</module>
</modules>
</project> </project>
\ 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