gpt4 book ai didi

reactjs - 从 Kafka 获取消息,发送到 Rsocket 并从 React 客户端接收

转载 作者:行者123 更新时间:2023-12-03 20:46:15 30 4
gpt4 key购买 nike

我正在尝试使用 Spring 云流将数据从 kafka 发送到 Rsocket,然后在 React 上表示数据
这是我的配置。

@Configuration
public class RsocketConsumerConfiguration {

@Bean
public Sinks.Many<Data> sender(){
return Sinks.many().multicast().directBestEffort();
}


}
@ Controller
公共(public)类服务器 Controller {
@Autowired
private Sinks.Many<Data> integer;

@MessageMapping("integer")
public Flux<Data> integer() {
return integer.asFlux();
}
@EnableBinding(IClientProcessor.class)
public class Listener {

@Autowired
private Sinks.Many<Data> integer;

@StreamListener(IClientProcessor.INTEGER)
public void integer(Data val) {
System.out.println(val);
integer.tryEmitNext(val);
}

}

   let  client = new RSocketClient({
transport: new RSocketWebSocketClient(
{
url: 'ws://localhost:7000/ws',
wsCreator: (url) => new WebSocket(url),
debug: true,
},
BufferEncoders,
),
setup: {
dataMimeType: "application/json",
metadataMimeType: MESSAGE_RSOCKET_COMPOSITE_METADATA.string,
keepAlive: 5000,
lifetime: 60000,
},
});

client
.then(rsocket => {
console.log("Connected to rsocket");
rsocket.requestStream({
metadata: Buffer.from(encodeCompositeMetadata([
[MESSAGE_RSOCKET_ROUTING, encodeRoute("integer")],
])),

})
.subscribe({
onSubscribe: s => {
s.request(2147483647)
},
onNext: (p) => {
let newData = {
time: new Date(JSON.parse(p.data).time).getUTCSeconds(),
integer: JSON.parse(p.data).integer
}
newData.integer >100?setInteger(currentData => [newData, ...currentData]):setInt(currentData => [newData, ...currentData])
console.log(newData)
},
onError: (e) => console.error(e),
onComplete: () => console.log("Done")
});

spring.cloud.stream.bindings.integer.destination=整数
无法在 react 应用程序中看到它。请指教。我做错了什么?

最佳答案

鉴于数据似乎直接从 Kafka(通过 Spring)传输到客户端,也许 stream Kafka messages via an internet-messaging broker to Internet-facing clients over WebSockets 更有意义。 .
披露:我不是那篇文章的作者,但在作者工作的那家公司工作。我们经常看到这个用例,所以期望这种方法可能有用。

关于reactjs - 从 Kafka 获取消息,发送到 Rsocket 并从 React 客户端接收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65463438/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com