xuekang
2024-05-10 edf3b7fde038fcf3e6d86b8b4b88c2ff6f9014cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package org.dromara.stream.mq.producer;
 
import org.dromara.stream.mq.TestMessaging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;
 
import java.util.UUID;
 
@Component
public class TestStreamProducer {
 
    @Autowired
    private StreamBridge streamBridge;
 
    public void streamTestMsg(String msg) {
        // 构建消息对象
        TestMessaging testMessaging = new TestMessaging()
            .setMsgId(UUID.randomUUID().toString())
            .setMsgText(msg);
        streamBridge.send("demo-out-0", MessageBuilder.withPayload(testMessaging).build());
    }
}