mirror of
https://github.com/jlengrand/vert.x.git
synced 2026-03-10 08:51:19 +00:00
fixed stomp client examples
This commit is contained in:
@@ -19,7 +19,7 @@ public class StompPerf {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
StompClient.connect(8080, new StompConnectHandler() {
|
||||
StompClient.connect(8181, new StompConnectHandler() {
|
||||
public void onConnect(final StompConnection conn) {
|
||||
final int warmup = 500000;
|
||||
final int numMessages = 1000000;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
require "stomp"
|
||||
require "buffer"
|
||||
include Stomp
|
||||
|
||||
topic = "test-topic"
|
||||
|
||||
# A very simple example using STOMP to send and consume some messages
|
||||
# Use this with the java STOMP server in src/examples/java/stomp
|
||||
|
||||
Stomp::Client.connect(8080) do |conn|
|
||||
StompClient.connect(8181) do |conn|
|
||||
conn.subscribe(topic) { |headers, body| puts "Got message #{body}" }
|
||||
(1..10).each { |i| conn.send(topic, Buffer.from_str("hello #{i}\n")) }
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ num_messages = 1000000;
|
||||
count = 0
|
||||
start = nil
|
||||
|
||||
Client.connect(8080, "localhost") { |conn|
|
||||
Client.connect(8181, "localhost") { |conn|
|
||||
conn.subscribe("test-topic") { |msg|
|
||||
count += 1
|
||||
if count == warmup + num_messages
|
||||
|
||||
@@ -9,6 +9,13 @@ import java.io.UnsupportedEncodingException;
|
||||
* User: tim
|
||||
* Date: 27/06/11
|
||||
* Time: 17:49
|
||||
*
|
||||
* A RecordParser takes as input a fragmented sequence of Buffers and outputs a record, which is also a Buffer
|
||||
* Records can be delimited by a sequence of bytes, or can be fixed size.
|
||||
* The delimiters can be changed or the parser can be switched between fixed size mode or delimited mode
|
||||
* any time after creation. This enables the parser to be used for spitting out records for protocols which may
|
||||
* involve a combination of delimited and fixed size records or where the delimiter changes.
|
||||
* The parser is not character encoding aware, and works with sequences of bytes not characters
|
||||
*/
|
||||
public class RecordParser extends DataHandler {
|
||||
|
||||
@@ -27,8 +34,23 @@ public class RecordParser extends DataHandler {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public static RecordParser newDelimited(final String delim, final String enc, final DataHandler output) {
|
||||
return newDelimited(delimToByteArray(delim, enc), output);
|
||||
/**
|
||||
* Helper method to convert a latin-1 String to an array of bytes for use as a delimiter
|
||||
* Please do not use this for non latin-1 characters
|
||||
* @param str
|
||||
* @return The byte[] form of the string
|
||||
*/
|
||||
public static byte[] latin1StringToBytes(String str) {
|
||||
byte[] bytes = new byte[str.length()];
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
bytes[i] = (byte)(c & 0xFF);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RecordParser newDelimited(String delim, DataHandler output) {
|
||||
return newDelimited(latin1StringToBytes(delim), output);
|
||||
}
|
||||
|
||||
public static RecordParser newDelimited(byte[] delim, DataHandler output) {
|
||||
@@ -43,16 +65,8 @@ public class RecordParser extends DataHandler {
|
||||
return ls;
|
||||
}
|
||||
|
||||
private static byte[] delimToByteArray(String delim, String enc) {
|
||||
try {
|
||||
return delim.getBytes(enc);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("Unsupported encoding " + enc);
|
||||
}
|
||||
}
|
||||
|
||||
public void delimitedMode(final String delim, final String enc) {
|
||||
delimitedMode(delimToByteArray(delim, enc));
|
||||
public void delimitedMode(String delim) {
|
||||
delimitedMode(latin1StringToBytes(delim));
|
||||
}
|
||||
|
||||
public void delimitedMode(byte[] delim) {
|
||||
|
||||
@@ -28,9 +28,9 @@ module ParserTools
|
||||
@java_parser.onData(data._to_java_buffer)
|
||||
end
|
||||
|
||||
def RecordParser.new_delimited(delim, enc = "UTF-8", proc = nil, &output_block)
|
||||
def RecordParser.new_delimited(delim, proc = nil, &output_block)
|
||||
output_block = proc if proc
|
||||
RecordParser.new(org.nodex.core.parsetools.RecordParser.newDelimited(delim, enc, OutputCallback.new(output_block)))
|
||||
RecordParser.new(org.nodex.core.parsetools.RecordParser.newDelimited(delim, OutputCallback.new(output_block)))
|
||||
end
|
||||
|
||||
def RecordParser.new_bytes_delimited(bytes, proc = nil, &output_block)
|
||||
@@ -43,8 +43,8 @@ module ParserTools
|
||||
RecordParser.new(org.nodex.core.parsetools.RecordParser.newFixed(size, OutputCallback.new(output_block)))
|
||||
end
|
||||
|
||||
def delimited_mode(delim, enc)
|
||||
@java_parser.delimitedMode(delim, enc)
|
||||
def delimited_mode(delim)
|
||||
@java_parser.delimitedMode(delim)
|
||||
end
|
||||
|
||||
def bytes_delimited_mode(bytes)
|
||||
|
||||
Reference in New Issue
Block a user