List of usage examples for javax.jms Connection start
void start() throws JMSException;
From source file:org.ct.amq.jdbc.security.JdbcAuthenticationPluginTest.java
public void testConnectionStartWithDisabledUserThrowsJMSSecurityException() throws Exception { Connection connection = factory.createConnection("disableduser", "password"); try {/*from w w w . j a v a 2s . co m*/ connection.start(); fail("Should throw JMSSecurityException"); } catch (JMSSecurityException jmsEx) { } catch (Exception e) { LOG.info("Expected JMSSecurityException but was: {}", e.getClass()); fail("Should throw JMSSecurityException"); } }
From source file:org.calrissian.mango.jms.stream.JmsFileTransferSupportTest.java
public void testFullCycle() throws Exception { try {//from w w w. j a va 2 s . com URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(String protocol) { if ("testprot".equals(protocol)) return new URLStreamHandler() { @Override protected URLConnection openConnection(URL u) throws IOException { return new URLConnection(u) { @Override public void connect() throws IOException { } @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(TEST_STR.getBytes()); } @Override public String getContentType() { return "content/notnull"; } }; } }; return null; } }); } catch (Error ignored) { } final ActiveMQTopic ft = new ActiveMQTopic("testFileTransfer"); ThreadPoolTaskExecutor te = new ThreadPoolTaskExecutor(); te.initialize(); JmsFileSenderListener listener = new JmsFileSenderListener(); final String hashAlgorithm = "MD5"; listener.setHashAlgorithm(hashAlgorithm); listener.setStreamRequestDestination(ft); listener.setPieceSize(9); listener.setTaskExecutor(te); ConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); cf = new SingleTopicConnectionFactory(cf, "test"); JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setConnectionFactory(cf); jmsTemplate.setReceiveTimeout(60000); listener.setJmsTemplate(jmsTemplate); Connection conn = cf.createConnection(); conn.start(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = sess.createConsumer(ft); consumer.setMessageListener(listener); JmsFileReceiver receiver = new JmsFileReceiver(); receiver.setHashAlgorithm(hashAlgorithm); receiver.setStreamRequestDestination(ft); receiver.setJmsTemplate(jmsTemplate); receiver.setPieceSize(9); JmsFileReceiverInputStream stream = (JmsFileReceiverInputStream) receiver.receiveStream("testprot:test"); StringBuilder buffer = new StringBuilder(); int read; while ((read = stream.read()) >= 0) { buffer.append((char) read); } stream.close(); assertEquals(TEST_STR, buffer.toString()); conn.stop(); }
From source file:org.apache.falcon.messaging.ProcessProducerTest.java
private void consumer() throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URL); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(getTopicName()); MessageConsumer consumer = session.createConsumer(destination); latch.countDown();// ww w. j a va2s . com for (int index = 0; index < outputFeedNames.length; ++index) { MapMessage m = (MapMessage) consumer.receive(); System.out.println("Consumed: " + m.toString()); assertMessage(m); Assert.assertEquals(m.getString(WorkflowExecutionArgs.OUTPUT_FEED_NAMES.getName()), outputFeedNames[index]); Assert.assertEquals(m.getString(WorkflowExecutionArgs.OUTPUT_FEED_PATHS.getName()), outputFeedPaths[index]); } connection.close(); }
From source file:org.apache.activemq.camel.JmsJdbcXARollbackTest.java
private boolean consumedFrom(String qName) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testXA"); factory.setWatchTopicAdvisories(false); Connection connection = factory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(new ActiveMQQueue(qName)); Message message = consumer.receive(500); LOG.info("Got from queue:{} {}", qName, message); connection.close();// ww w .j a v a 2 s .com return message != null; }
From source file:org.apache.activemq.camel.JmsJdbcXARollbackTest.java
private void sendJMSMessageToKickOffRoute() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testXA"); factory.setWatchTopicAdvisories(false); Connection connection = factory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(new ActiveMQQueue("scp_transacted")); TextMessage message = session.createTextMessage("Some Text, messageCount:" + messageCount++); message.setJMSCorrelationID("pleaseCorrelate"); producer.send(message);/*from www. j av a2 s .c o m*/ connection.close(); }
From source file:fr.xebia.sample.springframework.jms.requestreply.RequestReplyClientInvoker.java
/** * Request/Reply SpringFramework sample. * //from ww w .java 2s . c o m * @param request * sent to the remote service * @return reply returned by the remote service * @throws JMSException */ public String requestReply(String request) throws JMSException { Connection connection = connectionFactory.createConnection(); try { connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { MessageProducer messageProducer = session.createProducer(this.requestDestination); try { Message requestMessage = session.createTextMessage(request); requestMessage.setJMSReplyTo(this.replyToDestination); // requestMessage.setJMSCorrelationID(String.valueOf(random.nextLong())); messageProducer.send(requestMessage); String messageSelector = "JMSCorrelationID LIKE '" + requestMessage.getJMSMessageID() + "'"; MessageConsumer messageConsumer = session.createConsumer(this.replyToDestination, messageSelector); TextMessage replyMessage = (TextMessage) messageConsumer.receive(timeoutInMillis); Assert.notNull(replyMessage, "Timeout waiting for jms response"); logger.debug( "requestReply " + "\r\nrequest : " + requestMessage + "\r\nreply : " + replyMessage); String result = replyMessage.getText(); logger.debug("requestReply('" + request + "'): '" + result + "'"); return result; } finally { JmsUtils.closeMessageProducer(messageProducer); } } finally { JmsUtils.closeSession(session); } } finally { JmsUtils.closeConnection(connection); } }
From source file:com.datatorrent.lib.io.jms.JMSStringInputOperatorTest.java
private void produceMsg(int numMessages) throws Exception { // Create a ConnectionFactory ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); // Create a Connection Connection connection = connectionFactory.createConnection(); connection.start(); // Create a Session Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); // Create the destination (Topic or Queue) Destination destination = session.createQueue("TEST.FOO"); // Create a MessageProducer from the Session to the Topic or Queue MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); // Create a messages String text = "Hello world! From tester producer"; TextMessage message = session.createTextMessage(text); for (int i = 0; i < numMessages; i++) { producer.send(message);/* ww w .j a va 2s. c o m*/ } // Clean up session.close(); connection.close(); }
From source file:com.opengamma.examples.analyticservice.ExampleAnalyticServiceUsage.java
@Override protected void doRun() throws Exception { CommandLine commandLine = getCommandLine(); String activeMQUrl = commandLine.getOptionValue(ACTIVE_MQ_OPTION); String destinationName = commandLine.getOptionValue(QUEUE_OPTION); ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(activeMQUrl); activeMQConnectionFactory.setWatchTopicAdvisories(false); PooledConnectionFactory jmsConnectionFactory = new PooledConnectionFactory(activeMQConnectionFactory); jmsConnectionFactory.start();//w w w . j av a 2 s . co m JmsConnectorFactoryBean jmsConnectorFactoryBean = new com.opengamma.util.jms.JmsConnectorFactoryBean(); jmsConnectorFactoryBean.setName("StandardJms"); jmsConnectorFactoryBean.setConnectionFactory(jmsConnectionFactory); jmsConnectorFactoryBean.setClientBrokerUri(URI.create(activeMQUrl)); JmsConnector jmsConnector = jmsConnectorFactoryBean.getObjectCreating(); ByteArrayFudgeMessageReceiver fudgeReceiver = new ByteArrayFudgeMessageReceiver(new FudgeMessageReceiver() { @Override public void messageReceived(FudgeContext fudgeContext, FudgeMsgEnvelope msgEnvelope) { FudgeMsg message = msgEnvelope.getMessage(); s_logger.debug("received {}", message); } }, s_fudgeContext); final JmsByteArrayMessageDispatcher jmsDispatcher = new JmsByteArrayMessageDispatcher(fudgeReceiver); Connection connection = jmsConnector.getConnectionFactory().createConnection(); connection.start(); pushTrade("ARG", connection, destinationName, jmsConnector, jmsDispatcher); Thread.sleep(WAIT_BTW_TRADES); pushTrade("MMM", connection, destinationName, jmsConnector, jmsDispatcher); Thread.sleep(WAIT_BTW_TRADES * 10); connection.stop(); jmsConnectionFactory.stop(); }
From source file:org.sakaiproject.kernel.messaging.email.EmailMessagingService.java
private void startConnections() { for (Connection conn : connections) { try {// ww w.ja v a2 s .co m conn.start(); } catch (JMSException e) { try { LOG.error("Fail to start connection: " + conn.getClientID()); } catch (JMSException e1) { // TMI } e.printStackTrace(); } } }
From source file:com.microsoft.azure.servicebus.samples.jmstopicquickstart.JmsTopicQuickstart.java
public void run(String connectionString) throws Exception { // The connection string builder is the only part of the azure-servicebus SDK library // we use in this JMS sample and for the purpose of robustly parsing the Service Bus // connection string. ConnectionStringBuilder csb = new ConnectionStringBuilder(connectionString); // set up the JNDI context Hashtable<String, String> hashtable = new Hashtable<>(); hashtable.put("connectionfactory.SBCF", "amqps://" + csb.getEndpoint().getHost() + "?amqp.idleTimeout=120000&amqp.traceFrames=true"); hashtable.put("topic.TOPIC", "BasicTopic"); hashtable.put("queue.SUBSCRIPTION1", "BasicTopic/Subscriptions/Subscription1"); hashtable.put("queue.SUBSCRIPTION2", "BasicTopic/Subscriptions/Subscription2"); hashtable.put("queue.SUBSCRIPTION3", "BasicTopic/Subscriptions/Subscription3"); hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); Context context = new InitialContext(hashtable); ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF"); // Look up the topic Destination topic = (Destination) context.lookup("TOPIC"); // we create a scope here so we can use the same set of local variables cleanly // again to show the receive side seperately with minimal clutter {/*from w w w. jav a2s . co m*/ // Create Connection Connection connection = cf.createConnection(csb.getSasKeyName(), csb.getSasKey()); connection.start(); // Create Session, no transaction, client ack Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); // Create producer MessageProducer producer = session.createProducer(topic); // Send messaGES for (int i = 0; i < totalSend; i++) { BytesMessage message = session.createBytesMessage(); message.writeBytes(String.valueOf(i).getBytes()); producer.send(message); System.out.printf("Sent message %d.\n", i + 1); } producer.close(); session.close(); connection.stop(); connection.close(); } // Look up the subscription (pretending it's a queue) receiveFromSubscription(csb, context, cf, "SUBSCRIPTION1"); receiveFromSubscription(csb, context, cf, "SUBSCRIPTION2"); receiveFromSubscription(csb, context, cf, "SUBSCRIPTION3"); System.out.printf("Received all messages, exiting the sample.\n"); System.out.printf("Closing queue client.\n"); }