An example to demonstrate how to use WebSocket to send messages to a messaging server.
This example sends a stream of 10
MessageFrame to the specified server and expects 10 acknowledgments in
response.
There are three ways of running this example:
Default
The default way is to just run this class with no arguments, which will start a server (
MessagingServer)
on an ephemeral port and then send an HTTP request to that server and print the response.
If you want to see how
MessagingServer work, you can run
MessagingServer by yourself and
then pass the port on which the server started to this class as a program argument:
java io.reactivex.netty.examples.http.ws.messaging.MessagingClient [server port]
Existing HTTP server
You can also use this client to send a GET request "/ws" to an existing HTTP server (different than
MessagingServer) by passing the port and host of the existing server similar to the case above:
java io.reactivex.netty.examples.http.ws.messaging.MessagingClient [server port]
If the server host is omitted from the above, it defaults to "127.0.0.1"
In all the above usages, this client will print the response received from the server.
Retry
If the client does not receive acknowledgments for any message ID for 10 seconds, it re-sends the message. See
PendingMessageTracker for the relevant code.
This means that this example follows the atleast once delivery semantics.
Message buffering
Since, message production is asynchronous, if this client can not connect to the server, it will buffer the messages
in memory and wait for the server to come up.