List of usage examples for javax.jms JMSException printStackTrace
public void printStackTrace()
From source file:Replier.java
/** Create JMS client for sending and receiving messages. */ private void start(String broker, String username, String password, String rQueue, String mode) { // Set the operation mode imode = (mode.equals("uppercase")) ? UPPERCASE : LOWERCASE; // Create a connection. try {//from w w w . j a v a 2 s . co m javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createConnection(username, password); session = connect.createSession(true, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create Receivers to application queues as well as a Sender // to use for JMS replies. try { javax.jms.Queue queue = session.createQueue(rQueue); javax.jms.MessageConsumer receiver = session.createConsumer(queue); receiver.setMessageListener(this); replier = session.createProducer(null); // Queue will be set for each reply // Now that all setup is complete, start the Connection connect.start(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); exit(); } try { // Read standard input waiting for "EXIT" command. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); while (true) { System.out.println("\nReplier application:\n" + "============================\n" + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n" + "The application gets requests with JMSReplyTo set on the " + DEFAULT_QUEUE + " queue." + "The message is transformed to all uppercase or all lowercase, and then returned to the requestor." + "The Requestor application displays the result.\n\n" + "Enter EXIT or press Ctrl+C to close the Replier.\n"); String s = stdin.readLine(); if (s == null || s.equalsIgnoreCase("EXIT")) { System.out.println("\nStopping Replier. Please wait..\n>"); exit(); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } }
From source file:Talk.java
/** Create JMS client for sending and receiving messages. */ private void talker(String broker, String username, String password, String rQueue, String sQueue) { // Create a connection. try {//from w w w . jav a2s . c om javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createConnection(username, password); sendSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); receiveSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create Sender and Receiver 'Talk' queues try { if (sQueue != null) { javax.jms.Queue sendQueue = sendSession.createQueue(sQueue); sender = sendSession.createProducer(sendQueue); } if (rQueue != null) { javax.jms.Queue receiveQueue = receiveSession.createQueue(rQueue); javax.jms.MessageConsumer qReceiver = receiveSession.createConsumer(receiveQueue); qReceiver.setMessageListener(this); // Now that 'receive' setup is complete, start the Connection connect.start(); } } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); exit(); } try { if (rQueue != null) System.out.println(""); else System.out.println("\nNo receiving queue specified.\n"); // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); if (sQueue != null) System.out.println("\nTalk application:\n" + "=================\n" + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n" + "The application will send messages to the " + sQueue + " queue.\n" + "The application creates a receiver on the " + rQueue + " queue to consume any messages allocated to it.\n\n" + "Type some text, and then press Enter to send it as a TextMesssage from " + username + ".\n"); else System.out.println("\nPress CTRL-C to exit.\n"); while (true) { String s = stdin.readLine(); if (s == null) exit(); else if (s.length() > 0 && sQueue != null) { javax.jms.TextMessage msg = sendSession.createTextMessage(); msg.setText(username + ": " + s); // Queues usually are used for PERSISTENT messages. // Hold messages for 30 minutes (1,800,000 millisecs). sender.send(msg, javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY, MESSAGE_LIFESPAN); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } // Close the connection. exit(); }
From source file:org.sakaiproject.kernel.messaging.activemq.ActiveMQEmailDeliveryT.java
public void testGetConnections() { ActiveMQConnectionFactory clientFact = new ActiveMQConnectionFactory(vmURL); ActiveMQConnectionFactory serverFact = new ActiveMQConnectionFactory(vmURL); clientFact.setClientID(clientID);//w w w. ja va2s . co m serverFact.setClientID(listenerID); try { listenerConn = serverFact.createQueueConnection(); Assert.assertNotNull(listenerConn); clientConn = clientFact.createQueueConnection(); Assert.assertNotNull(clientConn); } catch (JMSException e) { e.printStackTrace(); Assert.assertTrue(false); } }
From source file:edu.psu.citeseerx.messaging.MsgService.java
/** * From ExceptionListener interface, providers handler implementation * for trapping JMS exceptions on any channel. *///from w w w. j a va2 s. co m public synchronized void onException(JMSException e) { e.printStackTrace(); }
From source file:ConsumerTool.java
public void onMessage(Message message) { messagesReceived++;//from w w w. j a v a 2 s . com try { if (message instanceof TextMessage) { TextMessage txtMsg = (TextMessage) message; if (verbose) { String msg = txtMsg.getText(); int length = msg.length(); if (length > 50) { msg = msg.substring(0, 50) + "..."; } System.out.println("[" + this.getName() + "] Received: '" + msg + "' (length " + length + ")"); } } else { if (verbose) { System.out.println("[" + this.getName() + "] Received: '" + message + "'"); } } if (message.getJMSReplyTo() != null) { replyProducer.send(message.getJMSReplyTo(), session.createTextMessage("Reply: " + message.getJMSMessageID())); } if (transacted) { if ((messagesReceived % batch) == 0) { System.out.println("Commiting transaction for last " + batch + " messages; messages so far = " + messagesReceived); session.commit(); } } else if (ackMode == Session.CLIENT_ACKNOWLEDGE) { if ((messagesReceived % batch) == 0) { System.out.println( "Acknowledging last " + batch + " messages; messages so far = " + messagesReceived); message.acknowledge(); } } } catch (JMSException e) { System.out.println("[" + this.getName() + "] Caught: " + e); e.printStackTrace(); } finally { if (sleepTime > 0) { try { Thread.sleep(sleepTime); } catch (InterruptedException e) { } } } }
From source file:org.sakaiproject.kernel.messaging.email.EmailMessagingService.java
private void createSessions() { int sessionsPerConnection = 1; Session sess = null;// ww w.ja va 2s. c o m for (Connection conn : connections) { for (int i = 0; i < sessionsPerConnection; ++i) { sess = null; try { sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); sessions.put(conn.getClientID(), sess); } catch (JMSException e) { try { LOG.error("Fail to create connection[" + i + "]: " + conn.getClientID()); } catch (JMSException e1) { // TMI } e.printStackTrace(); } } } }
From source file:SelectorTalk.java
/** Create JMS client for sending and receiving messages. */ private void talker(String broker, String username, String password, String rQueue, String sQueue, String selection) {/* w w w .j a v a 2 s.c om*/ // Create a connection. try { javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createConnection(username, password); sendSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); receiveSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create Sender and Receiver 'Talk' queues try { if (sQueue != null) { javax.jms.Queue sendQueue = sendSession.createQueue(sQueue); sender = sendSession.createProducer(sendQueue); } if (rQueue != null) { //NOTE: the Queue Receiver is set up with the Message Selector: javax.jms.Queue receiveQueue = receiveSession.createQueue(rQueue); javax.jms.MessageConsumer qReceiver = receiveSession.createConsumer(receiveQueue, PROPERTY_NAME + " = \'" + selection + "\'"); qReceiver.setMessageListener(this); connect.start(); } } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); exit(); } try { if (rQueue != null) System.out.println(""); else System.out.println("\nNo receiving queue specified.\n"); // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); if (sQueue != null) System.out.println("SelectorTalk application:\n" + "=========================\n" + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n" + "The application will send messages with " + PROPERTY_NAME + " set to " + selection + " to the " + sQueue + " queue.\n" + "The application creates a receiver on the " + rQueue + " queue selecting only messages where " + PROPERTY_NAME + " is " + selection + ".\n\n" + "Type some text, and then press Enter to publish it as a TextMesssage from " + username + ".\n"); else System.out.println("\nPress CTRL-C to exit.\n"); while (true) { String s = stdin.readLine(); if (s == null) exit(); else if (s.length() > 0 && sQueue != null) { javax.jms.TextMessage msg = sendSession.createTextMessage(); msg.setText(username + ": " + s); // NOTE: here we set the property for each sent message. msg.setStringProperty(PROPERTY_NAME, selection); sender.send(msg, javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY, MESSAGE_LIFESPAN); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } // Close the connection. exit(); }
From source file:Vendor.java
public void run() { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url); Session session = null;// w ww . j av a2s .co m Destination orderQueue; Destination monitorOrderQueue; Destination storageOrderQueue; TemporaryQueue vendorConfirmQueue; MessageConsumer orderConsumer = null; MessageProducer monitorProducer = null; MessageProducer storageProducer = null; try { Connection connection = connectionFactory.createConnection(); session = connection.createSession(true, Session.SESSION_TRANSACTED); orderQueue = session.createQueue("VendorOrderQueue"); monitorOrderQueue = session.createQueue("MonitorOrderQueue"); storageOrderQueue = session.createQueue("StorageOrderQueue"); orderConsumer = session.createConsumer(orderQueue); monitorProducer = session.createProducer(monitorOrderQueue); storageProducer = session.createProducer(storageOrderQueue); Connection asyncconnection = connectionFactory.createConnection(); asyncSession = asyncconnection.createSession(true, Session.SESSION_TRANSACTED); vendorConfirmQueue = asyncSession.createTemporaryQueue(); MessageConsumer confirmConsumer = asyncSession.createConsumer(vendorConfirmQueue); confirmConsumer.setMessageListener(this); asyncconnection.start(); connection.start(); while (true) { Order order = null; try { Message inMessage = orderConsumer.receive(); MapMessage message; if (inMessage instanceof MapMessage) { message = (MapMessage) inMessage; } else { // end of stream Message outMessage = session.createMessage(); outMessage.setJMSReplyTo(vendorConfirmQueue); monitorProducer.send(outMessage); storageProducer.send(outMessage); session.commit(); break; } // Randomly throw an exception in here to simulate a Database error // and trigger a rollback of the transaction if (new Random().nextInt(3) == 0) { throw new JMSException("Simulated Database Error."); } order = new Order(message); MapMessage orderMessage = session.createMapMessage(); orderMessage.setJMSReplyTo(vendorConfirmQueue); orderMessage.setInt("VendorOrderNumber", order.getOrderNumber()); int quantity = message.getInt("Quantity"); System.out.println("Vendor: Retailer ordered " + quantity + " " + message.getString("Item")); orderMessage.setInt("Quantity", quantity); orderMessage.setString("Item", "Monitor"); monitorProducer.send(orderMessage); System.out.println("Vendor: ordered " + quantity + " Monitor(s)"); orderMessage.setString("Item", "HardDrive"); storageProducer.send(orderMessage); System.out.println("Vendor: ordered " + quantity + " Hard Drive(s)"); session.commit(); System.out.println("Vendor: Comitted Transaction 1"); } catch (JMSException e) { System.out.println("Vendor: JMSException Occured: " + e.getMessage()); e.printStackTrace(); session.rollback(); System.out.println("Vendor: Rolled Back Transaction."); } } synchronized (supplierLock) { while (numSuppliers > 0) { try { supplierLock.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } connection.close(); asyncconnection.close(); } catch (JMSException e) { e.printStackTrace(); } }
From source file:TransactedTalk.java
/** Create JMS client for sending and receiving messages. */ private void talker(String broker, String username, String password, String rQueue, String sQueue) { // Create a connection. try {/* w w w . j ava 2 s . c o m*/ javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createConnection(username, password); // We want to be able up commit/rollback messages sent, // but not affect messages received. Therefore, we need two sessions. sendSession = connect.createSession(true, javax.jms.Session.AUTO_ACKNOWLEDGE); receiveSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create Sender and Receiver 'Talk' queues try { if (sQueue != null) { javax.jms.Queue sendQueue = sendSession.createQueue(sQueue); sender = sendSession.createProducer(sendQueue); } if (rQueue != null) { javax.jms.Queue receiveQueue = receiveSession.createQueue(rQueue); javax.jms.MessageConsumer qReceiver = receiveSession.createConsumer(receiveQueue); qReceiver.setMessageListener(this); // Now that 'receive' setup is complete, start the Connection connect.start(); } } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); exit(); } try { if (rQueue != null) System.out.println(""); else System.out.println("\nNo receiving queue specified.\n"); // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); if (sQueue != null) { System.out.println("TransactedTalk application:"); System.out.println("==========================="); System.out.println("The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + "."); System.out.println("The application will stage messages to " + sQueue + " until you either commit them or roll them back."); System.out.println("The application receives messages on " + rQueue + " to consume any committed messages sent there.\n"); System.out.println("1. Enter text to send and then press Enter to stage the message."); System.out.println("2. Add a few messages to the transaction batch."); System.out.println("3. Then, either:"); System.out.println( " o Enter the text 'COMMIT', and press Enter to send all the staged messages."); System.out.println( " o Enter the text 'CANCEL', and press Enter to drop the staged messages waiting to be sent."); } else System.out.println("\nPress CTRL-C to exit.\n"); while (true) { String s = stdin.readLine(); if (s == null) exit(); else if (s.trim().equals("CANCEL")) { // Rollback the messages. A new transaction is implicitly // started for following messages. System.out.print("Cancelling messages..."); sendSession.rollback(); System.out.println("Staged messages have been cleared."); } else if (s.length() > 0 && sQueue != null) { javax.jms.TextMessage msg = sendSession.createTextMessage(); msg.setText(username + ": " + s); // Queues usually are used for PERSISTENT messages. // Hold messages for 30 minutes (1,800,000 millisecs). sender.send(msg, javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY, MESSAGE_LIFESPAN); // See if we should send the messages if (s.trim().equals("COMMIT")) { // Commit (send) the messages. A new transaction is // implicitly started for following messages. System.out.print("Committing messages..."); sendSession.commit(); System.out.println("Staged messages have all been sent."); } } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } // Close the connection. exit(); }
From source file:gov.pnnl.goss.gridappsd.testmanager.TestManagerImpl.java
@Start public void start() { try {/* ww w. ja va 2s .co m*/ LogMessage logMessageObj = createLogMessage(); logMessageObj.setLogMessage("Starting " + this.getClass().getName()); logManager.log(logMessageObj, GridAppsDConstants.username); Credentials credentials = new UsernamePasswordCredentials(GridAppsDConstants.username, GridAppsDConstants.password); Client client = clientFactory.create(PROTOCOL.STOMP, credentials); // String path = "/Users/jsimpson/git/adms/GOSS-GridAPPS-D/gov.pnnl.goss.gridappsd/applications/python/exampleTestConfig.json"; // TestConfiguration testConf = loadTestConfig(path); // path = "/Users/jsimpson/git/adms/GOSS-GridAPPS-D/gov.pnnl.goss.gridappsd/applications/python/exampleTestScript.json"; // TestScript testScript = loadTestScript(path); // // requestSimulation(client, testConf, testScript); // TestConfigurationImpl tc = null; // // TestScriptImpl ts = null; // //TODO: Setup Figure out location of TestScripts // requestSimulation(client, tc, ts); //TODO: Collect data from data manager // TODO Build queries //TODO: Get Simulation Results from ProcessManager //TODO: Compare Results //TODO: // Is called directly from process manager Remove on message //TODO: subscribe to GridAppsDConstants.topic_request_prefix+/* instead of GridAppsDConstants.topic_requestSimulation client.subscribe(topic_requestTest, new GossResponseEvent() { @Override public void onMessage(Serializable message) { DataResponse event = (DataResponse) message; logMessageObj.setTimestamp(new Date().getTime()); logMessageObj.setLogMessage( "Recevied message: " + event.getData() + " on topic " + event.getDestination()); logManager.log(logMessageObj, GridAppsDConstants.username); RequestTest reqTest = RequestTest.parse(message.toString()); TestConfiguration testConfig = loadTestConfig(reqTest.getTestConfigPath()); TestScript testScript = loadTestScript(reqTest.getTestScriptPath()); try { requestSimulation(client, testConfig, testScript); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } catch (Exception e) { log.error("Error in process manager", e); } }