Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 从Kafka获取消息,发送到Rsocket并从React客户端接收_Reactjs_Spring_Spring Boot_Spring Cloud Stream_Rsocket - Fatal编程技术网

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

Reactjs 从Kafka获取消息,发送到Rsocket并从React客户端接收,reactjs,spring,spring-boot,spring-cloud-stream,rsocket,Reactjs,Spring,Spring Boot,Spring Cloud Stream,Rsocket,我正在尝试使用Spring cloud stream将数据从kafka发送到Rsocket,然后在React上表示数据 这是我的配置 @Configuration public class RsocketConsumerConfiguration { @Bean public Sinks.Many<Data> sender(){ return Sinks.many().multicast().directBestEffort(); }

我正在尝试使用Spring cloud stream将数据从kafka发送到Rsocket,然后在React上表示数据

这是我的配置

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

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

鉴于数据似乎是直接从卡夫卡(通过Spring)传输到客户机的,也许这样做更有意义


披露:我不是那篇文章的作者,但在作者工作的那家公司工作。我们经常看到这个用例,所以希望这种方法可能有用。

这个问题有什么进展吗?更新了answer@meuhedetmeuhedet:不要用解决方案更新问题文本!如果您将解决方案作为您自己问题的答案发布,效果会更好!您也可以将自己的答案标记为已接受。通过这种方式,读者很容易看到问题得到了解决。此外,读者还可以对您的答案进行投票。:)@Lii有很多新代码。我该把它放在哪里?@meuhedetmeuhedet。我不明白。。。你不能把代码放在答案文本的代码块中吗?
@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")
                    });