some rocketmq example.
parent
cb3f9760b9
commit
a216edc863
@ -0,0 +1,53 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
||||||
|
<artifactId>rocketmq-broadcast-consumer2-example</artifactId>
|
||||||
|
<name>Spring Cloud Starter Stream Alibaba RocketMQ Broadcasting Consume Example Cosumer1</name>
|
||||||
|
<description>Example demonstrating how to broadcast consumption</description>
|
||||||
|
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-json</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>${maven-deploy-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.examples.broadcast;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sorie
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class RocketMQBroadcastConsumer1Application {
|
||||||
|
private static final Logger log = LoggerFactory
|
||||||
|
.getLogger(RocketMQBroadcastConsumer1Application.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(RocketMQBroadcastConsumer1Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Consumer<Message<String>> consumer() {
|
||||||
|
return msg -> {
|
||||||
|
log.info(Thread.currentThread().getName() + " Consumer2 Receive New Messages: " + msg.getPayload());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
server:
|
||||||
|
port: 28084
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: rocketmq-broadcast-consumer1-example
|
||||||
|
cloud:
|
||||||
|
stream:
|
||||||
|
function:
|
||||||
|
definition: consumer;
|
||||||
|
rocketmq:
|
||||||
|
binder:
|
||||||
|
name-server: 192.168.0.200:9876
|
||||||
|
bindings:
|
||||||
|
consumer-in-0:
|
||||||
|
consumer:
|
||||||
|
messageModel: BROADCASTING
|
||||||
|
bindings:
|
||||||
|
consumer-in-0:
|
||||||
|
destination: broadcast
|
||||||
|
group: broadcast-consumer
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
org.springframework.context.support: debug
|
@ -0,0 +1,52 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
||||||
|
<artifactId>rocketmq-broadcast-consumer1-example</artifactId>
|
||||||
|
<name>Spring Cloud Starter Stream Alibaba RocketMQ Broadcasting Consume Example Consumer2</name>
|
||||||
|
<description>Example demonstrating how to broadcast consumption</description>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-json</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>${maven-deploy-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.examples.broadcast;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sorie
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class RocketMQBroadcastConsumer2Application {
|
||||||
|
private static final Logger log = LoggerFactory
|
||||||
|
.getLogger(RocketMQBroadcastConsumer2Application.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(RocketMQBroadcastConsumer2Application.class, args);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Consumer<Message<String>> consumer() {
|
||||||
|
return msg -> {
|
||||||
|
log.info(Thread.currentThread().getName() + " Consumer1 Receive New Messages: " + msg.getPayload());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
server:
|
||||||
|
port: 28083
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: rocketmq-broadcast-consumer2-example
|
||||||
|
cloud:
|
||||||
|
stream:
|
||||||
|
function:
|
||||||
|
definition: consumer;
|
||||||
|
rocketmq:
|
||||||
|
binder:
|
||||||
|
name-server: 192.168.0.200:9876
|
||||||
|
bindings:
|
||||||
|
consumer-in-0:
|
||||||
|
consumer:
|
||||||
|
messageModel: BROADCASTING
|
||||||
|
bindings:
|
||||||
|
consumer-in-0:
|
||||||
|
destination: broadcast
|
||||||
|
group: broadcast-consumer
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
org.springframework.context.support: debug
|
@ -0,0 +1,52 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
||||||
|
<artifactId>rocketmq-broadcast-producer-example</artifactId>
|
||||||
|
<name>Spring Cloud Starter Stream Alibaba RocketMQ Broadcasting Consume Example Producer</name>
|
||||||
|
<description>Example demonstrating how to use rocketmq to produce</description>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-json</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>${maven-deploy-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.examples.broadcast;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.apache.rocketmq.common.message.MessageConst;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sorie
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class RocketMQBroadcastConsumeApplication {
|
||||||
|
private static final Logger log = LoggerFactory
|
||||||
|
.getLogger(RocketMQBroadcastConsumeApplication.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(RocketMQBroadcastConsumeApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Supplier<Flux<Message<String>>> producer() {
|
||||||
|
return () -> {
|
||||||
|
return Flux.range(0, 100).map(i -> {
|
||||||
|
String key = "KEY" + i;
|
||||||
|
Map<String, Object> headers = new HashMap<>();
|
||||||
|
headers.put(MessageConst.PROPERTY_KEYS, key);
|
||||||
|
headers.put(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID, i);
|
||||||
|
Message<String> msg = new GenericMessage("Hello RocketMQ " + i, headers);
|
||||||
|
return msg;
|
||||||
|
}).log();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
server:
|
||||||
|
port: 28085
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: rocketmq-broadcast-producer-example
|
||||||
|
cloud:
|
||||||
|
stream:
|
||||||
|
function:
|
||||||
|
definition: producer;
|
||||||
|
rocketmq:
|
||||||
|
binder:
|
||||||
|
name-server: 192.168.0.200:9876
|
||||||
|
bindings:
|
||||||
|
producer-out-0:
|
||||||
|
producer:
|
||||||
|
group: output_1
|
||||||
|
bindings:
|
||||||
|
producer-out-0:
|
||||||
|
destination: broadcast
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
org.springframework.context.support: debug
|
@ -0,0 +1,55 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
||||||
|
<artifactId>rocketmq-delay-consume-example</artifactId>
|
||||||
|
<name>Spring Cloud Starter Stream Alibaba RocketMQ Delay Consume Example</name>
|
||||||
|
<description>Example demonstrating how to use rocketmq to delay consume</description>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>${maven-deploy-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.examples.broadcast;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.apache.rocketmq.common.message.MessageConst;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
/**
|
||||||
|
* @author sorie
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class RocketMQDelayConsumeApplication {
|
||||||
|
private static final Logger log = LoggerFactory
|
||||||
|
.getLogger(RocketMQDelayConsumeApplication.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(RocketMQDelayConsumeApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Supplier<Flux<Message<String>>> producer() {
|
||||||
|
return () -> {
|
||||||
|
return Flux.range(0, 100).map(i -> {
|
||||||
|
String key = "KEY" + i;
|
||||||
|
Map<String, Object> headers = new HashMap<>();
|
||||||
|
headers.put(MessageConst.PROPERTY_KEYS, key);
|
||||||
|
headers.put(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID, i);
|
||||||
|
headers.put("DELAY", 2);
|
||||||
|
Message<String> msg = new GenericMessage("Hello RocketMQ " + i, headers);
|
||||||
|
return msg;
|
||||||
|
}).log();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Consumer<Message<String>> consumer() {
|
||||||
|
return msg -> {
|
||||||
|
log.info(Thread.currentThread().getName() + " Consumer Receive New Messages: " + msg.getPayload());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
server:
|
||||||
|
port: 28086
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: rocketmq-delay-consume-example
|
||||||
|
cloud:
|
||||||
|
stream:
|
||||||
|
function:
|
||||||
|
definition: producer;consumer;
|
||||||
|
rocketmq:
|
||||||
|
binder:
|
||||||
|
name-server: 192.168.0.200:9876
|
||||||
|
bindings:
|
||||||
|
producer-out-0:
|
||||||
|
producer:
|
||||||
|
group: output_1
|
||||||
|
bindings:
|
||||||
|
producer-out-0:
|
||||||
|
destination: delay
|
||||||
|
consumer-in-0:
|
||||||
|
destination: delay
|
||||||
|
group: delay-group
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
org.springframework.context.support: debug
|
@ -0,0 +1,52 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
||||||
|
<artifactId>rocketmq-orderly-consume-example</artifactId>
|
||||||
|
<name>Spring Cloud Starter Stream Alibaba RocketMQ Orderly Consume Example</name>
|
||||||
|
<description>Example demonstrating how to use rocketmq to produce, and consume orderly</description>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-json</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>${maven-deploy-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.examples.orderly;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.rocketmq.client.producer.MessageQueueSelector;
|
||||||
|
import org.apache.rocketmq.common.message.Message;
|
||||||
|
import org.apache.rocketmq.common.message.MessageConst;
|
||||||
|
import org.apache.rocketmq.common.message.MessageQueue;
|
||||||
|
|
||||||
|
import org.springframework.messaging.MessageHeaders;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sorie
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class OrderlyMessageQueueSelector implements MessageQueueSelector {
|
||||||
|
@Override
|
||||||
|
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
|
||||||
|
Integer id = (Integer) ((MessageHeaders) arg).get(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID);
|
||||||
|
int index = id % Math.min(mqs.size(), RocketMQOrderlyConsumeApplication.tags.length);
|
||||||
|
return mqs.get(index);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.examples.orderly;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.stream.binder.rocketmq.support.RocketMQMessageConverterSupport;
|
||||||
|
import org.apache.rocketmq.common.message.MessageConst;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
/**
|
||||||
|
* @author sorie
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class RocketMQOrderlyConsumeApplication {
|
||||||
|
private static final Logger log = LoggerFactory
|
||||||
|
.getLogger(RocketMQOrderlyConsumeApplication.class);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* tag array.
|
||||||
|
*/
|
||||||
|
public static final String[] tags = new String[] {"TagA", "TagB", "TagC", "TagD", "TagE"};
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(RocketMQOrderlyConsumeApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Supplier<Flux<Message<String>>> producer() {
|
||||||
|
return () -> {
|
||||||
|
return Flux.range(0, 100).map(i -> {
|
||||||
|
String key = "KEY" + i;
|
||||||
|
Map<String, Object> headers = new HashMap<>();
|
||||||
|
headers.put(MessageConst.PROPERTY_KEYS, key);
|
||||||
|
headers.put(MessageConst.PROPERTY_TAGS, tags[i % tags.length]);
|
||||||
|
headers.put(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID, i);
|
||||||
|
Message<String> msg = new GenericMessage("Hello RocketMQ " + i, headers);
|
||||||
|
return msg;
|
||||||
|
}).log();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Consumer<Message<String>> consumer() {
|
||||||
|
return msg -> {
|
||||||
|
String tagHeaderKey = RocketMQMessageConverterSupport.toRocketHeaderKey(
|
||||||
|
MessageConst.PROPERTY_TAGS).toString();
|
||||||
|
log.info(Thread.currentThread().getName() + " Receive New Messages: " + msg.getPayload() + " TAG:" +
|
||||||
|
msg.getHeaders().get(tagHeaderKey).toString());
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
server:
|
||||||
|
port: 28082
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: rocketmq-orderly-consume-example
|
||||||
|
cloud:
|
||||||
|
stream:
|
||||||
|
function:
|
||||||
|
definition: producer;consumer;
|
||||||
|
rocketmq:
|
||||||
|
binder:
|
||||||
|
name-server: localhost:9876
|
||||||
|
bindings:
|
||||||
|
producer-out-0:
|
||||||
|
producer:
|
||||||
|
group: output_1
|
||||||
|
messageQueueSelector: orderlyMessageQueueSelector
|
||||||
|
consumer-in-0:
|
||||||
|
consumer:
|
||||||
|
# tag: {@code tag1||tag2||tag3 }; sql: {@code 'color'='blue' AND 'price'>100 } .
|
||||||
|
subscription: 'TagA || TagC || TagD'
|
||||||
|
push:
|
||||||
|
orderly: true
|
||||||
|
bindings:
|
||||||
|
producer-out-0:
|
||||||
|
destination: orderly
|
||||||
|
consumer-in-0:
|
||||||
|
destination: orderly
|
||||||
|
group: orderly-consumer
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
org.springframework.context.support: debug
|
@ -0,0 +1,55 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
||||||
|
<artifactId>rocketmq-sql-consume-example</artifactId>
|
||||||
|
<name>Spring Cloud Starter Stream Alibaba RocketMQ Sql Consume Example</name>
|
||||||
|
<description>Example demonstrating how to use rocketmq to filter message by sql</description>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>${maven-deploy-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.examples.broadcast;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.apache.rocketmq.common.message.MessageConst;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
/**
|
||||||
|
* @author sorie
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class RocketMQSqlConsumeApplication {
|
||||||
|
private static final Logger log = LoggerFactory
|
||||||
|
.getLogger(RocketMQSqlConsumeApplication.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(RocketMQSqlConsumeApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* color array.
|
||||||
|
*/
|
||||||
|
public static final String[] color = new String[] {"red1", "red2", "red3", "red4", "red5"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* price array.
|
||||||
|
*/
|
||||||
|
public static final Integer[] price = new Integer[] {1, 2, 3, 4, 5};
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Supplier<Flux<Message<String>>> producer() {
|
||||||
|
return () -> {
|
||||||
|
return Flux.range(0, 100).map(i -> {
|
||||||
|
String key = "KEY" + i;
|
||||||
|
Map<String, Object> headers = new HashMap<>();
|
||||||
|
headers.put(MessageConst.PROPERTY_KEYS, key);
|
||||||
|
headers.put("color", color[i % color.length]);
|
||||||
|
headers.put("price", price[i % price.length]);
|
||||||
|
headers.put(MessageConst.PROPERTY_ORIGIN_MESSAGE_ID, i);
|
||||||
|
Message<String> msg = new GenericMessage("Hello RocketMQ " + i, headers);
|
||||||
|
return msg;
|
||||||
|
}).log();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Consumer<Message<String>> consumer() {
|
||||||
|
return msg -> {
|
||||||
|
String colorHeaderKey = "color";
|
||||||
|
String priceHeaderKey = "price";
|
||||||
|
log.info(Thread.currentThread().getName() + " Receive New Messages: " + msg.getPayload() + " COLOR:" +
|
||||||
|
msg.getHeaders().get(colorHeaderKey).toString() + " " +
|
||||||
|
"PRICE: " + msg.getHeaders().get(priceHeaderKey).toString());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
server:
|
||||||
|
port: 28087
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: rocketmq-sql-consume-example
|
||||||
|
cloud:
|
||||||
|
stream:
|
||||||
|
function:
|
||||||
|
definition: producer;consumer;
|
||||||
|
rocketmq:
|
||||||
|
binder:
|
||||||
|
name-server: 192.168.0.200:9876
|
||||||
|
bindings:
|
||||||
|
producer-out-0:
|
||||||
|
producer:
|
||||||
|
group: output_1
|
||||||
|
consumer-in-0:
|
||||||
|
consumer:
|
||||||
|
# tag: {@code tag1||tag2||tag3 }; sql: {@code 'color'='blue' AND 'price'>100 } .
|
||||||
|
subscription: sql:(color in ('red1', 'red2', 'red4') and price>3)
|
||||||
|
bindings:
|
||||||
|
producer-out-0:
|
||||||
|
destination: sql
|
||||||
|
consumer-in-0:
|
||||||
|
destination: sql
|
||||||
|
group: sql-group
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
org.springframework.context.support: debug
|
Loading…
Reference in New Issue