Skip to content

Commit 0a0a931

Browse files
authored
[ISSUE #660] Add simple sample demo (#661)
* Add simple sample demo
1 parent f437f52 commit 0a0a931

20 files changed

Lines changed: 608 additions & 5 deletions

File tree

rocketmq-spring-boot-samples/pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,21 @@
3535
<module>rocketmq-consume-demo</module>
3636
<module>rocketmq-produce-acl-demo</module>
3737
<module>rocketmq-consume-acl-demo</module>
38+
<module>rocketmq-producer-simple-demo</module>
39+
<module>rocketmq-consumer-pull-simple-demo</module>
40+
<module>rocketmq-consumer-push-simple-demo</module>
3841
</modules>
3942

4043
<properties>
4144
<maven.compiler.source>1.8</maven.compiler.source>
4245
<maven.compiler.target>1.8</maven.compiler.target>
43-
<rocketmq-spring-boot-starter-version>2.3.1-SNAPSHOT</rocketmq-spring-boot-starter-version>
4446
</properties>
4547

4648
<dependencies>
4749
<dependency>
4850
<groupId>org.apache.rocketmq</groupId>
4951
<artifactId>rocketmq-spring-boot-starter</artifactId>
50-
<version>${rocketmq-spring-boot-starter-version}</version>
52+
<version>${project.version}</version>
5153
</dependency>
5254
</dependencies>
5355

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.apache.rocketmq</groupId>
24+
<artifactId>rocketmq-spring-boot-samples</artifactId>
25+
<version>2.3.1-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>rocketmq-consumer-pull-simple-demo</artifactId>
29+
30+
<properties>
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
</properties>
33+
34+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.rocketmq.samples.springboot;
19+
20+
21+
import java.util.List;
22+
import javax.annotation.Resource;
23+
import org.apache.rocketmq.spring.core.RocketMQTemplate;
24+
import org.springframework.boot.CommandLineRunner;
25+
import org.springframework.boot.SpringApplication;
26+
import org.springframework.boot.autoconfigure.SpringBootApplication;
27+
28+
@SpringBootApplication
29+
public class PullConsumerApplication implements CommandLineRunner {
30+
@Resource
31+
private RocketMQTemplate rocketMQTemplate;
32+
33+
public static void main(String[] args) {
34+
SpringApplication.run(PullConsumerApplication.class, args);
35+
}
36+
37+
@Override
38+
public void run(String... args) {
39+
for (int i = 0; i < 100; i++) {
40+
List<String> messages = rocketMQTemplate.receive(String.class);
41+
System.out.println(messages);
42+
}
43+
}
44+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
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+
rocketmq.name-server=localhost:9876
17+
18+
rocketmq.pull-consumer.group=demo-group
19+
rocketmq.pull-consumer.topic=demo-topic
20+
#rocketmq.pull-consumer.access-key=
21+
#rocketmq.pull-consumer.secret-key=
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.apache.rocketmq</groupId>
24+
<artifactId>rocketmq-spring-boot-samples</artifactId>
25+
<version>2.3.1-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>rocketmq-consumer-push-simple-demo</artifactId>
29+
30+
<properties>
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
</properties>
33+
34+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.rocketmq.samples.springboot;
19+
20+
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
21+
import org.apache.rocketmq.spring.core.RocketMQListener;
22+
import org.springframework.boot.CommandLineRunner;
23+
import org.springframework.boot.SpringApplication;
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
import org.springframework.stereotype.Service;
26+
27+
@SpringBootApplication
28+
public class PushConsumerApplication implements CommandLineRunner {
29+
30+
public static void main(String[] args) {
31+
SpringApplication.run(PushConsumerApplication.class, args);
32+
}
33+
34+
@Override
35+
public void run(String... args) {
36+
}
37+
38+
@Service
39+
@RocketMQMessageListener(topic = "demo-topic", consumerGroup = "demo-group")
40+
public static class DemoConsumer implements RocketMQListener<String> {
41+
public void onMessage(String message) {
42+
System.out.println("received message: " + message);
43+
}
44+
}
45+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
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+
rocketmq.name-server=localhost:9876
17+
18+
#rocketmq.consumer.access-key=
19+
#rocketmq.consumer.secret-key=
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.apache.rocketmq</groupId>
24+
<artifactId>rocketmq-spring-boot-samples</artifactId>
25+
<version>2.3.1-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>rocketmq-producer-simple-demo</artifactId>
29+
30+
<properties>
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
</properties>
33+
34+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.rocketmq.samples.springboot;
19+
20+
import javax.annotation.Resource;
21+
import org.apache.rocketmq.client.producer.SendResult;
22+
import org.apache.rocketmq.spring.core.RocketMQTemplate;
23+
import org.springframework.beans.factory.annotation.Value;
24+
import org.springframework.boot.CommandLineRunner;
25+
import org.springframework.boot.SpringApplication;
26+
import org.springframework.boot.autoconfigure.SpringBootApplication;
27+
28+
@SpringBootApplication
29+
public class ProducerApplication implements CommandLineRunner {
30+
@Resource
31+
private RocketMQTemplate rocketMQTemplate;
32+
33+
@Value("${rocketmq.producer.simple.demo.topic}")
34+
private String topic;
35+
36+
public static void main(String[] args) {
37+
SpringApplication.run(ProducerApplication.class, args);
38+
}
39+
40+
@Override
41+
public void run(String... args) {
42+
SendResult sendResult = rocketMQTemplate.syncSend(topic, "Hello, World!");
43+
System.out.println(sendResult);
44+
}
45+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
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+
rocketmq.name-server=localhost:9876
17+
18+
rocketmq.producer.simple.demo.topic=demo-topic
19+
rocketmq.producer.group=demo-group
20+
#rocketmq.producer.access-key=
21+
#rocketmq.producer.secret-key=

0 commit comments

Comments
 (0)