Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mall
arch
matrix
Commits
fa5b533a
Commit
fa5b533a
authored
Feb 12, 2020
by
QIANGLU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
恢复rocketmq start
parent
782901d5
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
231 additions
and
0 deletions
+231
-0
pom.xml
pom.xml
+1
-0
pom.xml
rocketmq-starter/pom.xml
+31
-0
MatrixListenerContainerConfiguration.java
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/config/MatrixListenerContainerConfiguration.java
+44
-0
MatrixRocketMQAutoConfiguration.java
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/config/MatrixRocketMQAutoConfiguration.java
+60
-0
MatrixConsumeHook.java
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/hook/MatrixConsumeHook.java
+32
-0
MatrixProducerHook.java
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/hook/MatrixProducerHook.java
+33
-0
MartixProducer.java
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/producer/MartixProducer.java
+26
-0
spring.factories
rocketmq-starter/src/main/resources/META-INF/spring.factories
+4
-0
No files found.
pom.xml
View file @
fa5b533a
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
<module>
config-starter
</module>
<module>
config-starter
</module>
<module>
matrix-protocol
</module>
<module>
matrix-protocol
</module>
<module>
matrix-datasource
</module>
<module>
matrix-datasource
</module>
<module>
rocketmq-starter
</module>
</modules>
</modules>
...
...
rocketmq-starter/pom.xml
0 → 100644
View file @
fa5b533a
<?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
</artifactId>
<groupId>
com.secoo.mall
</groupId>
<version>
1.2.10.RELEASE
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
rocketmq-starter
</artifactId>
<dependencies>
<dependency>
<groupId>
org.apache.rocketmq
</groupId>
<artifactId>
rocketmq-spring-boot-starter
</artifactId>
<version>
2.0.3
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>
maven-source-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/config/MatrixListenerContainerConfiguration.java
0 → 100644
View file @
fa5b533a
package
com
.
secoo
.
mall
.
rocketmq
.
config
;
import
com.secoo.mall.rocketmq.hook.MatrixConsumeHook
;
import
org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author qianglu
*/
@Configuration
public
class
MatrixListenerContainerConfiguration
implements
BeanPostProcessor
{
private
final
static
Logger
log
=
LoggerFactory
.
getLogger
(
MatrixListenerContainerConfiguration
.
class
);
@Value
(
"${matrix.rocketmq.consumer.delayLevel:0}"
)
private
int
delayLevel
;
@Bean
MatrixConsumeHook
matrixConsumeHook
()
{
return
new
MatrixConsumeHook
();
}
@Override
public
Object
postProcessAfterInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
if
(
bean
instanceof
DefaultRocketMQListenerContainer
)
{
DefaultRocketMQListenerContainer
container
=
(
DefaultRocketMQListenerContainer
)
bean
;
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"MatrixListenerContainerConfiguration config setDelayLevelWhenNextConsume value:{}"
,
delayLevel
);
}
container
.
setDelayLevelWhenNextConsume
(
delayLevel
);
container
.
getConsumer
().
getDefaultMQPushConsumerImpl
().
registerConsumeMessageHook
(
matrixConsumeHook
());
}
return
bean
;
}
}
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/config/MatrixRocketMQAutoConfiguration.java
0 → 100644
View file @
fa5b533a
package
com
.
secoo
.
mall
.
rocketmq
.
config
;
import
com.secoo.mall.rocketmq.hook.MatrixProducerHook
;
import
com.secoo.mall.rocketmq.producer.MartixProducer
;
import
org.apache.rocketmq.acl.common.AclClientRPCHook
;
import
org.apache.rocketmq.acl.common.SessionCredentials
;
import
org.apache.rocketmq.client.AccessChannel
;
import
org.apache.rocketmq.client.producer.DefaultMQProducer
;
import
org.apache.rocketmq.spring.autoconfigure.RocketMQProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
/**
* @author qianglu
*/
@Configuration
@Import
(
MatrixListenerContainerConfiguration
.
class
)
public
class
MatrixRocketMQAutoConfiguration
{
@Bean
public
DefaultMQProducer
defaultMQProducer
(
RocketMQProperties
rocketMQProperties
)
{
RocketMQProperties
.
Producer
producerConfig
=
rocketMQProperties
.
getProducer
();
String
nameServer
=
rocketMQProperties
.
getNameServer
();
String
groupName
=
producerConfig
.
getGroup
();
Assert
.
hasText
(
nameServer
,
"[rocketmq.name-server] must not be null"
);
Assert
.
hasText
(
groupName
,
"[rocketmq.producer.group] must not be null"
);
String
accessChannel
=
rocketMQProperties
.
getAccessChannel
();
MartixProducer
producer
;
String
ak
=
rocketMQProperties
.
getProducer
().
getAccessKey
();
String
sk
=
rocketMQProperties
.
getProducer
().
getSecretKey
();
MatrixProducerHook
matrixProducerHook
=
new
MatrixProducerHook
();
if
(!
StringUtils
.
isEmpty
(
ak
)
&&
!
StringUtils
.
isEmpty
(
sk
))
{
producer
=
new
MartixProducer
(
groupName
,
new
AclClientRPCHook
(
new
SessionCredentials
(
ak
,
sk
)),
rocketMQProperties
.
getProducer
().
isEnableMsgTrace
(),
rocketMQProperties
.
getProducer
().
getCustomizedTraceTopic
(),
matrixProducerHook
);
producer
.
setVipChannelEnabled
(
false
);
}
else
{
producer
=
new
MartixProducer
(
groupName
,
rocketMQProperties
.
getProducer
().
isEnableMsgTrace
(),
rocketMQProperties
.
getProducer
().
getCustomizedTraceTopic
(),
matrixProducerHook
);
}
producer
.
setNamesrvAddr
(
nameServer
);
if
(!
StringUtils
.
isEmpty
(
accessChannel
))
{
producer
.
setAccessChannel
(
AccessChannel
.
valueOf
(
accessChannel
));
}
producer
.
setSendMsgTimeout
(
producerConfig
.
getSendMessageTimeout
());
producer
.
setRetryTimesWhenSendFailed
(
producerConfig
.
getRetryTimesWhenSendFailed
());
producer
.
setRetryTimesWhenSendAsyncFailed
(
producerConfig
.
getRetryTimesWhenSendAsyncFailed
());
producer
.
setMaxMessageSize
(
producerConfig
.
getMaxMessageSize
());
producer
.
setCompressMsgBodyOverHowmuch
(
producerConfig
.
getCompressMessageBodyThreshold
());
producer
.
setRetryAnotherBrokerWhenNotStoreOK
(
producerConfig
.
isRetryNextServer
());
return
producer
;
}
}
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/hook/MatrixConsumeHook.java
0 → 100644
View file @
fa5b533a
package
com
.
secoo
.
mall
.
rocketmq
.
hook
;
import
org.apache.rocketmq.client.hook.ConsumeMessageContext
;
import
org.apache.rocketmq.client.hook.ConsumeMessageHook
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author qianglu
*/
public
class
MatrixConsumeHook
implements
ConsumeMessageHook
{
private
final
static
Logger
log
=
LoggerFactory
.
getLogger
(
MatrixConsumeHook
.
class
);
@Override
public
String
hookName
()
{
return
"MatrixConsumeHook"
;
}
@Override
public
void
consumeMessageBefore
(
ConsumeMessageContext
context
)
{
}
@Override
public
void
consumeMessageAfter
(
ConsumeMessageContext
context
)
{
try
{
log
.
info
(
"consumeMessageAfter,Succ:{} Topic:{},TraceContext:{},ConsumerGroup:{}"
,
context
.
isSuccess
(),
context
.
getMq
().
getTopic
(),
context
.
getMqTraceContext
(),
context
.
getConsumerGroup
());
}
catch
(
Exception
e
)
{
//防灾冗余
}
}
}
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/hook/MatrixProducerHook.java
0 → 100644
View file @
fa5b533a
package
com
.
secoo
.
mall
.
rocketmq
.
hook
;
import
org.apache.rocketmq.client.hook.SendMessageContext
;
import
org.apache.rocketmq.client.hook.SendMessageHook
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author qianglu
*/
public
class
MatrixProducerHook
implements
SendMessageHook
{
private
final
static
Logger
log
=
LoggerFactory
.
getLogger
(
MatrixProducerHook
.
class
);
@Override
public
String
hookName
()
{
return
"MatrixProducerHook"
;
}
@Override
public
void
sendMessageBefore
(
SendMessageContext
context
)
{
}
@Override
public
void
sendMessageAfter
(
SendMessageContext
context
)
{
try
{
log
.
info
(
"sendMessageAfter,TraceContext:{},Mode:{},Topic:{},Targs:{},ProducerGroup:{},BrokerAddr:{},Namespace:{},Exception:{}"
,
context
.
getMqTraceContext
(),
context
.
getCommunicationMode
().
name
(),
context
.
getMessage
().
getTopic
(),
context
.
getMessage
().
getTags
(),
context
.
getProducerGroup
(),
context
.
getBrokerAddr
(),
context
.
getNamespace
(),
context
.
getException
()
==
null
?
null
:
context
.
getException
().
getMessage
());
}
catch
(
Exception
e
)
{
//防灾冗余}
}
}
}
\ No newline at end of file
rocketmq-starter/src/main/java/com/secoo/mall/rocketmq/producer/MartixProducer.java
0 → 100644
View file @
fa5b533a
package
com
.
secoo
.
mall
.
rocketmq
.
producer
;
import
org.apache.rocketmq.client.hook.SendMessageHook
;
import
org.apache.rocketmq.client.producer.DefaultMQProducer
;
import
org.apache.rocketmq.remoting.RPCHook
;
/**
* @author qianglu
*/
public
class
MartixProducer
extends
DefaultMQProducer
{
public
MartixProducer
(
final
String
producerGroup
,
RPCHook
rpcHook
,
boolean
enableMsgTrace
,
final
String
customizedTraceTopic
,
SendMessageHook
messageHook
)
{
super
(
producerGroup
,
rpcHook
,
enableMsgTrace
,
customizedTraceTopic
);
this
.
defaultMQProducerImpl
.
registerSendMessageHook
(
messageHook
);
}
public
MartixProducer
(
final
String
producerGroup
,
boolean
enableMsgTrace
,
final
String
customizedTraceTopic
,
SendMessageHook
messageHook
)
{
super
(
producerGroup
,
enableMsgTrace
,
customizedTraceTopic
);
this
.
defaultMQProducerImpl
.
registerSendMessageHook
(
messageHook
);
}
}
rocketmq-starter/src/main/resources/META-INF/spring.factories
0 → 100755
View file @
fa5b533a
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.secoo.mall.rocketmq.config.MatrixRocketMQAutoConfiguration
\ 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