delay-message-client

延时消息客户端

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.github.kancyframework
ArtifactId

ArtifactId

delay-message-client
Last Version

Last Version

0.0.1-RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

delay-message-client
延时消息客户端
Source Code Management

Source Code Management

https://github.com/kancyframework/delay-message.git

Download delay-message-client

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.kancyframework/delay-message-client/ -->
<dependency>
    <groupId>com.github.kancyframework</groupId>
    <artifactId>delay-message-client</artifactId>
    <version>0.0.1-RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.kancyframework/delay-message-client/
implementation 'com.github.kancyframework:delay-message-client:0.0.1-RELEASE'
// https://jarcasting.com/artifacts/com.github.kancyframework/delay-message-client/
implementation ("com.github.kancyframework:delay-message-client:0.0.1-RELEASE")
'com.github.kancyframework:delay-message-client:jar:0.0.1-RELEASE'
<dependency org="com.github.kancyframework" name="delay-message-client" rev="0.0.1-RELEASE">
  <artifact name="delay-message-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.kancyframework', module='delay-message-client', version='0.0.1-RELEASE')
)
libraryDependencies += "com.github.kancyframework" % "delay-message-client" % "0.0.1-RELEASE"
[com.github.kancyframework/delay-message-client "0.0.1-RELEASE"]

Dependencies

compile (2)

Group / Artifact Type Version
com.github.kancyframework : delay-message-core jar 0.0.1-RELEASE
org.springframework.boot : spring-boot-configuration-processor Optional jar

provided (2)

Group / Artifact Type Version
org.springframework.cloud : spring-cloud-context jar
org.springframework.boot : spring-boot-starter-actuator jar

Project Modules

There are no modules declared in this project.

Delay Message Program

基于储存设备和定时任务驱动的延时消息解决方案

模块设计

  • 应用层:客户端、调度端
  • 数据层:数据储存设备
  • 核心层:定义标准、公共资源

客户端接入

1.引入delay-message-client.jar

<dependency>
    <groupId>com.github.kancyframework</groupId>
    <artifactId>delay-message-client</artifactId>
    <version>0.0.1-RELEASE</version>
</dependency>
<dependency>
    <groupId>com.github.kancyframework</groupId>
    <artifactId>delay-message-data-mongodb</artifactId>
    <version>0.0.1-RELEASE</version>
</dependency>

2.发送延时消息

@Slf4j
@RequiredArgsConstructor
@Component
public class DelayMessageClientDemo {
    private final DelayMessageClient delayMessageClient;

    /**
     * 发送消息
     */
    public void send(){
        TestDelayMessage testDelayMessage = new TestDelayMessage();
        testDelayMessage.setPayload(Collections.singletonMap("name","kancy"));
        testDelayMessage.setDelay(Duration.ofHours(5));
        delayMessageClient.send(testDelayMessage);
    }
}

调度端接入

1.引入delay-message-client.jar

<dependency>
    <groupId>com.github.kancyframework</groupId>
    <artifactId>delay-message-scheduler</artifactId>
    <version>0.0.1-RELEASE</version>
</dependency>
<dependency>
    <groupId>com.github.kancyframework</groupId>
    <artifactId>delay-message-data-mongodb</artifactId>
    <version>0.0.1-RELEASE</version>
</dependency>

2.调度

2.1本地调度

@Slf4j
@RequiredArgsConstructor
@Component
public class DemoScheduler {
    private final DelayMessageScheduler DelayMessageScheduler;

    @Async
    @Scheduled(cron = "0/5 * * * * ? ")
    public void onConsume() {
        DelayMessageScheduler.schedule("t_delay_message", 500);
    }
}

2.2分布式调度

1)添加xxl-job配置文件

# xxl-job配置
xxl.job.admin.addresses = http://10.10.24.106:12306/xxl-job-admin/
xxl.job.executor.appname = test-schedule-dev
xxl.job.executor.port = 39501
xxl.job.executor.logpath = logs/xxljob

2)配置调度任务

调度参数:{"table":"t_delay_message", "limit": 200}

  • DelayMessageTableJob(2.1.2及以下版本支持)
  • DelayMessageJob(2.1.2及以上版本支持)

微信截图_20200729153100.png

Versions

Version
0.0.1-RELEASE