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
a551176b
Commit
a551176b
authored
Dec 11, 2019
by
QIANGLU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新rocketmq
parent
138eb5e8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
275 additions
and
1 deletions
+275
-1
HelloWordClient.java
spring-boot-grpc/src/main/java/com/matrix/grpc/HelloWordClient.java
+1
-1
pom.xml
spring-boot-rocketmq/pom.xml
+71
-0
RcoketStartup.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/RcoketStartup.java
+22
-0
ConsumerListener.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/rocketmq/ConsumerListener.java
+33
-0
SendRocketDemo.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/rocketmq/SendRocketDemo.java
+57
-0
NettyClient.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/tcp/NettyClient.java
+27
-0
NettyServer.java
spring-boot-rocketmq/src/main/java/com/matrix/pure/tcp/NettyServer.java
+55
-0
application.yml
spring-boot-rocketmq/src/main/resources/application.yml
+9
-0
No files found.
spring-boot-grpc/src/main/java/com/matrix/grpc/HelloWordClient.java
View file @
a551176b
package
com
.
matrix
.
grpc
;
import
com.takumiCX.greeter.GreeterGrpc
;
import
com.takumiCX.greeter.HelloGrpc
;
import
com.takumiCX.greeter.HelloReply
;
import
com.takumiCX.greeter.HelloRequest
;
import
io.grpc.ManagedChannel
;
...
...
@@ -24,7 +25,6 @@ public class HelloWordClient {
ManagedChannel
channel
=
ManagedChannelBuilder
.
forAddress
(
"localhost"
,
port
).
usePlaintext
().
build
();
GreeterGrpc
.
GreeterBlockingStub
stub
=
GreeterGrpc
.
newBlockingStub
(
channel
);
Scanner
scanner
=
new
Scanner
(
System
.
in
);
while
(
true
){
...
...
spring-boot-rocketmq/pom.xml
0 → 100644
View file @
a551176b
<?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"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.nova
</groupId>
<artifactId>
spring-boot-rocketmq
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<parent>
<artifactId>
matrix
</artifactId>
<groupId>
com.secoo.mall
</groupId>
<version>
1.1.8.RELEASE
</version>
</parent>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
logger-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-autoconfigure
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
com.secoo.mall
</groupId>
<artifactId>
rocketmq-starter
</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
\ No newline at end of file
spring-boot-rocketmq/src/main/java/com/matrix/pure/RcoketStartup.java
0 → 100644
View file @
a551176b
package
com
.
matrix
.
pure
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* @ClassName RcoketStartup
* @Author QIANGLU
* @Date 2019/11/28 4:00 下午
* @Version 1.0
*/
@SpringBootApplication
public
class
RcoketStartup
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
RcoketStartup
.
class
,
args
);
}
}
spring-boot-rocketmq/src/main/java/com/matrix/pure/rocketmq/ConsumerListener.java
0 → 100644
View file @
a551176b
package
com
.
matrix
.
pure
.
rocketmq
;
import
org.apache.rocketmq.spring.annotation.RocketMQMessageListener
;
import
org.apache.rocketmq.spring.core.RocketMQListener
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
javax.print.DocFlavor
;
import
java.util.concurrent.atomic.AtomicInteger
;
/**
* @ClassName ConsumerListener
* @Author QIANGLU
* @Date 2019/11/28 3:53 下午
* @Version 1.0
*/
@Component
@RocketMQMessageListener
(
topic
=
"topic"
,
consumerGroup
=
"exwarngroup"
)
public
class
ConsumerListener
implements
RocketMQListener
<
String
>
{
private
final
static
Logger
log
=
LoggerFactory
.
getLogger
(
ConsumerListener
.
class
);
private
volatile
AtomicInteger
count
=
new
AtomicInteger
();
@Override
public
void
onMessage
(
String
message
)
{
log
.
info
(
" consumer count:{}"
,
count
.
incrementAndGet
());
}
}
spring-boot-rocketmq/src/main/java/com/matrix/pure/rocketmq/SendRocketDemo.java
0 → 100644
View file @
a551176b
package
com
.
matrix
.
pure
.
rocketmq
;
import
org.apache.rocketmq.client.producer.SendResult
;
import
org.apache.rocketmq.common.message.Message
;
import
org.apache.rocketmq.spring.core.RocketMQTemplate
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
/**
* @ClassName SendRocketService
* @Author QIANGLU
* @Date 2019/11/28 3:47 下午
* @Version 1.0
*/
@Component
public
class
SendRocketDemo
implements
Runnable
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SendRocketDemo
.
class
);
@Resource
private
RocketMQTemplate
rocketMQTemplate
;
private
ScheduledFuture
<?>
scheduledFuture
;
private
volatile
AtomicInteger
count
=
new
AtomicInteger
();
public
SendRocketDemo
(){
scheduledFuture
=
Executors
.
newSingleThreadScheduledExecutor
().
scheduleAtFixedRate
(
this
,
0
,
1
,
TimeUnit
.
SECONDS
);
}
@Override
public
void
run
()
{
//发送 Demo
try
{
Message
message
=
new
Message
();
//设置 body
message
.
setBody
(
"我是一条测试信息"
.
getBytes
());
//设置tag
message
.
setTags
(
"demo"
);
//同步发送 第一个参数是topic
SendResult
sendResult
=
rocketMQTemplate
.
syncSend
(
"topic"
,
message
);
//异步发送
rocketMQTemplate
.
asyncSend
(
"topic"
,
message
,
null
,
0
);
}
catch
(
Exception
e
){
logger
.
error
(
"发送MQ异常"
,
e
);
}
}
}
spring-boot-rocketmq/src/main/java/com/matrix/pure/tcp/NettyClient.java
0 → 100644
View file @
a551176b
package
com
.
matrix
.
pure
.
tcp
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.SocketChannel
;
/**
* @ClassName NettyServer
* @Author QIANGLU
* @Date 2019/12/3 11:31 下午
* @Version 1.0
*/
public
class
NettyClient
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
SocketChannel
socketChannel
=
SocketChannel
.
open
();
socketChannel
.
bind
(
new
InetSocketAddress
(
"localhost"
,
9999
));
ByteBuffer
byteBuffer
=
ByteBuffer
.
allocate
(
1024
);
byteBuffer
.
put
(
"this is test "
.
getBytes
());
byteBuffer
.
flip
();
while
(
byteBuffer
.
hasRemaining
()){
socketChannel
.
write
(
byteBuffer
);
}
}
}
spring-boot-rocketmq/src/main/java/com/matrix/pure/tcp/NettyServer.java
0 → 100644
View file @
a551176b
package
com
.
matrix
.
pure
.
tcp
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.SelectionKey
;
import
java.nio.channels.Selector
;
import
java.nio.channels.ServerSocketChannel
;
import
java.nio.channels.SocketChannel
;
import
java.util.Iterator
;
/**
* @ClassName NettyServer
* @Author QIANGLU
* @Date 2019/12/3 11:31 下午
* @Version 1.0
*/
public
class
NettyServer
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
Selector
selector
=
Selector
.
open
();
ServerSocketChannel
socketChannel
=
ServerSocketChannel
.
open
();
socketChannel
.
bind
(
new
InetSocketAddress
(
"loclhost"
,
9999
));
socketChannel
.
configureBlocking
(
false
);
socketChannel
.
register
(
selector
,
SelectionKey
.
OP_ACCEPT
);
while
(
true
)
{
selector
.
select
();
Iterator
<
SelectionKey
>
selectorIterator
=
selector
.
selectedKeys
().
iterator
();
while
(
selectorIterator
.
hasNext
()){
SelectionKey
selectionKey
=
selectorIterator
.
next
();
if
(
selectionKey
.
isAcceptable
()){
SocketChannel
channel
=
socketChannel
.
accept
();
channel
.
configureBlocking
(
false
);
channel
.
register
(
selector
,
SelectionKey
.
OP_READ
,
ByteBuffer
.
allocate
(
1024
));
}
if
(
selectionKey
.
isReadable
()){
}
}
//
SocketChannel
socketChannel1
=
socketChannel
.
accept
();
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
1024
);
int
reder
=
socketChannel1
.
read
(
buffer
);
if
(
reder
>
0
)
{
buffer
.
flip
();
byte
[]
bytes
=
new
byte
[
buffer
.
remaining
()];
buffer
.
get
(
bytes
);
String
body
=
new
String
(
bytes
,
"UTF-8"
);
System
.
out
.
println
(
"server 收到:"
+
body
);
}
}
}
}
spring-boot-rocketmq/src/main/resources/application.yml
0 → 100644
View file @
a551176b
spring
:
application
:
name
:
learn-rocketmq
server
:
port
:
6080
rocketmq
:
name-server
:
10.0.254.191:9876;10.0.254.206:9876
producer
:
group
:
learn-rocketmq
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