Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveMQ: How to get all messages in a queue for Receiver (Java)
    text
    copied!<p>Here is the Server's code: </p> <pre><code>import java.net.UnknownHostException; import java.io.IOException; import org.apache.activemq.transport.stomp.StompConnection; public class Server{ public static void main(String[] args) { try { StompConnection con = new StompConnection(); con.open("localhost", 61618); con.connect("admin", "admin123"); con.begin("a1"); con.send("/queue/test1", "This is test message 1"); con.send("/queue/test1", "This is test message 2"); con.send("/queue/test1", "This is test message 3"); con.commit("a1"); con.disconnect(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } </code></pre> <p>Here is the Client's code:</p> <pre><code>import java.io.IOException; import java.net.UnknownHostException; import java.util.Scanner; import org.apache.activemq.transport.stomp.StompConnection; import org.apache.activemq.transport.stomp.StompFrame; import org.apache.activemq.transport.stomp.Stomp.Headers.Subscribe; public class Client { public static void main(String[] args) { try { //login. Scanner in = new Scanner(System.in); System.out.print("Password: "); String pass = in.next(); if (!"123".equals(pass)){ System.out.println("Sorry, wrong password."); } else { StompConnection con= new StompConnection(); con.open("localhost", 61618); con.connect("admin", "admin123"); con.subscribe("/queue/test1", Subscribe.AckModeValues.CLIENT); con.begin("a2"); StompFrame mes = con.receive(); System.out.println(mes.getBody()); con.ack(message, "a2"); con.commit("a2"); con.disconnect(); } } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } </code></pre> <p>I have 3 messages on Server. However, I only can get 1 message per time in Client. How to get all the messages in the queue in a run? Anyone can help me? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload