xuekang
2024-05-11 3870bc26f80f38aa202fae6d07b351ed51b7957e
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 LogStreamProducer {
 
    @Autowired
    private StreamBridge streamBridge;
 
    public void streamLogMsg(String msg) {
        // 构建消息对象
        TestMessaging testMessaging = new TestMessaging()
            .setMsgId(UUID.randomUUID().toString())
            .setMsgText(msg);
        streamBridge.send("log-out-0", MessageBuilder.withPayload(testMessaging).build());
    }
}