|
|
@ -11,14 +11,13 @@ import { |
|
|
|
WellKnownMimeType, |
|
|
|
APPLICATION_JSON, |
|
|
|
} from "rsocket-core"; |
|
|
|
// MESSAGE_RSOCKET_AUTHENTICATION("message/x.rsocket.authentication.v0", (byte) 0x7C)
|
|
|
|
import { EchoResponder } from "./EchoResponder"; |
|
|
|
import { every } from "rsocket-flowable"; |
|
|
|
import RSocketTcpClient from "rsocket-tcp-client"; |
|
|
|
import RSocketWebSocketClient from "rsocket-websocket-client"; |
|
|
|
|
|
|
|
const maxRSocketRequestN = 2147483647; |
|
|
|
const host = "127.0.0.1"; |
|
|
|
const port = 7000; |
|
|
|
const keepAlive = 60000; |
|
|
|
const lifetime = 180000; |
|
|
|
const dataMimeType = "application/octet-stream"; |
|
|
@ -28,16 +27,17 @@ const address = { host: "localhost", port: 7000 }; |
|
|
|
|
|
|
|
const messageReceiver = (payload) => { |
|
|
|
//do what you want to do with received message
|
|
|
|
if ((payload.metadata as string).slice(1) == "user.queue.reply") console.log("YES"); |
|
|
|
if ((payload.metadata as string).slice(1) == "user.queue.reply") |
|
|
|
console.log("YES"); |
|
|
|
else console.log("No"); |
|
|
|
console.log((payload.metadata as string).slice(1)) |
|
|
|
console.log((payload.metadata as string).slice(1)); |
|
|
|
console.log(payload); |
|
|
|
}; |
|
|
|
const responder = new EchoResponder(messageReceiver); |
|
|
|
|
|
|
|
function getClientTransport(host: string, port: number) { |
|
|
|
return new RSocketWebSocketClient({ |
|
|
|
url: "ws://localhost:7000/client-id", |
|
|
|
url: `ws://${host}:${port}/client-id`, |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
@ -47,7 +47,7 @@ interface Message { |
|
|
|
message: string; |
|
|
|
} |
|
|
|
|
|
|
|
const client = new RSocketClient({ |
|
|
|
const client = new RSocketClient<Object, Encodable>({ |
|
|
|
// send/receive JSON objects instead of strings/buffers
|
|
|
|
serializers: { |
|
|
|
data: JsonSerializer, |
|
|
@ -56,8 +56,17 @@ const client = new RSocketClient({ |
|
|
|
setup: { |
|
|
|
//for connection mapping on server
|
|
|
|
payload: { |
|
|
|
data: "1234", |
|
|
|
metadata: String.fromCharCode("client-id".length) + "client-id", |
|
|
|
data: { id: 1234, name: "John" }, |
|
|
|
// metadata: encodeAndAddWellKnownMetadata(
|
|
|
|
// encodeAndAddCustomMetadata(
|
|
|
|
// Buffer.alloc(0),
|
|
|
|
// "message/x.rsocket.authentication.v0",
|
|
|
|
// Buffer.from("Hello World")
|
|
|
|
// ),
|
|
|
|
// MESSAGE_RSOCKET_ROUTING,
|
|
|
|
// Buffer.from(String.fromCharCode("client-id2".length) + "client-id2")
|
|
|
|
// ),
|
|
|
|
metadata: String.fromCharCode("client-id2".length) + "client-id2" |
|
|
|
}, |
|
|
|
// ms btw sending keepalive to server
|
|
|
|
keepAlive: 60000, |
|
|
@ -75,7 +84,7 @@ const client = new RSocketClient({ |
|
|
|
transport: getClientTransport(address.host, address.port), |
|
|
|
}); |
|
|
|
const route = "user.queue.reply"; |
|
|
|
const sendRoute = "private.news"; |
|
|
|
const sendRoute = "private.news.2"; |
|
|
|
client.connect().subscribe({ |
|
|
|
onComplete: (rSocket) => { |
|
|
|
every(1000).subscribe({ |
|
|
@ -110,7 +119,7 @@ client.connect().subscribe({ |
|
|
|
// });
|
|
|
|
|
|
|
|
rSocket.fireAndForget({ |
|
|
|
data: { toUser: "4567", fromUser: "1234", message: "testHello" }, |
|
|
|
data: <Message>{ toUser: "4567", fromUser: "1234", message: "testHello" }, |
|
|
|
metadata: String.fromCharCode(sendRoute.length) + sendRoute, |
|
|
|
}); |
|
|
|
// S APPLICATION_JSON.string
|
|
|
|