org.apache.activemq.transport.stomp.StompConnection Java Examples
The following examples show how to use
org.apache.activemq.transport.stomp.StompConnection.
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 | 6 votes |
private static void sendMessages(StompConnection connection, String type, String destination, String name, int interval, WrapInt count) throws Exception { while (true) { count.v++; connection.begin("tx1"); String message = String.format("[%s://%s] [%s] Message number %s", type, destination, name, count.v); connection.send(String.format("/%s/%s", type, destination), message, "tx1", null); connection.commit("tx1"); if (interval > 0) { System.out.println(String.format("%s - Sender: sent '%s'", df.format(new Date()), message)); try { Thread.sleep(interval); } catch (InterruptedException e) { e.printStackTrace(); } } } }
Example #2
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 #3
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 #4
Source File: StompClient.java From amazon-mq-workshop with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { CommandLine cmd = parseAndValidateCommandLineArguments(args); final WrapInt count = new WrapInt(); final long ds = System.currentTimeMillis(); final int interval = Integer.parseInt(cmd.getOptionValue("interval", "1000")); String name = cmd.getOptionValue("name", UUID.randomUUID().toString()); registerShutdownHook(count, ds, interval); StompConnection connection = new StompConnection(); String[] url = cmd.getOptionValue("url").split("://"); String[] hostAndPort = url[1].split(":"); try { String user = null; String password = null; String secrets = null; if (cmd.hasOption("user") && cmd.hasOption("password")) { user = cmd.getOptionValue("user"); password = cmd.getOptionValue("password"); } else { secrets = getUserPassword("MQBrokerUserPassword"); if (secrets!=null && !secrets.isEmpty()) { user = secrets.split(",")[0]; password = secrets.split(",")[1]; } } SocketFactory factory = SSLSocketFactory.getDefault(); Socket socket = factory.createSocket(hostAndPort[0], Integer.parseInt(hostAndPort[1])); connection.open(socket); connection.connect(user, password, name); System.out.println(String.format("Successfully connected to %s", cmd.getOptionValue("url"))); if (cmd.getOptionValue("mode").contentEquals("sender")) { sendMessages(connection, cmd.getOptionValue("type"), cmd.getOptionValue("destination"), name, interval, count); } else { receiveMessages(connection, cmd.getOptionValue("type"), cmd.getOptionValue("destination")); } } catch (javax.jms.JMSSecurityException ex) { System.out.println(String.format("Error: %s", ex.getMessage())); System.exit(1); } }
Example #5
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); }