Java Code Examples for org.apache.activemq.transport.stomp.StompConnection#receive()
The following examples show how to use
org.apache.activemq.transport.stomp.StompConnection#receive() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StompClient.java From amazon-mq-workshop with Apache License 2.0 | 5 votes |
private static void receiveMessages(StompConnection connection, String type, String destination) throws Exception { connection.subscribe(String.format("/%s/%s", type, destination), Subscribe.AckModeValues.AUTO); while (true) { try { StompFrame message = connection.receive(60000); System.out.println(String.format("%s - Receiver: received '%s'", df.format(new Date()), message.getBody())); } catch (SocketTimeoutException e) { // ignore } } }
Example 2
Source File: StompExample.java From chipster with MIT License | 5 votes |
public static void main(String args[]) throws Exception { StompConnection connection = new StompConnection(); connection.open("localhost", 61616); connection.connect("system", "manager"); connection.begin("tx1"); connection.send("/queue/test", "message1"); connection.send("/queue/test", "message2"); 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(); }
Example 3
Source File: ThreeBrokerStompTemporaryQueueTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
public void testStompTemporaryQueue() throws Exception { // Setup broker networks bridgeAndConfigureBrokers("BrokerA", "BrokerB"); bridgeAndConfigureBrokers("BrokerA", "BrokerC"); bridgeAndConfigureBrokers("BrokerB", "BrokerA"); bridgeAndConfigureBrokers("BrokerB", "BrokerC"); bridgeAndConfigureBrokers("BrokerC", "BrokerA"); bridgeAndConfigureBrokers("BrokerC", "BrokerB"); startAllBrokers(); waitForBridgeFormation(); Thread.sleep(1000); stompConnection = new StompConnection(); stompConnection.open("localhost", 61614); // Creating a temp queue stompConnection.sendFrame("CONNECT\n" + "login:system\n" + "passcode:manager\n\n" + Stomp.NULL); StompFrame frame = stompConnection.receive(); assertTrue(frame.toString().startsWith("CONNECTED")); stompConnection.subscribe("/temp-queue/meaningless", "auto"); stompConnection.send("/temp-queue/meaningless", "Hello World"); frame = stompConnection.receive(3000); assertEquals("Hello World", frame.getBody()); Thread.sleep(1000); assertEquals("Destination", 1, brokers.get("BrokerA").broker.getAdminView().getTemporaryQueues().length); assertEquals("Destination", 1, brokers.get("BrokerB").broker.getAdminView().getTemporaryQueues().length); assertEquals("Destination", 1, brokers.get("BrokerC").broker.getAdminView().getTemporaryQueues().length); int advisoryTopicsForTempQueues; advisoryTopicsForTempQueues = countTopicsByName("BrokerA", "ActiveMQ.Advisory.Consumer.Queue.ID"); assertEquals("Advisory topic should be present", 1, advisoryTopicsForTempQueues); advisoryTopicsForTempQueues = countTopicsByName("BrokerB", "ActiveMQ.Advisory.Consumer.Queue.ID"); assertEquals("Advisory topic should be present", 1, advisoryTopicsForTempQueues); advisoryTopicsForTempQueues = countTopicsByName("BrokerC", "ActiveMQ.Advisory.Consumer.Queue.ID"); assertEquals("Advisory topic should be present", 1, advisoryTopicsForTempQueues); stompConnection.disconnect(); Thread.sleep(1000); advisoryTopicsForTempQueues = countTopicsByName("BrokerA", "ActiveMQ.Advisory.Consumer.Queue.ID"); assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues); advisoryTopicsForTempQueues = countTopicsByName("BrokerB", "ActiveMQ.Advisory.Consumer.Queue.ID"); assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues); advisoryTopicsForTempQueues = countTopicsByName("BrokerC", "ActiveMQ.Advisory.Consumer.Queue.ID"); assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues); LOG.info("Restarting brokerA"); BrokerItem brokerItem = brokers.remove("BrokerA"); if (brokerItem != null) { brokerItem.destroy(); } BrokerService restartedBroker = createAndConfigureBroker(new URI("broker:(tcp://localhost:61616,stomp://localhost:61613)/BrokerA")); bridgeAndConfigureBrokers("BrokerA", "BrokerB"); bridgeAndConfigureBrokers("BrokerA", "BrokerC"); restartedBroker.start(); waitForBridgeFormation(); Thread.sleep(3000); assertEquals("Destination", 0, brokers.get("BrokerA").broker.getAdminView().getTemporaryQueues().length); assertEquals("Destination", 0, brokers.get("BrokerB").broker.getAdminView().getTemporaryQueues().length); assertEquals("Destination", 0, brokers.get("BrokerC").broker.getAdminView().getTemporaryQueues().length); advisoryTopicsForTempQueues = countTopicsByName("BrokerA", "ActiveMQ.Advisory.Consumer.Queue.ID"); assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues); advisoryTopicsForTempQueues = countTopicsByName("BrokerB", "ActiveMQ.Advisory.Consumer.Queue.ID"); assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues); advisoryTopicsForTempQueues = countTopicsByName("BrokerC", "ActiveMQ.Advisory.Consumer.Queue.ID"); assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues); }