feat: 升级SpringBoot和SpringCloud版本
This commit is contained in:
-20
@@ -1,20 +0,0 @@
|
||||
package com.rocketmq.demo.config;
|
||||
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.Output;
|
||||
import com.rocketmq.demo.config.RocketMqConfig.MySource;
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
|
||||
/**
|
||||
* 配置消息生产者
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@EnableBinding({MySource.class})
|
||||
public class RocketMqConfig {
|
||||
public interface MySource {
|
||||
@Output(Source.OUTPUT)
|
||||
MessageChannel output();
|
||||
}
|
||||
}
|
||||
+10
-7
@@ -1,37 +1,40 @@
|
||||
package com.rocketmq.demo.service;
|
||||
|
||||
import org.apache.rocketmq.common.message.MessageConst;
|
||||
import com.rocketmq.demo.config.RocketMqConfig.MySource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.stream.function.StreamBridge;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@Service
|
||||
public class SenderService {
|
||||
@Autowired
|
||||
private MySource source;
|
||||
private final static String TEST_OUT = "test-out-0";
|
||||
|
||||
@Resource
|
||||
private StreamBridge streamBridge;
|
||||
|
||||
/**
|
||||
* 发送字符消息
|
||||
*/
|
||||
public void send(String msg) {
|
||||
source.output().send(MessageBuilder.withPayload(msg).build());
|
||||
streamBridge.send(TEST_OUT, MessageBuilder.withPayload(msg).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送带tag的对象消息
|
||||
*/
|
||||
public <T> void sendWithTags(T msg, String tag) {
|
||||
Message message = MessageBuilder.withPayload(msg)
|
||||
Message<T> message = MessageBuilder.withPayload(msg)
|
||||
.setHeader(MessageConst.PROPERTY_TAGS, tag)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
|
||||
.build();
|
||||
source.output().send(message);
|
||||
streamBridge.send(TEST_OUT, message);
|
||||
}
|
||||
}
|
||||
@@ -6,27 +6,16 @@ spring:
|
||||
name: rocketmq-produce
|
||||
cloud:
|
||||
stream:
|
||||
bindings:
|
||||
test-out-0:
|
||||
destination: test-topic
|
||||
content-type: application/json
|
||||
group: produce-group
|
||||
rocketmq:
|
||||
binder:
|
||||
# RocketMQ 服务地址
|
||||
name-server: 192.168.28.130:9876
|
||||
bindings:
|
||||
output:
|
||||
producer:
|
||||
group: produce-group
|
||||
output2:
|
||||
producer:
|
||||
group: test-group2
|
||||
bindings:
|
||||
output:
|
||||
destination: test-topic
|
||||
content-type: application/json
|
||||
|
||||
logging:
|
||||
level:
|
||||
org:
|
||||
springframework:
|
||||
cloud:
|
||||
stream:
|
||||
binder:
|
||||
rocketmq: DEBUG
|
||||
org.springframework.context.support: debug
|
||||
Reference in New Issue
Block a user