Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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_Reactjs_Spring_Apache Kafka_Spring Cloud Stream_Rsocket - Fatal编程技术网

Reactjs 从kafka获取数据并将其发送到RSocket

Reactjs 从kafka获取数据并将其发送到RSocket,reactjs,spring,apache-kafka,spring-cloud-stream,rsocket,Reactjs,Spring,Apache Kafka,Spring Cloud Stream,Rsocket,我正在尝试从kafka获取消息,并使用Spring将其发送到RSocket。使用React在SpringJava上发布服务器端和客户端 @Configuration @EnableConfigurationProperties(RsocketConsumerProperties.class) public class RsocketConsumerConfiguration { @Bean public Function<Integer, Mono<Integer&

我正在尝试从kafka获取消息,并使用Spring将其发送到RSocket。使用React在SpringJava上发布服务器端和客户端

@Configuration
@EnableConfigurationProperties(RsocketConsumerProperties.class)
public class RsocketConsumerConfiguration {

    @Bean
    public Function<Integer, Mono<Integer>> rsocketConsumer(RSocketRequester.Builder builder,
                                                            RsocketConsumerProperties rsocketConsumerProperties) {
        RSocketRequester rSocketRequester = builder.websocket(URI.create("ws://localhost:7000/"));
        return input -> rSocketRequester.route(rsocketConsumerProperties.getRoute()).data(input).retrieveMono(Integer.class);
    }
}

您可以这样做
requester.route(“input”).data(“欢迎使用Rsocket”).send()我们有这个:

   /**
     * Perform a {@link RSocket#fireAndForget fireAndForget} sending the
     * provided data and metadata.
     * @return a completion that indicates if the payload was sent
     * successfully or not. Note, however that is a one-way send and there
     * is no indication of whether or how the event was handled on the
     * remote end.
     */
    Mono<Void> send();

我想说的是,在你展示的代码中,它意味着客户端。服务器位于另一端,在那里为
ws://
协议打开
7000
端口。因此,请确保您理解并正确配置了所有部件。例如,我不明白为什么在
侦听器
类中需要
@RestController

Hi-Artem。谢谢你的回复。我纠正了restcontroller,因为它不正确。我想做的是从卡夫卡那里得到消息,然后把它们发送到rsocket。你有什么建议怎么做?我想使用spring读取来自kafka的消息,并将它们发送给react(javascript),您可以使用
RSocketRequester
正确地进行操作。您唯一错过的是对该
send()
结果的
subscribe()
。您还可以使用函数式API查看最新的Spring Cloud Stream,并调查以下项目:。它有一个
RScoket接收器应用程序,用于执行像您这样的任务。与卡夫卡活页夹一起,您将实现您的目标,而无需编写代码!看起来很有希望,谢谢。让我们来考虑一下:meuhedetmeuhedet这是一个有用的答案。你应该考虑接受它(使用V图标,当然要投票)。
@Controller
public class ServerController {

    @MessageMapping("data")
    public Mono<Integer> hello(Integer integer) {
        return Mono.just(integer);
    }

}

  client.connect().subscribe({
    onComplete: socket => {
        socket.fireAndForget({
          data: { message: "hello from javascript!" },
          metadata: null
        });
      },
      onError: error => {
        console.log("got error");
        console.error(error);
      },
      onSubscribe: cancel => {
        /* call cancel() to abort */
        console.log("subscribe!");
        console.log(cancel);
        // cancel.cancel();
      }
    });
   
   /**
     * Perform a {@link RSocket#fireAndForget fireAndForget} sending the
     * provided data and metadata.
     * @return a completion that indicates if the payload was sent
     * successfully or not. Note, however that is a one-way send and there
     * is no indication of whether or how the event was handled on the
     * remote end.
     */
    Mono<Void> send();
    /**
     * Build an {@link RSocketRequester} with an
     * {@link io.rsocket.core.RSocketClient} that connects over WebSocket to
     * the given URL. The requester can be used to make requests
     * concurrently. Requests are made over a shared connection that is also
     * re-established as needed when further requests are made.
     * @param uri the URL to connect to
     * @return the created {@code RSocketRequester}
     * @since 5.3
     */
    RSocketRequester websocket(URI uri);