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 |
17 | package cc.uncarbon.framework.rocketmq.annotation;
18 |
19 | import cc.uncarbon.framework.rocketmq.core.producer.DefaultSendCallback;
20 | import cc.uncarbon.framework.rocketmq.core.producer.MessageSendType;
21 | import com.aliyun.openservices.ons.api.SendCallback;
22 |
23 | import java.lang.annotation.*;
24 |
25 | /**
26 | * ClassName: CommonMessage
27 | * Description:
28 | * date: 2019/5/3 11:16
29 | *
30 | * @author ThierrySquirrel
31 | * @since JDK 1.8
32 | */
33 | @Target(ElementType.METHOD)
34 | @Retention(RetentionPolicy.RUNTIME)
35 | @Inherited
36 | @Documented
37 | public @interface CommonMessage {
38 | /**
39 | * Message 所属的 Topic
40 | *
41 | * @return String
42 | */
43 | String topic() default "";
44 |
45 | /**
46 | * 订阅指定 Topic 下的 Tags:
47 | * 1. * 表示订阅所有消息
48 | * 2. TagA || TagB || TagC 表示订阅 TagA 或 TagB 或 TagC 的消息
49 | *
50 | * @return String
51 | */
52 | String tag() default "*";
53 |
54 | /**
55 | * 消息发送类型 默认异步
56 | *
57 | * @return MessageSendType
58 | */
59 | MessageSendType messageSendType() default MessageSendType.SEND_ASYNC;
60 |
61 | /**
62 | * 自定义SendCallback类
63 | *
64 | * @return callback
65 | */
66 | Class extends SendCallback> callback() default DefaultSendCallback.class;
67 | }
68 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/annotation/MessageListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.annotation;
18 |
19 |
20 | import java.lang.annotation.*;
21 |
22 | /**
23 | * ClassName: OrderMessage
24 | * Description:
25 | * date: 2019/4/27 21:36
26 | *
27 | * @author ThierrySquirrel
28 | * @since JDK 1.8
29 | */
30 | @Target(ElementType.METHOD)
31 | @Retention(RetentionPolicy.RUNTIME)
32 | @Inherited
33 | @Documented
34 | public @interface OrderMessage {
35 | /**
36 | * Message 所属的 Topic
37 | *
38 | * @return String
39 | */
40 | String topic() default "";
41 |
42 | /**
43 | * 订阅指定 Topic 下的 Tags:
44 | * 1. * 表示订阅所有消息
45 | * 2. TagA || TagB || TagC 表示订阅 TagA 或 TagB 或 TagC 的消息
46 | *
47 | * @return String
48 | */
49 | String tag() default "*";
50 | }
51 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/annotation/RocketListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.annotation;
18 |
19 | import com.aliyun.openservices.ons.api.PropertyValueConst;
20 | import java.lang.annotation.Documented;
21 | import java.lang.annotation.ElementType;
22 | import java.lang.annotation.Inherited;
23 | import java.lang.annotation.Retention;
24 | import java.lang.annotation.RetentionPolicy;
25 | import java.lang.annotation.Target;
26 | import org.springframework.stereotype.Component;
27 |
28 | /**
29 | * ClassName: RocketListener
30 | * Description:
31 | * date: 2019/4/26 21:35
32 | *
33 | * @author ThierrySquirrel
34 | * @since JDK 1.8
35 | */
36 | @Target(ElementType.TYPE)
37 | @Retention(RetentionPolicy.RUNTIME)
38 | @Inherited
39 | @Documented
40 | @Component
41 | public @interface RocketListener {
42 | /**
43 | * 您在控制台创建的 Group ID
44 | *
45 | * @return String
46 | */
47 | String groupID() default "";
48 |
49 | /**
50 | * 消费模式,默认集群消费
51 | *
52 | * @return String
53 | */
54 | String messageModel() default PropertyValueConst.CLUSTERING;
55 |
56 | /**
57 | * 消费线程数量,特定需求可以单独指定,默认同配置文件
58 | *
59 | * @return String
60 | */
61 | String consumeThreadNums();
62 |
63 | /**
64 | * 一次最大拉取消费数量,特定需求可以单独指定,默认同配置文件
65 | *
66 | * @return String
67 | */
68 | String consumeBatchSize();
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/annotation/RocketMessage.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.annotation;
18 |
19 | import org.springframework.stereotype.Component;
20 |
21 | import java.lang.annotation.*;
22 |
23 | /**
24 | * ClassName: RocketMessage
25 | * Description:
26 | * date: 2019/4/26 21:36
27 | *
28 | * @author ThierrySquirrel
29 | * @since JDK 1.8
30 | */
31 | @Target(ElementType.TYPE)
32 | @Retention(RetentionPolicy.RUNTIME)
33 | @Inherited
34 | @Component
35 | @Documented
36 | public @interface RocketMessage {
37 | /**
38 | * 您在控制台创建的 Group ID
39 | *
40 | * @return String
41 | */
42 | String groupID() default "";
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/annotation/ShardingKey.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2021 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 cc.uncarbon.framework.rocketmq.annotation;
17 |
18 | import java.lang.annotation.*;
19 |
20 | /**
21 | * Classname: ShardingKey
22 | * Description:
23 | * Date: 2021/11/3 19:57
24 | *
25 | * @author ThierrySquirrel
26 | * @since JDK 11
27 | */
28 | @Target({ElementType.PARAMETER})
29 | @Retention(RetentionPolicy.RUNTIME)
30 | @Documented
31 | @Inherited
32 | public @interface ShardingKey {
33 | }
34 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/annotation/StartDeliverTime.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2020 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 |
17 | package cc.uncarbon.framework.rocketmq.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * ClassName: StartDeliverTime
23 | * Description:
24 | * date: 2020/1/29 19:05
25 | *
26 | * @author ThierrySquirrel
27 | * @since JDK 1.8
28 | */
29 | @Target({ElementType.PARAMETER})
30 | @Retention(RetentionPolicy.RUNTIME)
31 | @Documented
32 | @Inherited
33 | public @interface StartDeliverTime {
34 | }
35 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/annotation/TransactionMessage.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.container;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.RocketMessage;
20 | import cc.uncarbon.framework.rocketmq.core.factory.ThreadPoolFactory;
21 | import cc.uncarbon.framework.rocketmq.core.strategy.RocketConsumerStrategy;
22 | import cc.uncarbon.framework.rocketmq.props.AliyunRocketProperties;
23 | import jakarta.annotation.PostConstruct;
24 | import lombok.NonNull;
25 | import org.springframework.context.ApplicationContext;
26 | import org.springframework.context.ApplicationContextAware;
27 |
28 | import java.util.Map;
29 | import java.util.concurrent.ThreadPoolExecutor;
30 |
31 | /**
32 | * ClassName: RocketProducerContainer
33 | * Description:
34 | * date: 2019/5/3 11:29
35 | *
36 | * @author ThierrySquirrel
37 | * @since JDK 1.8
38 | */
39 | public class RocketProducerContainer implements ApplicationContextAware {
40 |
41 | private ApplicationContext applicationContext;
42 |
43 | private final AliyunRocketProperties rocketProperties;
44 |
45 | private final Map consumerContainer;
46 |
47 |
48 | public RocketProducerContainer(Map consumerContainer, AliyunRocketProperties rocketProperties) {
49 | this.consumerContainer = consumerContainer;
50 | this.rocketProperties = rocketProperties;
51 | }
52 |
53 | @PostConstruct
54 | public void initialize() {
55 | // 创建临时线程池
56 | ThreadPoolExecutor threadPoolExecutor = ThreadPoolFactory.createProducerThreadPoolExecutor(rocketProperties);
57 | // 扫描标记 @RocketMessage 注解的类,再将其中标记了 @CommonMessage/@OrderMessage/@TransactionMessage 的方法包装一下
58 | // 依次注册到阿里云SDK
59 | applicationContext.getBeansWithAnnotation(RocketMessage.class)
60 | .forEach((beanName, bean) -> RocketConsumerStrategy.putProducer(threadPoolExecutor, consumerContainer, bean, rocketProperties, applicationContext));
61 | // 销毁临时线程池
62 | threadPoolExecutor.shutdown();
63 | }
64 |
65 | @Override
66 | public void setApplicationContext(@NonNull ApplicationContext applicationContext) {
67 | this.applicationContext = applicationContext;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/consumer/AbstractRocketListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.consumer;
18 |
19 | import cc.uncarbon.framework.rocketmq.core.factory.execution.MethodFactoryExecution;
20 | import lombok.Data;
21 | import lombok.extern.slf4j.Slf4j;
22 |
23 | /**
24 | * ClassName: AbstractRocketListener
25 | * Description:
26 | * date: 2019/4/27 17:07
27 | *
28 | * @author ThierrySquirrel
29 | * @since JDK 1.8
30 | */
31 | @Data
32 | @Slf4j
33 | public abstract class AbstractRocketListener {
34 | private MethodFactoryExecution methodFactoryExecution;
35 |
36 | protected AbstractRocketListener(MethodFactoryExecution methodFactoryExecution) {
37 | this.methodFactoryExecution = methodFactoryExecution;
38 | }
39 |
40 | public void printErrorLog() {
41 | log.error("Consumer agent failed!bean:{},method:{}",
42 | methodFactoryExecution.getBean(),
43 | methodFactoryExecution.getMethod());
44 | }
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/consumer/DefaultBatchMessageListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2020 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 cc.uncarbon.framework.rocketmq.core.consumer;
17 |
18 | import cc.uncarbon.framework.rocketmq.core.factory.execution.MethodFactoryExecution;
19 | import cc.uncarbon.framework.rocketmq.exception.RocketException;
20 | import com.aliyun.openservices.ons.api.Action;
21 | import com.aliyun.openservices.ons.api.ConsumeContext;
22 | import com.aliyun.openservices.ons.api.Message;
23 | import com.aliyun.openservices.ons.api.batch.BatchMessageListener;
24 | import lombok.extern.slf4j.Slf4j;
25 |
26 | import java.util.List;
27 |
28 | /**
29 | * ClassName: DefaultBatchMessageListener
30 | * Description:
31 | * date: 2020/12/8 9:08
32 | *
33 | * @author ThierrySquirrel
34 | * @since JDK 1.8
35 | */
36 | @Slf4j
37 | public class DefaultBatchMessageListener extends AbstractRocketListener implements BatchMessageListener {
38 | public DefaultBatchMessageListener(MethodFactoryExecution methodFactoryExecution) {
39 | super(methodFactoryExecution);
40 | }
41 |
42 | /**
43 | * 批量消费消息接口,由应用来实现
44 | * 需要注意网络抖动等不稳定的情形可能会带来消息重复,对重复消息敏感的业务可对消息做幂等处理
45 | *
46 | * @param messages 一批消息
47 | * @param context 消费上下文
48 | * @return {@link Action} 消费结果,如果应用抛出异常或者返回Null等价于返回Action.ReconsumeLater
49 | * @see 如何做到消费幂等
50 | */
51 | @Override
52 | public Action consume(List messages, ConsumeContext context) {
53 | log.info(">>>>messageList:{}>>>>", messages);
54 | try {
55 | for (Message message : messages) {
56 | super.getMethodFactoryExecution().methodExecution(message.getBody());
57 | }
58 | } catch (RocketException e) {
59 | super.printErrorLog();
60 | return Action.ReconsumeLater;
61 | }
62 | return Action.CommitMessage;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/consumer/DefaultMessageListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.consumer;
18 |
19 | import cc.uncarbon.framework.rocketmq.core.factory.execution.MethodFactoryExecution;
20 | import cc.uncarbon.framework.rocketmq.exception.RocketException;
21 | import com.aliyun.openservices.ons.api.Action;
22 | import com.aliyun.openservices.ons.api.ConsumeContext;
23 | import com.aliyun.openservices.ons.api.Message;
24 | import com.aliyun.openservices.ons.api.MessageListener;
25 | import lombok.extern.slf4j.Slf4j;
26 |
27 | /**
28 | * ClassName: DefaultMessageListener
29 | * Description:
30 | * date: 2019/4/27 17:05
31 | *
32 | * @author ThierrySquirrel
33 | * @since JDK 1.8
34 | */
35 | @Slf4j
36 | public class DefaultMessageListener extends AbstractRocketListener implements MessageListener {
37 |
38 | public DefaultMessageListener(MethodFactoryExecution methodFactoryExecution) {
39 | super(methodFactoryExecution);
40 | }
41 |
42 | /**
43 | * 消费消息接口,由应用来实现
44 | * 网络抖动等不稳定的情形可能会带来消息重复,对重复消息敏感的业务可对消息做幂等处理
45 | *
46 | * @param message 消息
47 | * @param context 消费上下文
48 | * @return 消费结果,如果应用抛出异常或者返回Null等价于返回Action.ReconsumeLater
49 | * @see 如何做到消费幂等
50 | */
51 | @Override
52 | public Action consume(Message message, ConsumeContext context) {
53 | log.info(">>>>message:{}>>>>", message);
54 | try {
55 | super.getMethodFactoryExecution().methodExecution(message.getBody());
56 | } catch (RocketException e) {
57 | super.printErrorLog();
58 | return Action.ReconsumeLater;
59 | }
60 | return Action.CommitMessage;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/consumer/DefaultMessageOrderListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.consumer;
18 |
19 | import cc.uncarbon.framework.rocketmq.core.factory.execution.MethodFactoryExecution;
20 | import cc.uncarbon.framework.rocketmq.exception.RocketException;
21 | import com.aliyun.openservices.ons.api.Message;
22 | import com.aliyun.openservices.ons.api.order.ConsumeOrderContext;
23 | import com.aliyun.openservices.ons.api.order.MessageOrderListener;
24 | import com.aliyun.openservices.ons.api.order.OrderAction;
25 | import lombok.extern.slf4j.Slf4j;
26 |
27 | /**
28 | * ClassName: DefaultMessageOrderListener
29 | * Description:
30 | * date: 2019/4/26 23:16
31 | *
32 | * @author ThierrySquirrel
33 | * @since JDK 1.8
34 | */
35 |
36 | @Slf4j
37 | public class DefaultMessageOrderListener extends AbstractRocketListener implements MessageOrderListener {
38 |
39 |
40 | public DefaultMessageOrderListener(MethodFactoryExecution methodFactoryExecution) {
41 | super(methodFactoryExecution);
42 | }
43 |
44 | /**
45 | * 消费消息接口,由应用来实现
46 | * 需要注意网络抖动等不稳定的情形可能会带来消息重复,对重复消息敏感的业务可对消息做幂等处理
47 | *
48 | * @param message 消息
49 | * @param context 消费上下文
50 | * @return {@link OrderAction} 消费结果,如果应用抛出异常或者返回Null等价于返回Action.ReconsumeLater
51 | * @see 如何做到消费幂等
52 | */
53 | @Override
54 | public OrderAction consume(Message message, ConsumeOrderContext context) {
55 | log.info(">>>> Order message:{}>>>>", message);
56 | try {
57 | super.getMethodFactoryExecution().methodExecution(message.getBody());
58 | } catch (RocketException e) {
59 | super.printErrorLog();
60 | return OrderAction.Suspend;
61 | }
62 | return OrderAction.Success;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/ConsumerFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory;
18 |
19 | import com.aliyun.openservices.ons.api.Consumer;
20 | import com.aliyun.openservices.ons.api.ONSFactory;
21 | import com.aliyun.openservices.ons.api.batch.BatchConsumer;
22 | import com.aliyun.openservices.ons.api.order.OrderConsumer;
23 |
24 | import java.util.Properties;
25 |
26 |
27 | /**
28 | * ClassName: ConsumerFactory
29 | * Description:
30 | * date: 2019/4/27 15:55
31 | *
32 | * @author ThierrySquirrel
33 | * @since JDK 1.8
34 | */
35 | public final class ConsumerFactory {
36 | private ConsumerFactory() {
37 | }
38 |
39 | public static Consumer createConsumer(Properties properties) {
40 | return ONSFactory.createConsumer(properties);
41 | }
42 |
43 |
44 | public static OrderConsumer createOrderConsumer(Properties properties) {
45 | return ONSFactory.createOrderedConsumer(properties);
46 | }
47 |
48 | public static BatchConsumer createBatchConsumer(Properties properties) {
49 | return ONSFactory.createBatchConsumer(properties);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/ConsumerPropertiesFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.RocketListener;
20 | import cc.uncarbon.framework.rocketmq.props.AliyunRocketProperties;
21 | import com.aliyun.openservices.ons.api.PropertyKeyConst;
22 | import java.util.Objects;
23 | import java.util.Properties;
24 |
25 | /**
26 | * ClassName: ConsumerPropertiesFactory
27 | * Description:
28 | * date: 2019/4/27 15:37
29 | *
30 | * @author ThierrySquirrel
31 | * @since JDK 1.8
32 | */
33 | public final class ConsumerPropertiesFactory {
34 | private ConsumerPropertiesFactory() {
35 | }
36 |
37 | public static Properties createConsumerProperties(AliyunRocketProperties rocketProperties,
38 | RocketListener rocketListener) {
39 |
40 | Properties properties = PropertiesFactory.createProperties(rocketProperties);
41 |
42 | properties.put(PropertyKeyConst.GROUP_ID, rocketListener.groupID());
43 | properties.put(PropertyKeyConst.MessageModel, rocketListener.messageModel());
44 | properties.put(PropertyKeyConst.ConsumeThreadNums,
45 | // 消费线程数量,特定需求可以单独指定
46 | Objects.nonNull(rocketListener.consumeThreadNums()) ? rocketListener.consumeThreadNums()
47 | : rocketProperties.getConsumeThreadNums());
48 | properties.put(PropertyKeyConst.MaxReconsumeTimes, rocketProperties.getMaxReconsumeTimes());
49 | properties.put(PropertyKeyConst.ConsumeTimeout, rocketProperties.getConsumeTimeout());
50 |
51 | if (Objects.nonNull(rocketListener.consumeBatchSize())) {
52 | // 一次最大拉取消费数量,特定需求可以单独指定
53 | properties.put(PropertyKeyConst.MAX_BATCH_MESSAGE_COUNT, rocketListener.consumeBatchSize());
54 | }
55 |
56 | return properties;
57 |
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/MessageFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.CommonMessage;
20 | import cc.uncarbon.framework.rocketmq.annotation.OrderMessage;
21 | import cc.uncarbon.framework.rocketmq.annotation.TransactionMessage;
22 | import com.aliyun.openservices.ons.api.Message;
23 |
24 | /**
25 | * ClassName: MessageFactory
26 | * Description:
27 | * date: 2019/4/28 21:55
28 | *
29 | * @author ThierrySquirrel
30 | * @since JDK 1.8
31 | */
32 | public final class MessageFactory {
33 | private MessageFactory() {
34 | }
35 |
36 | public static Message createMessage(CommonMessage commonMessage, byte[] body) {
37 | return new Message(commonMessage.topic(),
38 | commonMessage.tag(),
39 | body);
40 | }
41 |
42 | public static Message createMessage(OrderMessage orderMessage, byte[] body) {
43 | return new Message(orderMessage.topic(),
44 | orderMessage.tag(),
45 | body);
46 | }
47 |
48 | public static Message createMessage(TransactionMessage transactionMessage, byte[] body) {
49 | return new Message(transactionMessage.topic(),
50 | transactionMessage.tag(),
51 | body);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/MethodFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory;
18 |
19 | import java.lang.reflect.Method;
20 |
21 | /**
22 | * ClassName: MethodFactory
23 | * Description:
24 | * date: 2019/4/27 16:13
25 | *
26 | * @author ThierrySquirrel
27 | * @since JDK 1.8
28 | */
29 |
30 | public final class MethodFactory {
31 | private MethodFactory() {
32 | }
33 |
34 | public static Class> getMethodParameter(Method method) {
35 | return method.getParameterTypes()[0];
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/ProducerFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.RocketMessage;
20 | import cc.uncarbon.framework.rocketmq.props.AliyunRocketProperties;
21 | import com.aliyun.openservices.ons.api.ONSFactory;
22 | import com.aliyun.openservices.ons.api.Producer;
23 | import com.aliyun.openservices.ons.api.PropertyKeyConst;
24 | import com.aliyun.openservices.ons.api.order.OrderProducer;
25 | import com.aliyun.openservices.ons.api.transaction.LocalTransactionChecker;
26 | import com.aliyun.openservices.ons.api.transaction.TransactionProducer;
27 |
28 | import java.util.Properties;
29 |
30 | /**
31 | * ClassName: ProducerFactory
32 | * Description:
33 | * date: 2019/4/28 21:35
34 | *
35 | * @author ThierrySquirrel
36 | * @since JDK 1.8
37 | */
38 | public final class ProducerFactory {
39 | private ProducerFactory() {
40 | }
41 |
42 | public static Producer createProducer(RocketMessage rocketMessage, AliyunRocketProperties rocketProperties) {
43 | Properties properties = ProducerPropertiesFactory.createProducerProperties(rocketMessage, rocketProperties);
44 | return ONSFactory.createProducer(properties);
45 | }
46 |
47 | public static OrderProducer createOrderProducer(RocketMessage rocketMessage, AliyunRocketProperties rocketProperties) {
48 | Properties properties = ProducerPropertiesFactory.createProducerProperties(rocketMessage, rocketProperties);
49 | return ONSFactory.createOrderProducer(properties);
50 | }
51 |
52 | public static TransactionProducer createTransactionProducer(RocketMessage rocketMessage, AliyunRocketProperties rocketProperties, LocalTransactionChecker localTransactionChecker) {
53 | Properties properties = ProducerPropertiesFactory.createProducerProperties(rocketMessage, rocketProperties);
54 | properties.put(PropertyKeyConst.CheckImmunityTimeInSeconds, rocketProperties.getCheckImmunityTimeInSeconds());
55 | return ONSFactory.createTransactionProducer(properties, localTransactionChecker);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/ProducerPropertiesFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.RocketMessage;
20 | import cc.uncarbon.framework.rocketmq.props.AliyunRocketProperties;
21 | import com.aliyun.openservices.ons.api.PropertyKeyConst;
22 |
23 | import java.util.Properties;
24 |
25 | /**
26 | * ClassName: ProducerPropertiesFactory
27 | * Description:
28 | * date: 2019/4/28 21:21
29 | *
30 | * @author ThierrySquirrel
31 | * @since JDK 1.8
32 | */
33 | public final class ProducerPropertiesFactory {
34 | private ProducerPropertiesFactory() {
35 | }
36 |
37 | public static Properties createProducerProperties(RocketMessage rockerMessage, AliyunRocketProperties rocketProperties) {
38 | Properties properties = PropertiesFactory.createProperties(rocketProperties);
39 | properties.put(PropertyKeyConst.SendMsgTimeoutMillis, rocketProperties.getSendMsgTimeoutMillis());
40 | properties.put(PropertyKeyConst.GROUP_ID, rockerMessage.groupID());
41 | return properties;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/PropertiesFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory;
18 |
19 | import cc.uncarbon.framework.rocketmq.props.AliyunRocketProperties;
20 | import com.aliyun.openservices.ons.api.PropertyKeyConst;
21 |
22 | import java.util.Properties;
23 |
24 | /**
25 | * ClassName: PropertiesFactory
26 | * Description:
27 | * date: 2019/4/27 20:26
28 | *
29 | * @author ThierrySquirrel
30 | * @since JDK 1.8
31 | */
32 | public final class PropertiesFactory {
33 | private PropertiesFactory() {
34 | }
35 |
36 | public static Properties createProperties(AliyunRocketProperties rocketProperties) {
37 | Properties properties = new Properties();
38 | properties.put(PropertyKeyConst.NAMESRV_ADDR, rocketProperties.getNameSrvAddr());
39 | properties.put(PropertyKeyConst.AccessKey, rocketProperties.getAccessKey());
40 | properties.put(PropertyKeyConst.SecretKey, rocketProperties.getSecretKey());
41 | properties.put(PropertyKeyConst.OnsChannel, rocketProperties.getOnsChannel());
42 |
43 | return properties;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/SendMessageFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.CommonMessage;
20 | import cc.uncarbon.framework.rocketmq.annotation.OrderMessage;
21 | import cc.uncarbon.framework.rocketmq.annotation.TransactionMessage;
22 | import cc.uncarbon.framework.rocketmq.core.strategy.SendMessageStrategy;
23 | import cc.uncarbon.framework.rocketmq.core.utils.ApplicationContextUtils;
24 | import com.aliyun.openservices.ons.api.Message;
25 | import com.aliyun.openservices.ons.api.Producer;
26 | import com.aliyun.openservices.ons.api.order.OrderProducer;
27 | import com.aliyun.openservices.ons.api.transaction.TransactionProducer;
28 | import org.springframework.context.ApplicationContext;
29 |
30 |
31 | /**
32 | * ClassName: SendMessageFactory
33 | * Description:
34 | * date: 2019/4/29 21:52
35 | *
36 | * @author ThierrySquirrel
37 | * @since JDK 1.8
38 | */
39 | public final class SendMessageFactory {
40 | private SendMessageFactory() {
41 | }
42 |
43 | public static void sendMessage(Long startDeliverTime, Producer producer, CommonMessage commonMessage, byte[] bytes, ApplicationContext applicationContext) {
44 | Message message = MessageFactory.createMessage(commonMessage, bytes);
45 | if (null != startDeliverTime) {
46 | message.setStartDeliverTime(startDeliverTime);
47 | }
48 | SendMessageStrategy.send(commonMessage, producer, message, applicationContext);
49 | }
50 |
51 | public static void sendMessage(OrderProducer orderProducer, OrderMessage orderMessage, byte[] bytes, String shardingKeyFactory) {
52 | Message message = MessageFactory.createMessage(orderMessage, bytes);
53 | orderProducer.send(message, shardingKeyFactory);
54 | }
55 |
56 | public static void sendMessage(TransactionProducer transactionProducer, TransactionMessage transactionMessage, byte[] bytes, ApplicationContext applicationContext) {
57 | Message message = MessageFactory.createMessage(transactionMessage, bytes);
58 | transactionProducer.send(message, ApplicationContextUtils.getLocalTransactionExecuter(applicationContext, transactionMessage.executor()), null);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/ShardingKeyFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2021 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 cc.uncarbon.framework.rocketmq.core.factory;
17 |
18 | import cc.uncarbon.framework.rocketmq.annotation.ShardingKey;
19 | import cn.hutool.core.util.ObjectUtil;
20 |
21 | import java.lang.reflect.Parameter;
22 |
23 | /**
24 | * Classname: ShardingKeyFactory
25 | * Description:
26 | * Date: 2021/11/3 20:00
27 | *
28 | * @author ThierrySquirrel
29 | * @since JDK 11
30 | */
31 | public final class ShardingKeyFactory {
32 | private ShardingKeyFactory() {
33 | }
34 |
35 | public static String getShardingKeyFactory(Object[] args, Parameter[] params) {
36 | for (int i = 0; i < args.length; i++) {
37 | ShardingKey annotation = params[i].getAnnotation(ShardingKey.class);
38 | if (ObjectUtil.isNotEmpty(annotation)) {
39 | return (String) args[i];
40 | }
41 | }
42 | return null;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/StartDeliverTimeFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2020 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.StartDeliverTime;
20 | import cn.hutool.core.util.ObjectUtil;
21 |
22 | import java.lang.reflect.Parameter;
23 |
24 | /**
25 | * ClassName: StartDeliverTimeFactory
26 | * Description:
27 | * date: 2020/1/29 19:07
28 | *
29 | * @author ThierrySquirrel
30 | * @since JDK 1.8
31 | */
32 | public final class StartDeliverTimeFactory {
33 |
34 | private StartDeliverTimeFactory() {
35 | }
36 |
37 | public static Long getStartDeliverTime(Object[] args, Parameter[] params) {
38 | for (int i = 0; i < args.length; i++) {
39 | StartDeliverTime annotation = params[i].getAnnotation(StartDeliverTime.class);
40 | if (ObjectUtil.isNotEmpty(annotation)) {
41 | return (Long) args[i];
42 | }
43 | }
44 | return null;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/execution/MethodFactoryExecution.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory.execution;
18 |
19 | import cc.uncarbon.framework.rocketmq.core.factory.MethodFactory;
20 | import cc.uncarbon.framework.rocketmq.core.serializer.RocketSerializer;
21 | import cc.uncarbon.framework.rocketmq.exception.RocketException;
22 | import lombok.AllArgsConstructor;
23 | import lombok.Data;
24 | import lombok.extern.slf4j.Slf4j;
25 |
26 | import java.lang.reflect.Method;
27 |
28 | /**
29 | * ClassName: MethodFactoryExecution
30 | * Description:
31 | * date: 2019/4/27 16:26
32 | *
33 | * @author ThierrySquirrel
34 | * @since JDK 1.8
35 | */
36 | @Slf4j
37 | @AllArgsConstructor
38 | @Data
39 | public class MethodFactoryExecution {
40 | private Object bean;
41 | private Method method;
42 | private RocketSerializer rocketSerializer;
43 |
44 | public void methodExecution(byte[] message) throws RocketException {
45 | try {
46 | Class> methodParameter = MethodFactory.getMethodParameter(method);
47 | Object methodParameterBean = rocketSerializer.deSerialize(message, methodParameter);
48 | method.invoke(bean, methodParameterBean);
49 | } catch (Exception e) {
50 | throw new RocketException(e);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/execution/ProducerFactoryExecution.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory.execution;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.RocketMessage;
20 | import cc.uncarbon.framework.rocketmq.core.strategy.PutProducerStrategy;
21 | import cc.uncarbon.framework.rocketmq.props.AliyunRocketProperties;
22 | import cc.uncarbon.framework.rocketmq.thread.AbstractProducerThread;
23 | import org.springframework.context.ApplicationContext;
24 |
25 | import java.util.Map;
26 |
27 | /**
28 | * ClassName: ProducerFactoryExecution
29 | * Description:
30 | * date: 2019/5/3 13:25
31 | *
32 | * @author ThierrySquirrel
33 | * @since JDK 1.8
34 | */
35 | public class ProducerFactoryExecution extends AbstractProducerThread {
36 |
37 | public ProducerFactoryExecution(Map producerConsumer, RocketMessage rocketMessage, Object bean,
38 | AliyunRocketProperties rocketProperties, ApplicationContext applicationContext) {
39 | super(producerConsumer, rocketMessage, bean, rocketProperties, applicationContext);
40 | }
41 |
42 | /**
43 | * 开始向容器装填
44 | *
45 | * @param producerConsumer producerConsumer
46 | * @param rocketMessage rocketMessage
47 | * @param bean bean
48 | * @param rocketProperties rocketProperties
49 | * @param applicationContext applicationContext
50 | */
51 | @Override
52 | protected void statsPutProducer(Map producerConsumer, RocketMessage rocketMessage, Object bean,
53 | AliyunRocketProperties rocketProperties, ApplicationContext applicationContext) {
54 | PutProducerStrategy.putProducer(producerConsumer, rocketMessage, bean, rocketProperties, applicationContext);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/execution/SendMessageFactoryExecution.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory.execution;
18 |
19 |
20 | import cc.uncarbon.framework.rocketmq.annotation.RocketMessage;
21 | import cc.uncarbon.framework.rocketmq.core.strategy.ProducerStrategy;
22 | import cc.uncarbon.framework.rocketmq.thread.AbstractSendMessageThread;
23 | import lombok.extern.slf4j.Slf4j;
24 | import org.springframework.context.ApplicationContext;
25 |
26 | import java.util.Map;
27 |
28 |
29 | /**
30 | * ClassName: SendMessageFactoryExecution
31 | * Description:
32 | * date: 2019/4/28 21:31
33 | *
34 | * @author ThierrySquirrel
35 | * @since JDK 1.8
36 | */
37 | @Slf4j
38 | public class SendMessageFactoryExecution extends AbstractSendMessageThread {
39 |
40 | public SendMessageFactoryExecution(Long startDeliverTime, String shardingKeyFactory,
41 | Map consumerContainer, RocketMessage rocketMessage,
42 | Object message, byte[] bytes, ApplicationContext applicationContext) {
43 | super(startDeliverTime, shardingKeyFactory, consumerContainer, rocketMessage, message, bytes, applicationContext);
44 | }
45 |
46 | /**
47 | * 开始发送消息
48 | *
49 | * @param startDeliverTime startDeliverTime
50 | * @param shardingKeyFactory shardingKeyFactory
51 | * @param consumerContainer consumerContainer
52 | * @param rocketMessage rocketMessage
53 | * @param message message
54 | * @param bytes bytes
55 | * @param applicationContext applicationContext
56 | */
57 | @Override
58 | protected void statsSendMessage(Long startDeliverTime, String shardingKeyFactory,
59 | Map consumerContainer, RocketMessage rocketMessage,
60 | Object message, byte[] bytes, ApplicationContext applicationContext) {
61 | ProducerStrategy.statsSendMessage(startDeliverTime, shardingKeyFactory, consumerContainer, rocketMessage, message, bytes, applicationContext);
62 | }
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/factory/execution/ThreadPoolExecutorExecution.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.factory.execution;
18 |
19 | import lombok.experimental.UtilityClass;
20 |
21 | import java.util.concurrent.ThreadPoolExecutor;
22 |
23 | /**
24 | * ClassName: ThreadPoolExecutorExecution
25 | * Description:
26 | * date: 2019/4/27 19:55
27 | *
28 | * @author ThierrySquirrel
29 | * @since JDK 1.8
30 | */
31 | @UtilityClass
32 | public class ThreadPoolExecutorExecution {
33 |
34 | public static void statsThread(ThreadPoolExecutor threadPoolExecutor, Runnable runnable) {
35 | threadPoolExecutor.execute(runnable);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/producer/DefaultLocalTransactionChecker.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.producer;
18 |
19 | import com.aliyun.openservices.ons.api.Message;
20 | import com.aliyun.openservices.ons.api.transaction.LocalTransactionChecker;
21 | import com.aliyun.openservices.ons.api.transaction.TransactionStatus;
22 | import lombok.AllArgsConstructor;
23 | import lombok.Data;
24 | import lombok.extern.slf4j.Slf4j;
25 |
26 | /**
27 | * ClassName: DefaultLocalTransactionChecker
28 | * Description:
29 | * date: 2019/4/28 21:42
30 | *
31 | * @author ThierrySquirrel
32 | * @since JDK 1.8
33 | */
34 | @Slf4j
35 | @AllArgsConstructor
36 | @Data
37 | public class DefaultLocalTransactionChecker implements LocalTransactionChecker {
38 | private TransactionStatus transactionStatus;
39 |
40 | /**
41 | * 回查本地事务,Broker回调Producer,将未结束的事务发给Producer,由Producer来再次决定事务是提交还是回滚
42 | *
43 | * @param msg 消息
44 | * @return {@link TransactionStatus} 事务状态, 包含提交事务、回滚事务、未知状态
45 | */
46 | @Override
47 | public TransactionStatus check(Message msg) {
48 | log.info(">>>> Review local transactions message:{}>>>>", msg);
49 | return transactionStatus;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/producer/DefaultLocalTransactionExecutor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.producer;
18 |
19 | import com.aliyun.openservices.ons.api.Message;
20 | import com.aliyun.openservices.ons.api.transaction.LocalTransactionExecuter;
21 | import com.aliyun.openservices.ons.api.transaction.TransactionStatus;
22 | import lombok.extern.slf4j.Slf4j;
23 |
24 | /**
25 | * ClassName: DefaultLocalTransactionExecuter
26 | * Description:
27 | * date: 2019/4/28 22:28
28 | *
29 | * @author ThierrySquirrel
30 | * @since JDK 1.8
31 | */
32 | @Slf4j
33 | public class DefaultLocalTransactionExecutor implements LocalTransactionExecuter {
34 | /**
35 | * 执行本地事务,由应用来重写
36 | *
37 | * @param msg 消息
38 | * @param arg 应用自定义参数,由send方法传入并回调
39 | * @return {@link TransactionStatus} 返回事务执行结果,包括提交事务、回滚事务、未知状态
40 | */
41 | @Override
42 | public TransactionStatus execute(Message msg, Object arg) {
43 | log.info(">>>> Execute local transaction message:{}>>>>", msg);
44 | return TransactionStatus.CommitTransaction;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/producer/DefaultSendCallback.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.producer;
18 |
19 | import com.aliyun.openservices.ons.api.OnExceptionContext;
20 | import com.aliyun.openservices.ons.api.SendCallback;
21 | import com.aliyun.openservices.ons.api.SendResult;
22 | import lombok.extern.slf4j.Slf4j;
23 |
24 | /**
25 | * ClassName: DefaultSendCallback
26 | * Description:
27 | * date: 2019/4/29 23:32
28 | *
29 | * @author ThierrySquirrel
30 | * @since JDK 1.8
31 | */
32 | @Slf4j
33 | public class DefaultSendCallback implements SendCallback {
34 | /**
35 | * 发送成功回调的方法.
36 | *
37 | * @param sendResult 发送结果
38 | */
39 | @Override
40 | public void onSuccess(SendResult sendResult) {
41 | log.info("Message sent successfully. >> sendResult = {}", sendResult);
42 | }
43 |
44 | /**
45 | * 发送失败回调方法.
46 | *
47 | * @param context 失败上下文.
48 | */
49 | @Override
50 | public void onException(OnExceptionContext context) {
51 | log.error("Failed to send message. >> topic = {}, messageId = {}, exception ", context.getTopic(), context.getMessageId(), context.getException());
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/producer/MessageSendType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.serializer;
18 |
19 | /**
20 | * ClassName: RocketSerializer
21 | * Description:
22 | * date: 2019/10/17 18:24
23 | *
24 | * @author ThierrySquirrel
25 | * @since JDK 1.8
26 | */
27 | public interface RocketSerializer {
28 | /**
29 | * 序列化为byte[]
30 | * @param object 对象
31 | * @param 泛型
32 | * @return 二进制数据
33 | */
34 | byte[] serialize(T object);
35 |
36 | /**
37 | * byte[]反序列化为对象
38 | *
39 | * @param bytes 序列化的二进制数据
40 | * @param clazz 反序列化后的对象
41 | * @param T
42 | * @return 对象
43 | */
44 | T deSerialize(byte[] bytes, Class clazz);
45 | }
46 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/strategy/ProducerStrategy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.strategy;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.CommonMessage;
20 | import cc.uncarbon.framework.rocketmq.annotation.OrderMessage;
21 | import cc.uncarbon.framework.rocketmq.annotation.RocketMessage;
22 | import cc.uncarbon.framework.rocketmq.annotation.TransactionMessage;
23 | import cc.uncarbon.framework.rocketmq.core.factory.ProducerConsumerFactory;
24 | import cc.uncarbon.framework.rocketmq.core.factory.SendMessageFactory;
25 | import com.aliyun.openservices.ons.api.Producer;
26 | import com.aliyun.openservices.ons.api.order.OrderProducer;
27 | import com.aliyun.openservices.ons.api.transaction.TransactionProducer;
28 | import org.springframework.context.ApplicationContext;
29 |
30 | import java.util.Map;
31 |
32 | /**
33 | * ClassName: ProducerStrategy
34 | * Description:
35 | * date: 2019/4/29 21:34
36 | *
37 | * @author ThierrySquirrel
38 | * @since JDK 1.8
39 | */
40 | public class ProducerStrategy {
41 | private ProducerStrategy() {
42 | }
43 |
44 | public static void statsSendMessage(Long startDeliverTime, String shardingKeyFactory, Map consumerContainer, RocketMessage rocketMessage, Object message, byte[] bytes, ApplicationContext applicationContext) {
45 | if (message instanceof CommonMessage commonMessage) {
46 | Producer producer = ProducerConsumerFactory.getProducer(consumerContainer, rocketMessage, commonMessage);
47 | SendMessageFactory.sendMessage(startDeliverTime, producer, commonMessage, bytes, applicationContext);
48 | return;
49 | }
50 | if (message instanceof OrderMessage orderMessage) {
51 | OrderProducer orderProducer = ProducerConsumerFactory.getProducer(consumerContainer, rocketMessage, orderMessage);
52 | SendMessageFactory.sendMessage(orderProducer, orderMessage, bytes, shardingKeyFactory);
53 | return;
54 | }
55 | if (message instanceof TransactionMessage transactionMessage) {
56 | TransactionProducer transactionProducer = ProducerConsumerFactory.getProducer(consumerContainer, rocketMessage, transactionMessage);
57 | SendMessageFactory.sendMessage(transactionProducer, transactionMessage, bytes, applicationContext);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/strategy/SendMessageStrategy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.strategy;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.CommonMessage;
20 | import cc.uncarbon.framework.rocketmq.core.producer.MessageSendType;
21 | import cc.uncarbon.framework.rocketmq.core.utils.ApplicationContextUtils;
22 | import com.aliyun.openservices.ons.api.Message;
23 | import com.aliyun.openservices.ons.api.Producer;
24 | import org.springframework.context.ApplicationContext;
25 |
26 |
27 | /**
28 | * ClassName: SendMessageStrategy
29 | * Description:
30 | * date: 2019/4/29 23:37
31 | *
32 | * @author ThierrySquirrel
33 | * @since JDK 1.8
34 | */
35 | public final class SendMessageStrategy {
36 | private SendMessageStrategy() {
37 | }
38 |
39 | public static void send(CommonMessage commonMessage, Producer producer, Message message, ApplicationContext applicationContext) {
40 | if (commonMessage.messageSendType().equals(MessageSendType.SEND)) {
41 | producer.send(message);
42 | } else if (commonMessage.messageSendType().equals(MessageSendType.SEND_ASYNC)) {
43 | producer.sendAsync(message, ApplicationContextUtils.getSendCallback(applicationContext, commonMessage.callback()));
44 | } else if (commonMessage.messageSendType().equals(MessageSendType.SEND_ONE_WAY)) {
45 | producer.sendOneway(message);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/utils/AnnotatedMethodsUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.utils;
18 |
19 | import org.springframework.core.MethodIntrospector;
20 | import org.springframework.core.annotation.AnnotatedElementUtils;
21 |
22 | import java.lang.annotation.Annotation;
23 | import java.lang.reflect.Method;
24 | import java.util.Map;
25 |
26 | /**
27 | * ClassName: AnnotatedMethodsUtils
28 | * Description:
29 | * date: 2019/5/3 11:44
30 | *
31 | * @author ThierrySquirrel
32 | * @since JDK 1.8
33 | */
34 | public final class AnnotatedMethodsUtils {
35 | private AnnotatedMethodsUtils() {
36 | }
37 |
38 | public static Map getMethodAndAnnotation(Object bean, Class annotation) {
39 | return MethodIntrospector.selectMethods(bean.getClass(),
40 | (MethodIntrospector.MetadataLookup) method -> AnnotatedElementUtils
41 | .findMergedAnnotation(method, annotation));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/utils/AspectUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2020 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 |
17 | package cc.uncarbon.framework.rocketmq.core.utils;
18 |
19 | import org.aspectj.lang.ProceedingJoinPoint;
20 | import org.aspectj.lang.reflect.MethodSignature;
21 |
22 | import java.lang.annotation.Annotation;
23 | import java.lang.reflect.Method;
24 | import java.lang.reflect.Parameter;
25 |
26 | /**
27 | * ClassName: AspectUtils
28 | * Description:
29 | * date: 2020/1/29 18:49
30 | *
31 | * @author ThierrySquirrel
32 | * @since JDK 1.8
33 | */
34 | public final class AspectUtils {
35 | private AspectUtils() {
36 | }
37 |
38 | private static Method getMethod(ProceedingJoinPoint proceedingJoinPoint) {
39 | MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature();
40 | return signature.getMethod();
41 | }
42 |
43 | public static T getAnnotation(ProceedingJoinPoint proceedingJoinPoint, Class annotationClass) {
44 | return getMethod(proceedingJoinPoint).getAnnotation(annotationClass);
45 | }
46 |
47 | public static T getDeclaringClassAnnotation(ProceedingJoinPoint proceedingJoinPoint, Class annotationClass) {
48 | return getMethod(proceedingJoinPoint).getDeclaringClass().getAnnotation(annotationClass);
49 | }
50 |
51 | public static Parameter[] getParams(ProceedingJoinPoint proceedingJoinPoint) {
52 | Method method = getMethod(proceedingJoinPoint);
53 | return method.getParameters();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/core/utils/InterceptRocket.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.core.utils;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.RocketMessage;
20 | import cc.uncarbon.framework.rocketmq.core.factory.execution.SendMessageFactoryExecution;
21 | import cc.uncarbon.framework.rocketmq.core.factory.execution.ThreadPoolExecutorExecution;
22 | import cc.uncarbon.framework.rocketmq.core.serializer.RocketSerializer;
23 | import org.springframework.context.ApplicationContext;
24 |
25 | import java.lang.annotation.Annotation;
26 | import java.util.Map;
27 | import java.util.concurrent.ThreadPoolExecutor;
28 |
29 | /**
30 | * ClassName: InterceptRocket
31 | * Description:
32 | * date: 2019/4/29 22:03
33 | *
34 | * @author ThierrySquirrel
35 | * @since JDK 1.8
36 | */
37 | public final class InterceptRocket {
38 | private InterceptRocket() {
39 | }
40 |
41 | public static Object intercept(Long startDeliverTime, String shardingKeyFactory,
42 | RocketMessage rocketMessage, T annotation, Object proceed,
43 | Map consumerContainer, ThreadPoolExecutor threadPoolExecutor,
44 | ApplicationContext applicationContext) {
45 | RocketSerializer mqSerializer = applicationContext.getBean(RocketSerializer.class);
46 | byte[] body = mqSerializer.serialize(proceed);
47 |
48 | ThreadPoolExecutorExecution.statsThread(threadPoolExecutor,
49 | new SendMessageFactoryExecution(startDeliverTime, shardingKeyFactory, consumerContainer, rocketMessage, annotation, body, applicationContext));
50 | return proceed;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/exception/RocketException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.exception;
18 |
19 | /**
20 | * ClassName: RocketException
21 | * Description:
22 | * date: 2019/4/27 16:44
23 | *
24 | * @author ThierrySquirrel
25 | * @since JDK 1.8
26 | */
27 | public class RocketException extends Exception {
28 |
29 | public RocketException(String message) {
30 | super(message);
31 | }
32 |
33 | public RocketException(Throwable cause) {
34 | super(cause);
35 | }
36 |
37 | public RocketException(String message, Throwable cause) {
38 | super(message, cause);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/thread/AbstractConsumerThread.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 |
17 | package cc.uncarbon.framework.rocketmq.thread;
18 |
19 | import cc.uncarbon.framework.rocketmq.annotation.MessageListener;
20 | import cc.uncarbon.framework.rocketmq.annotation.RocketListener;
21 | import cc.uncarbon.framework.rocketmq.core.factory.execution.MethodFactoryExecution;
22 | import cc.uncarbon.framework.rocketmq.props.AliyunRocketProperties;
23 | import lombok.Data;
24 |
25 | /**
26 | * ClassName: AbstractConsumerThread
27 | * Description:
28 | * date: 2019/4/27 20:03
29 | *
30 | * @author ThierrySquirrel
31 | * @since JDK 1.8
32 | */
33 | @Data
34 | public abstract class AbstractConsumerThread implements Runnable {
35 | private AliyunRocketProperties rocketProperties;
36 | private RocketListener rocketListener;
37 | private MessageListener consumerListener;
38 | private MethodFactoryExecution methodFactoryExecution;
39 |
40 | protected AbstractConsumerThread(AliyunRocketProperties rocketProperties, RocketListener rocketListener, MessageListener consumerListener, MethodFactoryExecution methodFactoryExecution) {
41 | this.rocketProperties = rocketProperties;
42 | this.rocketListener = rocketListener;
43 | this.consumerListener = consumerListener;
44 | this.methodFactoryExecution = methodFactoryExecution;
45 | }
46 |
47 | /**
48 | * 消费者开始监听
49 | *
50 | * @param rocketProperties rocketProperties
51 | * @param rocketListener rocketListener
52 | * @param consumerListener consumerListener
53 | * @param methodFactoryExecution methodFactoryExecution
54 | */
55 | protected abstract void statsConsumer(AliyunRocketProperties rocketProperties,
56 | RocketListener rocketListener,
57 | MessageListener consumerListener,
58 | MethodFactoryExecution methodFactoryExecution);
59 |
60 | @Override
61 | public void run() {
62 | statsConsumer(this.getRocketProperties(),
63 | this.getRocketListener(),
64 | this.getConsumerListener(),
65 | this.getMethodFactoryExecution());
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/helio-starter-rocketmq-aliyun/src/main/java/cc/uncarbon/framework/rocketmq/thread/AbstractProducerThread.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2019 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 | *