-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ 升级rocketmq-spring-boot-starter 2.2.3
- Loading branch information
Showing
12 changed files
with
151 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...g-boot-rocketmq/src/main/java/moe/ahao/spring/boot/rocketmq/AbstractRocketMQListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package moe.ahao.spring.boot.rocketmq; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.rocketmq.common.message.MessageExt; | ||
import org.apache.rocketmq.spring.core.RocketMQListener; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* 抽象的消费者MessageListener组件 | ||
* 实现RocktMQ原生的RocketMQListener | ||
*/ | ||
@Slf4j | ||
public abstract class AbstractRocketMQListener implements RocketMQListener<MessageExt> { | ||
|
||
@Override | ||
public void onMessage(MessageExt message) { | ||
try { | ||
log.info("接收到MQ消息开始, message:{}", message); | ||
|
||
this.onMessage(new String(message.getBody(), StandardCharsets.UTF_8)); | ||
} catch (Exception e) { | ||
log.error("接收到MQ消息, 消费MQ消息异常, message:{}", message, e); | ||
} | ||
} | ||
|
||
public abstract void onMessage(String message); | ||
} |
14 changes: 14 additions & 0 deletions
14
ahao-spring-boot-rocketmq/src/main/java/moe/ahao/spring/boot/rocketmq/Constant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package moe.ahao.spring.boot.rocketmq; | ||
|
||
public class Constant { | ||
public static final String DEFAULT_TOPIC = "ahao-topic"; | ||
public static final String DEFAULT_NAMESPACE = "ahao-namespace"; | ||
|
||
public static final String CONSUMER_GROUP_TAG1 = "ahao-consumer-group-tag1"; | ||
public static final String CONSUMER_GROUP_TAG2 = "ahao-consumer-group-tag2"; | ||
|
||
public static final String TAG1 = "TAG1"; | ||
public static final String TAG2 = "TAG2"; | ||
|
||
|
||
} |
35 changes: 35 additions & 0 deletions
35
ahao-spring-boot-rocketmq/src/main/java/moe/ahao/spring/boot/rocketmq/Event1MQListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package moe.ahao.spring.boot.rocketmq; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import moe.ahao.exception.BizException; | ||
import org.apache.rocketmq.spring.annotation.ConsumeMode; | ||
import org.apache.rocketmq.spring.annotation.MessageModel; | ||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@RocketMQMessageListener( | ||
namespace = "${rocketmq.consumer.namespace}", | ||
topic = Constant.DEFAULT_TOPIC, | ||
consumerGroup = Constant.CONSUMER_GROUP_TAG1, | ||
selectorExpression = Constant.TAG1, | ||
consumeMode = ConsumeMode.CONCURRENTLY, | ||
messageModel = MessageModel.CLUSTERING, | ||
consumeThreadNumber = 1 | ||
) | ||
public class Event1MQListener extends AbstractRocketMQListener { | ||
@Override | ||
public void onMessage(String message) { | ||
log.info("事件监听器Event1MQListener, 接收到message:{}", message); | ||
try { | ||
|
||
} catch (BizException e) { | ||
log.error("业务失败", e); | ||
// throw e; | ||
} catch (Exception e) { | ||
log.error("异常失败", e); | ||
throw e; // nack | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ahao-spring-boot-rocketmq/src/main/java/moe/ahao/spring/boot/rocketmq/Event2MQListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package moe.ahao.spring.boot.rocketmq; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import moe.ahao.exception.BizException; | ||
import org.apache.rocketmq.spring.annotation.ConsumeMode; | ||
import org.apache.rocketmq.spring.annotation.MessageModel; | ||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@RocketMQMessageListener( | ||
namespace = "${rocketmq.consumer.namespace}", | ||
topic = Constant.DEFAULT_TOPIC, | ||
consumerGroup = Constant.CONSUMER_GROUP_TAG2, | ||
selectorExpression = Constant.TAG2, | ||
consumeMode = ConsumeMode.CONCURRENTLY, | ||
messageModel = MessageModel.CLUSTERING, | ||
consumeThreadNumber = 1 | ||
) | ||
public class Event2MQListener extends AbstractRocketMQListener { | ||
@Override | ||
public void onMessage(String message) { | ||
log.info("事件监听器Event2MQListener, 接收到message:{}", message); | ||
try { | ||
|
||
} catch (BizException e) { | ||
log.error("业务失败", e); | ||
// throw e; | ||
} catch (Exception e) { | ||
log.error("异常失败", e); | ||
throw e; // nack | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
ahao-spring-boot-rocketmq/src/main/resources/application-rocketmq.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
spring: | ||
application: | ||
name: ahao-rocketmq | ||
|
||
|
||
rocketmq.name-server: 192.168.19.131:9876 | ||
rocketmq.producer.namespace: ahao-namespace | ||
rocketmq.producer.group: ahao-producer-group | ||
rocketmq.consumer.namespace: ahao-namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
spring: | ||
application: | ||
name: ahao-rocketmq | ||
profiles: | ||
active: rocketmq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
ahao-spring-boot-rocketmq/src/test/resources/application-rocketmq.yml
This file was deleted.
Oops, something went wrong.