StompConnection connection = new StompConnection(); connection.open("localhost", 61613); connection.connect("system", "manager"); StompFrame connect = connection.receive(); if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) { throw new Exception ("Not connected"); } connection.begin("tx1"); connection.send("/queue/test", "message1", "tx1", null); connection.send("/queue/test", "message2", "tx1", null); connection.commit("tx1"); connection.subscribe("/queue/test", Subscribe.AckModeValues.CLIENT); connection.begin("tx2"); StompFrame message = connection.receive(); System.out.println(message.getBody()); connection.ack(message, "tx2"); message = connection.receive(); System.out.println(message.getBody()); connection.ack(message, "tx2"); connection.commit("tx2"); connection.disconnect();
public String receiveFrame() throws Exception { return receiveFrame(RECEIVE_TIMEOUT); }
System.setProperty("javax.net.ssl.keyStore", "/home/foo/.keystore/client.ks"); System.setProperty("javax.net.ssl.keyStorePassword", "changeme"); System.setProperty("javax.net.ssl.trustStore", "/home/foo/.keystore/client.ts"); StompConnection connection = new StompConnection(); SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory .getDefault(); SSLSocket sslsocket = (SSLSocket) factory.createSocket("127.0.0.1", 61612); connection.open(sslsocket);
public void send(String destination, String message, String transaction, HashMap<String, String> headers) throws Exception { if (headers == null) { headers = new HashMap<String, String>(); } headers.put("destination", destination); if (transaction != null) { headers.put("transaction", transaction); } StompFrame frame = new StompFrame("SEND", headers, message.getBytes()); sendFrame(frame.format()); }
public void connect(HashMap<String, String> headers) throws Exception { StompFrame frame = new StompFrame("CONNECT", headers); sendFrame(frame.format()); StompFrame connect = receive(); if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) { throw new Exception ("Not connected: " + connect.getBody()); } }
public void ack(String messageId) throws Exception { ack(messageId, null); }
public void subscribe(String destination) throws Exception { subscribe(destination, null, null); }
public void connect(String username, String password) throws Exception { connect(username, password, null); }
public void send(String destination, String message) throws Exception { send(destination, message, null, null); }
public void open(String host, int port) throws IOException, UnknownHostException { open(new Socket(host, port)); }
public StompFrame receive() throws Exception { return receive(RECEIVE_TIMEOUT); }
public String receiveFrame(long timeOut) throws Exception { stompSocket.setSoTimeout((int)timeOut); InputStream is = stompSocket.getInputStream(); int c = 0; for (;;) { c = is.read(); if (c < 0) { throw new IOException("socket closed."); } else if (c == 0) { c = is.read(); if (c == '\n') { // end of frame return stringFromBuffer(inputBuffer); } else { inputBuffer.write(0); inputBuffer.write(c); } } else { inputBuffer.write(c); } } }
public void disconnect() throws Exception { disconnect(null); }
public void ack(String messageId, String transaction) throws Exception { HashMap<String, String> headers = new HashMap<String, String>(); headers.put("message-id", messageId); if (transaction != null) headers.put("transaction", transaction); StompFrame frame = new StompFrame("ACK", headers); sendFrame(frame.format()); }
public void connect(String username, String password, String client) throws Exception { HashMap<String, String> headers = new HashMap(); headers.put("login", username); headers.put("passcode", password); if (client != null) { headers.put("client-id", client); } StompFrame frame = new StompFrame("CONNECT", headers); sendFrame(frame.format()); StompFrame connect = receive(); if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) { throw new Exception ("Not connected: " + connect.getBody()); } }
public void ack(String messageId) throws Exception { ack(messageId, null); }
public void subscribe(String destination) throws Exception { subscribe(destination, null, null); }
public void connect(String username, String password) throws Exception { connect(username, password, null); }
public void send(String destination, String message) throws Exception { send(destination, message, null, null); }
public void open(String host, int port) throws IOException, UnknownHostException { open(new Socket(host, port)); }