无法在服务器端读取 requestResponse 调用的负载
Unable to read the payload of a requestResponse call at the server side
考虑下面的 TS 客户端代码片段:
this.rSocketClient.connect().subscribe({
onComplete: socket => {
const endpoint = ‚accesscode’;
socket.requestResponse({
data: clientId, //the clientId is a non-empty string
metadata: String.fromCharCode(endpoint.length) + endpoint
}).subscribe({
onComplete: () => console.log(’Done’),
onError: error => {
console.log('Connection has been closed due to:: ' + error);
},
});
},
onError: error => console.error(error),
onSubscribe: cancel => {}
});
我想知道我的服务器 accesscode
端点的签名应该是什么样子。事实上,我尝试了以下解决方案,但没有达到预期效果。事实上,当我在 getAccessCode
内放置一个断点时,调用被捕获但 clientId
无法解析:
@MessageMapping("accesscode")
public Mono<String> getAccessCode(@Payload String clientId) {
log.info("requested clientId:"+clientId);
//Server side processing to read the corresponding 'accesscode' from the DB
return Mono.just(DefaultPayload.create(accesscode));
}
我们将不胜感激任何帮助。
Spring 中的 rsocket 就像 API 作为 Web Socket (https://rsocket.io/),它提供了一个 API 类型(通过 TCP)服务供客户端使用应用程序。因此,端点是您调用以获取某些数据资源的一些 URI。所以,它是一个类似这样的 URI:ws://localhost:8080/WebsocketTest/testserver 或 yourtag://url:portnumber/resource 或者如果您在本地测试,它甚至可以是 localhost。
端点最好使用 clientId 调用。这取决于您的 rsocket 设计。另外,你想在这里做什么?您尝试通过 rsocket 提供什么服务?
您可以在此处找到有关该主题的一些专家:https://gitter.im/rsocket/rsocket-java
您的客户端需要发送 spring-boot 决定关闭的路由信息。参见 https://domenicosibilio.medium.com/rsocket-with-spring-boot-js-zero-to-hero-ef63128f973d
具体看客户端设置中的mime类型,以及你代码中@MessageMapping要匹配的路由。
// Create an instance of a client
client = new RSocketClient({
serializers: {
data: JsonSerializer,
metadata: IdentitySerializer
},
setup: {
// ms btw sending keepalive to server
keepAlive: 60000,
// ms timeout if no keepalive response
lifetime: 180000,
// format of `data`
dataMimeType: 'application/json',
// format of `metadata`
metadataMimeType: 'message/x.rsocket.routing.v0',
},
transport: new RSocketWebSocketClient({
url: 'ws://localhost:8080/tweetsocket'
}),
});
// Open the connection
client.connect().subscribe({
onComplete: socket => {
// socket provides the rsocket interactions fire/forget, request/response,
// request/stream, etc as well as methods to close the socket.
socket.requestStream({
data: {
'author': document.getElementById("author-filter").value
},
metadata: String.fromCharCode('tweets.by.author'.length) + 'tweets.by.author',
}).subscribe({
onComplete: () => console.log('complete'),
onError: error => {
console.log(error);
addErrorMessage("Connection has been closed due to ", error);
},
onNext: payload => {
console.log(payload.data);
addMessage(payload.data);
},
onSubscribe: subscription => {
subscription.request(2147483647);
},
});
},
onError: error => {
console.log(error);
addErrorMessage("Connection has been refused due to ", error);
},
onSubscribe: cancel => {
/* call cancel() to abort */
}
});
考虑下面的 TS 客户端代码片段:
this.rSocketClient.connect().subscribe({
onComplete: socket => {
const endpoint = ‚accesscode’;
socket.requestResponse({
data: clientId, //the clientId is a non-empty string
metadata: String.fromCharCode(endpoint.length) + endpoint
}).subscribe({
onComplete: () => console.log(’Done’),
onError: error => {
console.log('Connection has been closed due to:: ' + error);
},
});
},
onError: error => console.error(error),
onSubscribe: cancel => {}
});
我想知道我的服务器 accesscode
端点的签名应该是什么样子。事实上,我尝试了以下解决方案,但没有达到预期效果。事实上,当我在 getAccessCode
内放置一个断点时,调用被捕获但 clientId
无法解析:
@MessageMapping("accesscode")
public Mono<String> getAccessCode(@Payload String clientId) {
log.info("requested clientId:"+clientId);
//Server side processing to read the corresponding 'accesscode' from the DB
return Mono.just(DefaultPayload.create(accesscode));
}
我们将不胜感激任何帮助。
rsocket 就像 API 作为 Web Socket (https://rsocket.io/),它提供了一个 API 类型(通过 TCP)服务供客户端使用应用程序。因此,端点是您调用以获取某些数据资源的一些 URI。所以,它是一个类似这样的 URI:ws://localhost:8080/WebsocketTest/testserver 或 yourtag://url:portnumber/resource 或者如果您在本地测试,它甚至可以是 localhost。
端点最好使用 clientId 调用。这取决于您的 rsocket 设计。另外,你想在这里做什么?您尝试通过 rsocket 提供什么服务?
您可以在此处找到有关该主题的一些专家:https://gitter.im/rsocket/rsocket-java
您的客户端需要发送 spring-boot 决定关闭的路由信息。参见 https://domenicosibilio.medium.com/rsocket-with-spring-boot-js-zero-to-hero-ef63128f973d
具体看客户端设置中的mime类型,以及你代码中@MessageMapping要匹配的路由。
// Create an instance of a client
client = new RSocketClient({
serializers: {
data: JsonSerializer,
metadata: IdentitySerializer
},
setup: {
// ms btw sending keepalive to server
keepAlive: 60000,
// ms timeout if no keepalive response
lifetime: 180000,
// format of `data`
dataMimeType: 'application/json',
// format of `metadata`
metadataMimeType: 'message/x.rsocket.routing.v0',
},
transport: new RSocketWebSocketClient({
url: 'ws://localhost:8080/tweetsocket'
}),
});
// Open the connection
client.connect().subscribe({
onComplete: socket => {
// socket provides the rsocket interactions fire/forget, request/response,
// request/stream, etc as well as methods to close the socket.
socket.requestStream({
data: {
'author': document.getElementById("author-filter").value
},
metadata: String.fromCharCode('tweets.by.author'.length) + 'tweets.by.author',
}).subscribe({
onComplete: () => console.log('complete'),
onError: error => {
console.log(error);
addErrorMessage("Connection has been closed due to ", error);
},
onNext: payload => {
console.log(payload.data);
addMessage(payload.data);
},
onSubscribe: subscription => {
subscription.request(2147483647);
},
});
},
onError: error => {
console.log(error);
addErrorMessage("Connection has been refused due to ", error);
},
onSubscribe: cancel => {
/* call cancel() to abort */
}
});