micronaut RxWebSocketClient如何动态连接到客户端?

时间:2019-06-21 12:49:48

标签: micronaut

@Client("http://localhost:8082")我在提供的链接的这段代码上有以下声明:

/**
 * TODO this is currently hard wired to something that is dynamic in command object host/port
 */
@Inject
@Client("http://localhost:8082")
RxWebSocketClient webSocketClient;

还有segment of code远处:

 ChatClientWebSocket chatClient = webSocketClient.connect(ChatClientWebSocket.class, "/ws/process").blockingFirst();
                    chatClient.send(serializeMessage(msg));

理想情况下,我想基于command object中的现有数据来定义哪个客户端:

 private String host;
    private int port;

在上一类中,主机端口是由此微服务本身生成的,出于测试目的,该主机端口是物理绑定的,但假设它动态出现在不同的端口127.0.0.1:8083127.0.0.1:8084上,等等如何动态主机端口声明在顶部声明的内容,即

@Client("http://localhost:8082")

理想情况下,我需要做的是这样的事情 因此,客户端连接是基于当前对象主机端口定义而动态的,而不是在动态发生之外的页面顶部进行硬编码的。

                @Client(cmd.getHost()+":"+cmd.getPort())
                RxWebSocketClient webSocketClient;
                ChatClientWebSocket chatClient = webSocketClient.connect(ChatClientWebSocket.class, "/ws/process").blockingFirst();
                chatClient.send(serializeMessage(msg));

1 个答案:

答案 0 :(得分:0)

您可以尝试使用属性:

@Client("${myapp.api.twitter.url}")
RxWebSocketClient webSocketClient;