新增rocketmq-demo演示工程
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
package com.rocketmq;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Rocketmq消费者 demo
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RocketMqConsumeApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RocketMqConsumeApplication.class, args);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.rocketmq.demo.config;
|
||||
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.Input;
|
||||
import com.rocketmq.demo.config.RocketMqConfig.MySink;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@EnableBinding({MySink.class})
|
||||
public class RocketMqConfig {
|
||||
public interface MySink {
|
||||
@Input(Sink.INPUT)
|
||||
SubscribableChannel input();
|
||||
|
||||
@Input("input2")
|
||||
SubscribableChannel input2();
|
||||
|
||||
@Input("input3")
|
||||
SubscribableChannel input3();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.rocketmq.demo.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 订单实体
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Order implements Serializable {
|
||||
private static final long serialVersionUID = 2801814838883246461L;
|
||||
|
||||
private Long orderId;
|
||||
private String orderNo;
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.rocketmq.demo.service;
|
||||
|
||||
import com.rocketmq.demo.model.Order;
|
||||
|
||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@Service
|
||||
public class ReceiveService {
|
||||
/**
|
||||
* 字符串消息
|
||||
*/
|
||||
@StreamListener(Sink.INPUT)
|
||||
public void receiveInput(String receiveMsg) {
|
||||
System.out.println("input receive: " + receiveMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象消息
|
||||
*/
|
||||
@StreamListener("input2")
|
||||
public void receiveInput2(@Payload Order order) {
|
||||
System.out.println("input2 receive: " + order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过spring.messaging对象来接收消息
|
||||
*/
|
||||
@StreamListener("input3")
|
||||
public void receiveInput3(Message msg) {
|
||||
System.out.println("input3 receive: " + msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
server:
|
||||
port: 11003
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: rocketmq-produce
|
||||
cloud:
|
||||
stream:
|
||||
rocketmq:
|
||||
binder:
|
||||
# RocketMQ 服务器地址
|
||||
name-server: 192.168.28.130:9876
|
||||
bindings:
|
||||
input2:
|
||||
consumer:
|
||||
#增加tag过滤
|
||||
tags: tagObj
|
||||
bindings:
|
||||
input:
|
||||
destination: test-topic
|
||||
content-type: text/plain
|
||||
group: consume-group1
|
||||
consumer:
|
||||
#并发消费线程数
|
||||
concurrency: 20
|
||||
input2:
|
||||
destination: test-topic
|
||||
content-type: application/json
|
||||
group: consume-group2
|
||||
consumer:
|
||||
#并发消费线程数
|
||||
concurrency: 20
|
||||
input3:
|
||||
destination: test-topic
|
||||
content-type: text/plain
|
||||
group: consume-group3
|
||||
consumer:
|
||||
#并发消费线程数
|
||||
concurrency: 20
|
||||
Reference in New Issue
Block a user