4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.utils;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/29
22 | * @description 数据库操作标识
23 | */
24 | public enum RdbOperation {
25 | INSERT, UPDATE, DELETE
26 | }
27 |
--------------------------------------------------------------------------------
/mykit-delay-rpc/mykit-rpc-dubbo/mykit-rpc-dubbo-xml/src/main/resources/spring/mykit-delay-server-main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/mykit-delay-rpc/mykit-rpc-dubbo/mykit-rpc-dubbo-xml/src/test/resources/spring/mykit-delay-server-client.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/mykit-delay-rpc/mykit-rpc-dubbo/mykit-rpc-dubbo-xml/src/main/resources/dubbo/mykit-delay-server.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/redis/event/JobEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.redis.event;
17 |
18 | import io.mykit.delay.queue.JobMsg;
19 |
20 | /**
21 | * @author liuyazhuang
22 | * @version 1.0.0
23 | * @date 2019/5/30
24 | * @description Job事件
25 | */
26 | public interface JobEvent {
27 |
28 | JobMsg getJob();
29 | }
30 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/leader/LeaderManager.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.leader;
17 |
18 |
19 | import io.mykit.delay.queue.redis.support.Lifecycle;
20 |
21 | /**
22 | * @author liuyazhuang
23 | * @version 1.0.0
24 | * @date 2019/5/29
25 | * @description Leader管理器
26 | */
27 | public interface LeaderManager extends Lifecycle {
28 |
29 | boolean isLeader();
30 | }
31 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/redis/event/JobEventListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.redis.event;
17 |
18 | import com.google.common.eventbus.Subscribe;
19 |
20 | /**
21 | * @author liuyazhuang
22 | * @version 1.0.0
23 | * @date 2019/5/30
24 | * @description Job事件监听器
25 | */
26 | public interface JobEventListener {
27 |
28 | @Subscribe
29 | void listen(JobEvent event);
30 | }
31 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/extension/ExtNamed.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.extension;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * @author liuyazhuang
22 | * @version 1.0.0
23 | * @date 2019/5/29
24 | * @description 扩展名称
25 | */
26 | @Documented
27 | @Retention(RetentionPolicy.RUNTIME)
28 | @Target({ElementType.TYPE})
29 | public @interface ExtNamed {
30 | String value();
31 | }
32 |
--------------------------------------------------------------------------------
/mykit-delay-common/src/main/java/io/mykit/delay/common/exception/JobNotFoundException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.exception;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/29
22 | * @description 任务未找到异常
23 | */
24 | public class JobNotFoundException extends DelayQueueException {
25 |
26 | public JobNotFoundException(String errorMessage, Object... args) {
27 | super(errorMessage, args);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/mykit-delay-controller/src/main/java/io/mykit/delay/controller/AdminController.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.controller;
17 |
18 | import org.springframework.stereotype.Controller;
19 | import org.springframework.web.bind.annotation.RequestMapping;
20 |
21 | /**
22 | * @author liuyazhuang
23 | * @version 1.0.0
24 | * @date 2019/5/30
25 | * @description 后台管理Controller 待实现
26 | */
27 | @Controller
28 | @RequestMapping(value = "/admin")
29 | public class AdminController {
30 | }
31 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/extension/SPI.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.extension;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * @author liuyazhuang
22 | * @version 1.0.0
23 | * @date 2019/5/29
24 | * @description
25 | */
26 | @Documented
27 | @Retention(RetentionPolicy.RUNTIME)
28 | @Target({ElementType.TYPE})
29 | public @interface SPI {
30 |
31 | /**
32 | * 默认的实现方式
33 | */
34 | String value() default "";
35 | }
36 |
--------------------------------------------------------------------------------
/mykit-delay-common/src/main/java/io/mykit/delay/common/utils/Status.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.utils;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/29
22 | * @description 状态枚举类
23 | */
24 | public enum Status {
25 | WaitPut,//待加入
26 | Delay,//已经进入延时队列
27 | Ready,//已经出了延时队列 客户端可以方法此数据
28 | Finish,//客户端已经处理完数据了
29 | Delete,//客户端已经把数据删除了
30 | Restore,//手动恢复重发状态/或者是在实时队列中验证时间出现异常 再次放入buck中
31 | ConsumerFailRestore//消费失败
32 | }
33 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/redis/support/Lifecycle.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.redis.support;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/30
22 | * @description 声明周期接口
23 | */
24 | public interface Lifecycle {
25 |
26 | /**
27 | * 启动
28 | */
29 | void start();
30 |
31 | /**
32 | * 停止
33 | */
34 | void stop();
35 |
36 | /**
37 | * 是否正在运行
38 | * @return 是返回true; 否返回false
39 | */
40 | boolean isRunning();
41 | }
42 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/leader/ServerNode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.leader;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/29
22 | * @description 服务器节点
23 | */
24 | public class ServerNode {
25 | public static final String DIR_SPLITE = "/";
26 | public static final String ROOT = "mykit-delay";
27 | public static final String LEADERLATCH = DIR_SPLITE + ROOT + DIR_SPLITE + "latch";
28 | public static String NAMESPACE = "io-mykit-delay";
29 | }
30 |
--------------------------------------------------------------------------------
/mykit-delay-common/src/main/java/io/mykit/delay/common/exception/ConsumeQueueException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.exception;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/29
22 | * @description 消费者队列异常
23 | */
24 | public class ConsumeQueueException extends DelayQueueException {
25 |
26 |
27 | private static final long serialVersionUID = 4455481920310547043L;
28 |
29 | public ConsumeQueueException(String errorMessage, Object... args) {
30 | super(errorMessage, args);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/core/ConsumeQueueProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.core;
17 |
18 | import io.mykit.delay.common.exception.ConsumeQueueException;
19 | import io.mykit.delay.queue.extension.SPI;
20 |
21 | /**
22 | * @author liuyazhuang
23 | * @version 1.0.0
24 | * @date 2019/5/29
25 | * @description 消费者队列提供者
26 | */
27 | @SPI("consoleCQ")
28 | public interface ConsumeQueueProvider {
29 | void init();
30 |
31 | void consumer(Job job) throws ConsumeQueueException;
32 |
33 | void destory();
34 | }
35 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/core/Job.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.core;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/29
22 | * @description 任务
23 | */
24 | public interface Job {
25 |
26 | String getBizKey();
27 |
28 |
29 | String getTopic();
30 |
31 |
32 | String getId();
33 |
34 |
35 | long getDelay();
36 |
37 |
38 | long getTtl();
39 |
40 |
41 | String getBody();
42 |
43 |
44 | long getCreateTime();
45 |
46 |
47 | int getStatus();
48 |
49 |
50 | String getSubtopic();
51 |
52 | String toJsonString();
53 | }
54 |
--------------------------------------------------------------------------------
/mykit-delay-common/src/main/java/io/mykit/delay/common/exception/DelayQueueException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.exception;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/29
22 | * @description 延迟队列异常
23 | */
24 | public class DelayQueueException extends RuntimeException {
25 |
26 | private static final long serialVersionUID = 5018901344199973515L;
27 |
28 | public DelayQueueException(final String errorMessage, final Object... args) {
29 | super(String.format(errorMessage, args));
30 | }
31 |
32 | public DelayQueueException(final Throwable cause) {
33 | super(cause);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/activemq/ActiveMQSender.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.activemq;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/6/12
22 | * @description ActiveMQ消息发送接口
23 | */
24 | public interface ActiveMQSender {
25 | /**
26 | * 发送消息
27 | * @param name 队列或者主题的名称
28 | * @param message 发送的消息
29 | */
30 | void send(String name, final String message);
31 |
32 | /**
33 | * 延时发送消息
34 | * @param name 队列或者主题的名称
35 | * @param message 发送的消息
36 | * @param scheduledDelayTime 延时时间
37 | */
38 | void send(String name, final String message,final long scheduledDelayTime);
39 | }
40 |
--------------------------------------------------------------------------------
/mykit-delay-test/src/main/java/io/mykit/delay/TestDelayQueue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay;
17 |
18 | import io.mykit.delay.queue.core.ConsumeQueueProvider;
19 | import io.mykit.delay.starter.ready.StartGetReady;
20 | import org.springframework.boot.SpringApplication;
21 | import org.springframework.boot.autoconfigure.SpringBootApplication;
22 |
23 | /**
24 | * @author liuyazhuang
25 | * @version 1.0.0
26 | * @date 2019/5/30
27 | * @description 测试延迟队列
28 | */
29 | @SpringBootApplication
30 | public class TestDelayQueue {
31 |
32 | public static void main(String[] args) {
33 | StartGetReady.ready(ConsumeQueueProvider.class.getName());
34 | SpringApplication.run(TestDelayQueue.class, args);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/mykit-delay-core/src/main/java/io/mykit/delay/MykitDelayCoreApplication.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay;
17 |
18 | import io.mykit.delay.queue.core.ConsumeQueueProvider;
19 | import io.mykit.delay.starter.ready.StartGetReady;
20 | import org.springframework.boot.SpringApplication;
21 | import org.springframework.boot.autoconfigure.SpringBootApplication;
22 |
23 | /**
24 | * @author liuyazhuang
25 | * @version 1.0.0
26 | * @date 2019/5/30
27 | * @description 程序入口
28 | */
29 | @SpringBootApplication
30 | public class MykitDelayCoreApplication {
31 |
32 | public static void main(String[] args){
33 | StartGetReady.ready(ConsumeQueueProvider.class.getName());
34 | SpringApplication.run(MykitDelayCoreApplication.class, args);
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/core/Queue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.core;
17 |
18 | import io.mykit.delay.common.exception.DelayQueueException;
19 | import io.mykit.delay.queue.JobMsg;
20 | import io.mykit.delay.queue.redis.support.Lifecycle;
21 |
22 | /**
23 | * @author liuyazhuang
24 | * @version 1.0.0
25 | * @date 2019/5/29
26 | * @description 队列
27 | */
28 | public interface Queue extends Lifecycle {
29 |
30 | void push(JobMsg job) throws DelayQueueException;
31 |
32 |
33 | boolean ack(String jobMsgId) throws DelayQueueException;
34 |
35 | long getSize();
36 |
37 | void clear();
38 |
39 | boolean delete(String jobMsgId);
40 |
41 | JobMsg getJob(String jobId);
42 |
43 | String getImplementType();
44 | }
45 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/redis/JobWrapp.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.redis;
17 |
18 | import com.alibaba.fastjson.JSONObject;
19 | import io.mykit.delay.queue.JobMsg;
20 |
21 | /**
22 | * @author liuyazhuang
23 | * @version 1.0.0
24 | * @date 2019/5/30
25 | * @description 任务包装类
26 | */
27 | public class JobWrapp extends JobMsg {
28 |
29 | private static final long serialVersionUID = -4623468942451592116L;
30 | private String buckedName;
31 |
32 | public String getBuckedName() {
33 | return buckedName;
34 | }
35 |
36 | public void setBuckedName(String buckedName) {
37 | this.buckedName = buckedName;
38 | }
39 |
40 | @Override
41 | public String toJsonString() {
42 | return JSONObject.toJSONString(this);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/mykit-delay-rpc/mykit-rpc-dubbo/mykit-rpc-dubbo-server/src/main/java/io/mykit/delay/MykitDelayServer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2020-9999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay;
17 |
18 | import io.mykit.delay.queue.core.ConsumeQueueProvider;
19 | import io.mykit.delay.starter.ready.StartGetReady;
20 | import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
21 | import org.springframework.boot.SpringApplication;
22 | import org.springframework.boot.autoconfigure.SpringBootApplication;
23 |
24 | /**
25 | * @author binghe
26 | * @version 1.0.0
27 | * @description 启动类
28 | */
29 | @EnableDubbo
30 | @SpringBootApplication
31 | public class MykitDelayServer {
32 | public static void main(String[] args){
33 | StartGetReady.ready(ConsumeQueueProvider.class.getName());
34 | SpringApplication.run(MykitDelayServer.class, args);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/mykit-delay-rpc/mykit-rpc-dubbo/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | mykit-delay-rpc
7 | io.mykit.delay
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | mykit-rpc-dubbo
13 | pom
14 |
15 | mykit-rpc-dubbo-xml
16 | mykit-rpc-dubbo-common
17 | mykit-rpc-dubbo-server
18 |
19 |
20 |
21 | UTF-8
22 | 2.7.8
23 | 4.0.1
24 |
25 |
26 |
27 |
28 | org.apache.dubbo
29 | dubbo
30 | ${dubbo.version}
31 |
32 |
33 | spring
34 | org.springframework
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/mykit-delay-common/src/main/java/io/mykit/delay/common/utils/BlockUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.utils;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/29
22 | * @description 块工具
23 | */
24 | public final class BlockUtils {
25 |
26 | public static final long DEF_SLEEP_TIMES = 100L;
27 |
28 | public static void waitingShortTime() {
29 | sleep(DEF_SLEEP_TIMES);
30 | }
31 |
32 | public static void sleep(final long millis, final boolean isInterrupt) {
33 | try {
34 | Thread.sleep(millis);
35 | } catch (final InterruptedException ex) {
36 | if (isInterrupt) {
37 | Thread.currentThread().interrupt();
38 | }
39 |
40 | }
41 | }
42 |
43 | public static void sleep(final long millis) {
44 | sleep(millis, false);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/cqp/RocketMQConsumeQueue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.cqp;
17 |
18 | import io.mykit.delay.common.autoconfigigure.message.MessageProducer;
19 | import io.mykit.delay.common.exception.ConsumeQueueException;
20 | import io.mykit.delay.queue.core.ConsumeQueueProvider;
21 | import io.mykit.delay.queue.core.Job;
22 | import io.mykit.delay.queue.extension.ExtNamed;
23 |
24 | /**
25 | * @author liuyazhuang
26 | * @version 1.0.0
27 | * @date 2019/5/29
28 | * @description RocketMQ消费队列实现
29 | */
30 | @ExtNamed("rocketmqCQ")
31 | public class RocketMQConsumeQueue implements ConsumeQueueProvider {
32 |
33 | @Override
34 | public void init() {
35 |
36 | }
37 |
38 | @Override
39 | public void consumer(Job job) throws ConsumeQueueException {
40 | MessageProducer.send(job);
41 | }
42 |
43 | @Override
44 | public void destory() {
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/redis/support/DistributedLock.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.redis.support;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/30
22 | * @description 分布式锁
23 | */
24 | public interface DistributedLock {
25 |
26 | /**
27 | * 尝试加锁
28 | * @param key 加锁的key
29 | * @return 尝试加锁成功返回true; 失败返回false
30 | */
31 | boolean tryLock(String key);
32 |
33 | /**
34 | * 尝试加锁
35 | * @param key 加锁的key
36 | * @param timeout 超时时间
37 | * @return 尝试加锁成功返回true; 失败返回false
38 | */
39 | boolean tryLock(String key, long timeout);
40 |
41 | /**
42 | * 加锁操作
43 | * @param key 加锁的key
44 | * @return 加锁成功返回true; 失败返回false
45 | */
46 | boolean lock(String key);
47 | /**
48 | * 解锁操作
49 | * @param key 解锁的key
50 | * @return 解锁成功返回true; 失败返回false
51 | */
52 | void unlock(String key);
53 | }
54 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/redis/event/RedisJobTraceEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.redis.event;
17 |
18 | import io.mykit.delay.common.utils.RdbOperation;
19 | import io.mykit.delay.queue.JobMsg;
20 |
21 | /**
22 | * @author liuyazhuang
23 | * @version 1.0.0
24 | * @date 2019/5/30
25 | * @description Redis Job 栈事件
26 | */
27 | public class RedisJobTraceEvent implements JobEvent {
28 |
29 | private JobMsg jobMsg = null;
30 | private RdbOperation operation = RdbOperation.UPDATE;
31 |
32 | public RedisJobTraceEvent(JobMsg jobMsg) {
33 | this.jobMsg = jobMsg;
34 | }
35 |
36 | public RedisJobTraceEvent(JobMsg jobMsg, RdbOperation operation) {
37 | this.jobMsg = jobMsg;
38 | this.operation = operation;
39 | }
40 |
41 | @Override
42 | public JobMsg getJob() {
43 | return jobMsg;
44 | }
45 |
46 | public RdbOperation getOperation() {
47 | return operation;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/leader/LeaderWorkListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.rpc.dubbo;
17 |
18 | import io.mykit.delay.common.utils.ResponseMessage;
19 | import io.mykit.delay.queue.redis.JobWrapp;
20 |
21 | /**
22 | * @author binghe
23 | * @version 1.0.0
24 | * @description 发布的Dubbo接口
25 | */
26 | public interface MykitDelayDubboInterface {
27 |
28 | /**
29 | * 推送消息
30 | */
31 | ResponseMessage push(JobWrapp jobMsg);
32 |
33 | /**
34 | * 删除任务
35 | */
36 | ResponseMessage delete(String jobId);
37 |
38 |
39 | /**
40 | * 完成任务
41 | */
42 | ResponseMessage finish(String jobId);
43 |
44 | /**
45 | * 恢复单个任务
46 | */
47 | ResponseMessage reStoreJob(String jobId);
48 |
49 | /**
50 | * 提供一个方法 假设缓存中间件出现异常 以及数据错乱的情况 提供恢复功能
51 | * @param expire 过期的数据是否需要重发 true需要, false不需要 默认为true
52 | */
53 | ResponseMessage reStore(Boolean expire);
54 |
55 | /**
56 | * 清除所有的任务
57 | */
58 | ResponseMessage clearAll();
59 | }
60 |
--------------------------------------------------------------------------------
/mykit-delay-config/src/main/java/io/mykit/delay/starter/ready/MykitDelayFileLoad.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.starter.ready;
17 |
18 | import java.io.IOException;
19 | import java.io.InputStream;
20 | import java.util.Properties;
21 |
22 | /**
23 | * @author liuyazhuang
24 | * @version 1.0.0
25 | * @date 2019/5/31
26 | * @description 加载Properties文件
27 | */
28 | public class MykitDelayFileLoad {
29 |
30 | public static final String LOG_PATH = "log.path";
31 | public static final String CLASS_PATH = "class.path";
32 | public static final String DEFAULT_CQ = "default.cq";
33 |
34 | private volatile static Properties mProperties;
35 |
36 | static{
37 | mProperties = new Properties();
38 | InputStream in = MykitDelayFileLoad.class.getClassLoader().getResourceAsStream("properties/starter.properties");
39 | try {
40 | mProperties.load(in);
41 | } catch (IOException e) {
42 | e.printStackTrace();
43 | }
44 | }
45 |
46 | public static String getStringValue(String key){
47 | return mProperties.getProperty(key, "");
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/mykit-delay-rpc/mykit-rpc-dubbo/mykit-rpc-dubbo-xml/src/main/java/io/mykit/delay/MykitDelayServer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2020-9999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay;
17 |
18 | import org.slf4j.Logger;
19 | import org.slf4j.LoggerFactory;
20 | import org.springframework.context.support.ClassPathXmlApplicationContext;
21 |
22 | import java.io.BufferedReader;
23 | import java.io.InputStreamReader;
24 |
25 | /**
26 | * @author binghe
27 | * @version 1.0.0
28 | * @description Dubbo服务
29 | */
30 | public class MykitDelayServer {
31 | private static final Logger LOGGER = LoggerFactory.getLogger(MykitDelayServer.class);
32 | public static void main(String[] args){
33 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/mykit-delay-server-main.xml");
34 | context.start();
35 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
36 | try{
37 | while (!"exit".equals(br.readLine())){
38 | Thread.sleep(60000);
39 | }
40 | }catch (Exception e){
41 | LOGGER.error("启动mykit-rpc-dubbo-xml服务失败 {}", e);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/common/autoconfigigure/message/rocketmq/RocketMQProperties.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.autoconfigigure.message.rocketmq;
17 |
18 | import org.springframework.boot.context.properties.ConfigurationProperties;
19 |
20 | /**
21 | * @author liuyazhuang
22 | * @version 1.0.0
23 | * @date 2019/5/29
24 | * @description RocketMQ属性信息
25 | */
26 | @ConfigurationProperties(prefix = RocketMQProperties.MYKIT_DELAY_ROCKETMQ_PREFIX)
27 | public class RocketMQProperties {
28 | public static final String MYKIT_DELAY_ROCKETMQ_PREFIX = "mykit.delay.rocketmq";
29 | private String namesrvAddr;
30 | private String filterSourceRoot = "/home/";
31 |
32 | public String getNamesrvAddr() {
33 | return namesrvAddr;
34 | }
35 |
36 | public void setNamesrvAddr(String namesrvAddr) {
37 | this.namesrvAddr = namesrvAddr;
38 | }
39 |
40 | public String getFilterSourceRoot() {
41 | return filterSourceRoot;
42 | }
43 |
44 | public void setFilterSourceRoot(String filterSourceRoot) {
45 | this.filterSourceRoot = filterSourceRoot;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/redis/event/RedisJobEventListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.redis.event;
17 |
18 | import io.mykit.delay.common.utils.RdbOperation;
19 | import io.mykit.delay.common.utils.Status;
20 | import io.mykit.delay.queue.JobMsg;
21 | import io.mykit.delay.queue.redis.RdbStore;
22 |
23 | /**
24 | * @author liuyazhuang
25 | * @version 1.0.0
26 | * @date 2019/5/30
27 | * @description Redis Job事件监听器
28 | */
29 | public class RedisJobEventListener implements JobEventListener {
30 |
31 | private RdbStore store;
32 |
33 | @Override
34 | public void listen(JobEvent event) {
35 | if (event instanceof RedisJobTraceEvent) {
36 | RedisJobTraceEvent e = (RedisJobTraceEvent) event;
37 | JobMsg job = e.getJob();
38 | if (e.getOperation() == RdbOperation.INSERT && job.getStatus() != Status.Restore.ordinal()) {
39 | store.insertJob(job);
40 | } else {
41 | store.updateJobsStatus(job);
42 | }
43 | }
44 | }
45 |
46 | public void setStore(RdbStore store) {
47 | this.store = store;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/mykit-delay-common/src/main/java/io/mykit/delay/common/utils/Constants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.utils;
17 |
18 | /**
19 | * @author liuyazhuang
20 | * @version 1.0.0
21 | * @date 2019/5/29
22 | * @description 系统常量类
23 | */
24 | public class Constants {
25 |
26 | public static final String USER_DIR = "user.dir";
27 | public static String SOFT_HOME_KEY = "soft.home";
28 | public static String SOFT_LOG_HOME_KEY = "soft.logs";
29 | public static String SOFT_HOME = System.getProperty(SOFT_HOME_KEY);
30 | public static String SOFT_LOG_HOME = System.getProperty(SOFT_LOG_HOME_KEY);
31 |
32 | public static final String HEALTH_INDICATOR_NAME = "mykit-delay";
33 | public static final String CODE_UTF8 = "UTF-8";
34 | public static final String RUN = "run";
35 | public static final String IS_CLUSTER = "isCluster";
36 | public static final String BUCKET_SIZE = "bucketSize";
37 | public static final String PREFIX = "prefix";
38 | public static final String NAMESPACE = "namespace";
39 | public static final String IS_MASTER = "isMaster";
40 | public static final String MYKIT_DELAY_REGISTRY_ENABLE = "mykit.delay.registry.enable";
41 | }
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/queue/cqp/ConsoleConsumeQueue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.queue.cqp;
17 |
18 | import io.mykit.delay.common.exception.ConsumeQueueException;
19 | import io.mykit.delay.common.utils.FastJsonConvert;
20 | import io.mykit.delay.queue.core.ConsumeQueueProvider;
21 | import io.mykit.delay.queue.core.Job;
22 | import io.mykit.delay.queue.extension.ExtNamed;
23 | import org.slf4j.Logger;
24 | import org.slf4j.LoggerFactory;
25 |
26 | /**
27 | * @author liuyazhuang
28 | * @version 1.0.0
29 | * @date 2019/5/29
30 | * @description 控制台消费队列实现
31 | */
32 | @ExtNamed("consoleCQ")
33 | public class ConsoleConsumeQueue implements ConsumeQueueProvider {
34 | private final Logger logger = LoggerFactory.getLogger(ConsoleConsumeQueue.class);
35 | @Override
36 | public void init() {
37 |
38 | }
39 |
40 | @Override
41 | public void consumer(Job job) throws ConsumeQueueException {
42 | System.out.println(String.format("invoke topic %s json:%s", job.getTopic(), FastJsonConvert.convertObjectToJSON(job)));
43 | logger.info(String.format("invoke topic %s json:%s", job.getTopic(), FastJsonConvert.convertObjectToJSON(job)));
44 | }
45 |
46 | @Override
47 | public void destory() {
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/mykit-delay-queue/src/main/java/io/mykit/delay/common/listener/FailedEventListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.listener;
17 |
18 | import io.mykit.delay.queue.redis.RedisQueue;
19 | import io.mykit.delay.queue.redis.RedisQueueImpl;
20 | import org.springframework.boot.context.event.ApplicationFailedEvent;
21 | import org.springframework.context.ApplicationContext;
22 | import org.springframework.context.ApplicationListener;
23 | import org.springframework.context.annotation.Configuration;
24 |
25 | /**
26 | * @author liuyazhuang
27 | * @version 1.0.0
28 | * @date 2019/5/29
29 | * @description 失败事件监听器
30 | */
31 | @Configuration
32 | public class FailedEventListener implements ApplicationListener {
33 | @Override
34 | public void onApplicationEvent(ApplicationFailedEvent event) {
35 | Throwable throwable = event.getException();
36 | handler(throwable, event);
37 | }
38 |
39 | private void handler(Throwable throwable, ApplicationFailedEvent event) {
40 | ApplicationContext ctx = event.getApplicationContext();
41 | if (ctx != null) {
42 | RedisQueue redisQueue = ctx.getBean(RedisQueueImpl.class);
43 | if (redisQueue != null && redisQueue.isRunning()) {
44 | redisQueue.stop();
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/mykit-delay-common/src/main/java/io/mykit/delay/common/utils/NamedUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019-2999 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.mykit.delay.common.utils;
17 |
18 | import com.google.common.base.Joiner;
19 |
20 | import java.util.List;
21 | import com.google.common.collect.Lists;
22 |
23 |
24 | /**
25 | * @author liuyazhuang
26 | * @version 1.0.0
27 | * @date 2019/5/29
28 | * @description 名称工具类
29 | */
30 | public class NamedUtil {
31 | public static final String SPLITE_CHAR = ":";
32 | public static final String LOCK_CHAR = "LOCK";
33 |
34 | public static String buildBucketName(String prefix, String name, int index) {
35 | List