Merge remote-tracking branch 'origin/master'

master
wujingtao 2 years ago
commit 69b450d22f

@ -12,8 +12,8 @@
<artifactId>cdp-common-core</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>cdp-common</artifactId>
<groupId>com.baiye</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>cdp-common-rocketmq</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>cdp-common-rocketmq</name>
<description>cdp-common-rocketmq</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.baiye</groupId>
<artifactId>cdp-common-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 引入 Spring Cloud Alibaba Stream RocketMQ 相关依赖,将 RocketMQ 作为消息队列,并实现对其的自动配置 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -12,8 +12,8 @@
<artifactId>cdp-common-security</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>

@ -16,6 +16,7 @@
<module>cdp-common-core</module>
<module>cdp-common-exception</module>
<module>cdp-common-mybatis-plus</module>
<module>cdp-common-rocketmq</module>
</modules>
<properties>

@ -0,0 +1,34 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
.mvn

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>cdp-tool-mq</artifactId>
<groupId>com.baiye</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>cdp-tool-mq-producer</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>cdp-tool-mq-producer</name>
<description>cdp-tool-mq-producer</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.baiye</groupId>
<artifactId>cdp-common-rocketmq</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,22 @@
package com.baiye;
import com.baiye.message.MySource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.stream.annotation.EnableBinding;
/**
* @author Enzo
* @date 2022-7-13
*/
@EnableBinding(MySource.class)
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class CdpToolMqProducerApplication {
public static void main(String[] args) {
SpringApplication.run(CdpToolMqProducerApplication.class, args);
}
}

@ -0,0 +1,42 @@
package com.baiye.controller;
import com.baiye.message.Demo01Message;
import com.baiye.message.MySource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Random;
@RestController
@RequestMapping("/demo01")
public class Demo01Controller {
private Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private MySource mySource;
@GetMapping("/send_orderly")
public boolean sendOrderly() {
// 发送 3 条相同 id 的消息
int id = new Random().nextInt();
for (int i = 0; i < 3; i++) {
// 创建 Message
Demo01Message message = new Demo01Message().setId(id);
// 创建 Spring Message 对象
Message<Demo01Message> springMessage = MessageBuilder.withPayload(message)
.build();
// 发送消息
mySource.testOutPut().send(springMessage);
}
return true;
}
}

@ -0,0 +1,29 @@
package com.baiye.message;
/**
* 01 Message
*/
public class Demo01Message {
/**
*
*/
private Integer id;
public Demo01Message setId(Integer id) {
this.id = id;
return this;
}
public Integer getId() {
return id;
}
@Override
public String toString() {
return "Demo01Message{" +
"id=" + id +
'}';
}
}

@ -0,0 +1,11 @@
package com.baiye.message;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.MessageChannel;
public interface MySource {
@Output("test-output")
MessageChannel testOutPut();
}

@ -0,0 +1,35 @@
package com.baiye.message;
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.Message;
/**
* @description MQ
* @ClassName: TransactionListenerImpl
* @author: jbcode@126.com
* @date: 2020/8/7 9:21
* @Copyright:
*/
@RocketMQTransactionListener(txProducerGroup = "test")
public class TransactionListenerImpl implements RocketMQLocalTransactionListener {
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
public RocketMQLocalTransactionState executeLocalTransaction(Message msg, Object arg) {
return RocketMQLocalTransactionState.UNKNOWN;
}
@Override
public RocketMQLocalTransactionState checkLocalTransaction(Message msg) {
// ... check local transaction status and return rollback, commit or unknown
logger.info("[checkLocalTransaction][回查消息:{}]", msg);
return RocketMQLocalTransactionState.COMMIT;
}
}

@ -0,0 +1,31 @@
spring:
application:
name: stream-rocketmq-producer-application
cloud:
# Spring Cloud Stream 配置项,对应 BindingServiceProperties 类
stream:
# Binding 配置项,对应 BindingProperties Map
bindings:
erbadagang-output:
destination: TEST-TOPIC-01 # 目的地。这里使用 RocketMQ Topic
content-type: application/json # 内容格式。这里使用 JSON
# Producer 配置项,对应 ProducerProperties 类
producer:
partition-key-expression: payload['id'] # 分区 key 表达式。该表达式基于 Spring EL从消息中获得分区 key。
# Spring Cloud Stream RocketMQ 配置项
rocketmq:
# RocketMQ Binder 配置项,对应 RocketMQBinderConfigurationProperties 类
binder:
name-server: 8.130.96.163:9876 # RocketMQ Namesrv 地址
# RocketMQ 自定义 Binding 配置项,对应 RocketMQBindingProperties Map
bindings:
test-output:
# RocketMQ Producer 配置项,对应 RocketMQProducerProperties 类
producer:
transactional: true
group: test # 生产者分组
sync: true # 是否同步发送消息,默认为 false 异步。
server:
port: 18080

@ -0,0 +1,13 @@
package com.baiye;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class CdpToolMqProducerApplicationTests {
@Test
void contextLoads() {
}
}

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.baiye</groupId>
<artifactId>cpd-tool-mq-consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cpd-tool-mq-consumer</name>
<description>cpd-tool-mq-consumer</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.baiye</groupId>
<artifactId>cdp-common-rocketmq</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,22 @@
package com.baiye;
import com.baiye.listener.MySink;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.stream.annotation.EnableBinding;
/**
* @author Enzo
* @date 2022-7-13
*/
@EnableBinding(MySink.class)
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class CpdToolMqConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(CpdToolMqConsumerApplication.class, args);
}
}

@ -0,0 +1,20 @@
package com.baiye.listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;
@Component
public class Demo01Consumer {
private Logger logger = LoggerFactory.getLogger(getClass());
@StreamListener(MySink.TEST_INPUT)
public void onMessage(Message<?> message) {
logger.info("[onMessage][线程编号:{} 消息内容:{}]", Thread.currentThread().getId(), message);
// throw new RuntimeException("抛出一个异常");
}
}

@ -0,0 +1,13 @@
package com.baiye.listener;
import org.springframework.cloud.stream.annotation.Input;
import org.springframework.messaging.SubscribableChannel;
public interface MySink {
String TEST_INPUT = "test-input";
@Input(TEST_INPUT)
SubscribableChannel demo01Input();
}

@ -0,0 +1,29 @@
package com.baiye.message;
/**
* 01 Message
*/
public class Demo01Message {
/**
*
*/
private Integer id;
public Demo01Message setId(Integer id) {
this.id = id;
return this;
}
public Integer getId() {
return id;
}
@Override
public String toString() {
return "Demo01Message{" +
"id=" + id +
'}';
}
}

@ -0,0 +1,31 @@
spring:
application:
name: @artifactId@
cloud:
# Spring Cloud Stream ?????? BindingServiceProperties ?
stream:
# Binding ?????? BindingProperties Map
bindings:
test-input:
destination: TEST-TOPIC-01 # ???????? RocketMQ Topic
content-type: application/json # ????????? JSON
group: test-consumer-group-test-topic-01 # ?????,???????+topic?
# Spring Cloud Stream RocketMQ ???
rocketmq:
# RocketMQ Binder ?????? RocketMQBinderConfigurationProperties ?
binder:
name-server: 8.130.96.163:9876 # RocketMQ Namesrv ??
# RocketMQ ??? Binding ?????? RocketMQBindingProperties Map
bindings:
test-input:
# RocketMQ Consumer ?????? RocketMQConsumerProperties ?
consumer:
delay-level-when-next-consume: 0 # ????????????????????? 0
enabled: true # ?????????? true
broadcasting: false # ???????????? false ??????
orderly: true # ?????????? false ?????
server:
port: ${random.int[10000,19999]} # ??????????????

@ -0,0 +1,13 @@
package com.baiye;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class CpdToolMqConsumerApplicationTests {
@Test
void contextLoads() {
}
}

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>cdp-tools</artifactId>
<groupId>com.baiye</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>cdp-tool-mq</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>cdp-tool-mq</name>
<description>cdp-tool-mq</description>
<packaging>pom</packaging>
<modules>
<module>cdp-tool-mq-producer</module>
<module>cpd-tool-mq-consumer</module>
</modules>
<properties>
<java.version>1.8</java.version>
</properties>
</project>

@ -15,6 +15,7 @@
<module>dy-tool-livetelecast</module>
<module>dy-tool-member</module>
<module>dy-tool-video</module>
<module>cdp-tool-mq</module>
</modules>
<properties>
@ -22,4 +23,4 @@
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
</project>

@ -270,6 +270,13 @@
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>5.2.1.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>

Loading…
Cancel
Save