Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix-sample
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mall
arch
matrix-sample
Commits
1f9b3cfb
Commit
1f9b3cfb
authored
Mar 19, 2020
by
qiuweili123
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加hbasedemo
parent
a9f95a29
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
1 deletions
+121
-1
Application.java
matrix-sample-hbase/matrix-sample-hbase-springboot/src/main/java/com/secoo/mall/Application.java
+15
-0
SimpleHBase.java
matrix-sample-hbase/matrix-sample-hbase-springboot/src/main/java/com/secoo/mall/hbase/SimpleHBase.java
+95
-0
application.yml
matrix-sample-hbase/matrix-sample-hbase-springboot/src/main/resources/application.yml
+9
-0
RoketMqSampleApplication.java
matrix-sample-rocketmq/matrix-sample-rocketmq-springboot/src/main/java/com/secoo/rocketmq/RoketMqSampleApplication.java
+2
-1
No files found.
matrix-sample-hbase/matrix-sample-hbase-springboot/src/main/java/com/secoo/mall/Application.java
0 → 100644
View file @
1f9b3cfb
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"
);
}
}
matrix-sample-hbase/matrix-sample-hbase-springboot/src/main/java/com/secoo/mall/hbase/SimpleHBase.java
0 → 100644
View file @
1f9b3cfb
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
();
}
}
matrix-sample-hbase/matrix-sample-hbase-springboot/src/main/resources/application.yml
0 → 100644
View file @
1f9b3cfb
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
matrix-sample-rocketmq/matrix-sample-rocketmq-springboot/src/main/java/com/secoo/rocketmq/RoketMqSampleApplication.java
View file @
1f9b3cfb
...
...
@@ -42,6 +42,6 @@ public class RoketMqSampleApplication implements ApplicationRunner {
template
.
syncSend
(
destination2
,
user
,
10000
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment