List of usage examples for javax.jms Connection start
void start() throws JMSException;
From source file:org.apache.activemq.store.kahadb.MultiKahaDBQueueDeletionTest.java
@Override protected void createConsumer(ActiveMQDestination dest) throws JMSException { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerConnectURI); Connection connection = factory.createConnection(); connection.setClientID("client1"); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); session.createConsumer(dest);/*w w w .ja va 2s.c om*/ }
From source file:com.datatorrent.lib.io.jms.JMSTestBase.java
public void produceMsg(String text) 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 TextMessage message = session.createTextMessage(text); producer.send(message);//from w ww .j a v a2 s. co m // Clean up session.close(); connection.close(); }
From source file:com.nesscomputing.jms.activemq.ServiceDiscoveryTransportFactoryTest.java
private void consumeTestMessage() throws Exception { final Connection connection = factory.createConnection(); connection.start(); try {/* w ww. ja v a2 s . c om*/ final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); final MessageConsumer consumer = session.createConsumer(session.createQueue(QNAME)); final Message message = consumer.receive(1000); LOG.info(ObjectUtils.toString(message, "<no message>")); Assert.assertEquals(uniqueId, ((TextMessage) message).getText()); } finally { connection.stop(); connection.close(); } }
From source file:io.fabric8.msg.gateway.TestGateway.java
/** * TODO - lets figure out a way of mocking kubernetes, running a ZK ensemble, an Artemis broker and testing it! * @throws Exception/*from www. java 2 s .c o m*/ */ @Ignore public void simpleTest() throws Exception { int numberOfMessages = 10; String destinationName = "jms.queue.test.foo"; String brokerURL = "tcp://0.0.0.0:61616"; ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL); Connection consumerConnection = factory.createConnection(); consumerConnection.start(); Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination consumerDestination = consumerSession.createQueue(destinationName); MessageConsumer messageConsumer = consumerSession.createConsumer(consumerDestination); Connection producerConnection = factory.createConnection(); producerConnection.start(); Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = producerSession.createQueue(destinationName); MessageProducer producer = producerSession.createProducer(destination); for (int i = 0; i < numberOfMessages; i++) { Message message = producerSession.createTextMessage("test message: " + i); producer.send(message); //System.err.println("Sent message " + message); } Message message; for (int i = 0; i < numberOfMessages; i++) { message = messageConsumer.receive(5000); Assert.assertNotNull(message); //System.err.println("Got Message " + message); } messageConsumer.close(); }
From source file:io.fabric8.mq.controller.coordination.BrokerJMXPropertiesTest.java
@Test public void testNumberOfTopicProducers() throws Exception { String uriString = brokerService.getDefaultSocketURIString(); ConnectionFactory factory = new ActiveMQConnectionFactory(uriString); Connection connection = factory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); int numberOfProducers = 10; List<MessageProducer> producers = new ArrayList<>(); Topic topic = session.createTopic("topic.test"); for (int i = 0; i < numberOfProducers; i++) { MessageProducer producer = session.createProducer(topic); producers.add(producer);// ww w. j ava 2s . c o m } ObjectName root = BrokerJmxUtils.getRoot(client); Assert.assertNotNull(root); List<ObjectName> list = BrokerJmxUtils.getDestinations(client, root, "Topic"); Assert.assertNotNull(list); Assert.assertFalse(list.isEmpty()); ObjectName result = null; for (ObjectName objectName : list) { if (objectName.getKeyProperty("destinationName").equals("topic.test")) { result = objectName; } } Assert.assertNotNull(result); Object producerCount = BrokerJmxUtils.getAttribute(client, result, "ProducerCount"); Assert.assertNotNull(producerCount); int pc = Integer.parseInt(producerCount.toString()); Assert.assertEquals(pc, numberOfProducers); connection.close(); }
From source file:org.apache.falcon.regression.core.supportClasses.JmsMessageConsumer.java
@Override public void run() { try {/*w w w . j a v a 2s. c o m*/ // Getting JMS connection from the server Connection connection = new ActiveMQConnectionFactory(brokerURL).createConnection(); connection.start(); // Creating session for sending messages Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(topicName); MessageConsumer consumer = session.createConsumer(destination); try { LOGGER.info("Starting to receive messages."); int count = 0; for (; count < MAX_MESSAGE_COUNT; ++count) { Message message = consumer.receive(); //blocking call if (message == null) { LOGGER.info("Received empty message, count = " + count); } else { LOGGER.info("Received message, id = " + message.getJMSMessageID()); receivedMessages.add((MapMessage) message); } } if (count >= MAX_MESSAGE_COUNT) { LOGGER.warn("Not reading more messages, already read " + count + " messages."); } } finally { LOGGER.info("Stopping to receive messages."); connection.close(); } } catch (Exception e) { LOGGER.info("caught exception: " + ExceptionUtils.getStackTrace(e)); } }
From source file:com.nesscomputing.jms.activemq.ServiceDiscoveryTransportFactoryTest.java
@Test public void testDiscoveryUri() throws Exception { final ServiceInformation vmbrokerInfo = new ServiceInformation("vmbroker", null, UUID.randomUUID(), ImmutableMap.of("uri", "vm://disco-test-broker-" + uniqueId)); final Config config = Config .getFixedConfig(ImmutableMap.of("ness.jms.connection-url", "srvc://vmbroker?discoveryId=%s")); Guice.createInjector(new AbstractModule() { @Override/*ww w . j av a 2s .c om*/ protected void configure() { binder().requireExplicitBindings(); binder().disableCircularProxies(); install(new ConfigModule(config)); install(new JmsModule(config, "test")); install(new DiscoveryJmsModule(config)); bind(ReadOnlyDiscoveryClient.class).toInstance( MockedReadOnlyDiscoveryClient.builder().addServiceInformation(vmbrokerInfo).build()); } }).injectMembers(this); final ConnectionFactory directFactory = new ActiveMQConnectionFactory( "vm://disco-test-broker-" + uniqueId + "?broker.persistent=false"); final Connection directConnection = directFactory.createConnection(); directConnection.start(); try { sendTestMessage(directConnection); consumeTestMessage(); } finally { directConnection.stop(); directConnection.close(); } }
From source file:org.fusesource.stompjms.JmsTestSupport.java
protected void sendMessages(Destination destination, int count) throws Exception { ConnectionFactory factory = createConnectionFactory(); Connection connection = factory.createConnection(); connection.start(); sendMessages(connection, destination, count); connection.close();/*from www. j a v a2 s . c o m*/ }
From source file:org.ct.amq.jdbc.security.JdbcAuthenticationPluginTest.java
public void testConnectionStartWithUnknownUserThrowsJMSSecurityException() throws Exception { Connection connection = factory.createConnection("badUser", "password"); try {//from w w w .j av a 2 s .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:com.microsoft.azure.servicebus.samples.jmstopicquickstart.JmsTopicQuickstart.java
private void receiveFromSubscription(ConnectionStringBuilder csb, Context context, ConnectionFactory cf, String name) throws NamingException, JMSException, InterruptedException { AtomicInteger totalReceived = new AtomicInteger(0); System.out.printf("Subscription %s: \n", name); Destination subscription = (Destination) context.lookup(name); // 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 consumer MessageConsumer consumer = session.createConsumer(subscription); // Set callback listener. Gets called for each received message. consumer.setMessageListener(message -> { try {/* w ww . ja v a2 s .c o m*/ System.out.printf("Received message %d with sq#: %s\n", totalReceived.incrementAndGet(), // increments the counter message.getJMSMessageID()); message.acknowledge(); } catch (Exception e) { System.out.printf("%s", e.toString()); } }); // wait on the main thread until all sent messages have been received while (totalReceived.get() < totalSend) { Thread.sleep(1000); } consumer.close(); session.close(); connection.stop(); connection.close(); }