List of usage examples for javax.jms Session createConsumer
MessageConsumer createConsumer(Destination destination) throws JMSException;
From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueReceiveFailTest.java
@Test public void testReceive() throws Exception { Connection connection = activeMQConnectionFactory.createConnection(); connection.start();/*from ww w. j av a 2s .c o m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(activeMQTestQueueA); Message rawMessage = consumer.receive(1000); assertNull(rawMessage); connection.close(); }
From source file:org.apache.activemq.JmsTopicSendReceiveWithTwoConnectionsTest.java
protected MessageConsumer createConsumer(Session session, Destination dest) throws JMSException { return session.createConsumer(dest); }
From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueReceiveTest.java
@Test public void testReceive() throws Exception { Connection connection = activeMQConnectionFactory.createConnection(); connection.start();// w ww .j a v a 2s.c o m Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(activeMQTestQueueA); Message rawMessage = consumer.receive(1000); assertTrue(rawMessage instanceof TextMessage); TextMessage message = (TextMessage) rawMessage; assertEquals("test text", message.getText()); connection.close(); }
From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueSendReceiveTest.java
@Test public void testReceive() throws Exception { Connection connection = activeMQConnectionFactory.createConnection(); connection.start();/* www.java2s . co m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(activeMQTestQueueA); Message rawMessage = consumer.receive(); assertTrue(rawMessage instanceof TextMessage); TextMessage message = (TextMessage) rawMessage; assertEquals("test text", message.getText()); connection.close(); }
From source file:sk.seges.test.jms.multiple.QueueSendReceiveTest.java
@Test public void testReceive() throws Exception { Connection connection = testConnectionFactory.createConnection(); connection.start();/* www . j a v a 2 s. co m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(testQueueA); Message rawMessage = consumer.receive(); assertTrue(rawMessage instanceof TextMessage); TextMessage message = (TextMessage) rawMessage; assertEquals("test text", message.getText()); connection.close(); }
From source file:org.apache.servicemix.samples.bridge.BridgeTest.java
public void testSimpleCall() throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Destination outQueue = new ActiveMQQueue("bridge.output"); Connection connection = factory.createConnection(); connection.start();//w w w . java 2 s .c o m Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); MessageConsumer createConsumer = session.createConsumer(outQueue); createConsumer.setMessageListener(new MessageListener() { public void onMessage(Message arg0) { BridgeTest.recieved = true; ActiveMQTextMessage msg = (ActiveMQTextMessage) arg0; assertNotNull(msg); } }); HttpClient client = new HttpClient(); PostMethod post = new PostMethod(url); post.setRequestBody(new FileInputStream("src/test/resources/request.xml")); int executeMethod = client.executeMethod(post); assertEquals(202, executeMethod); int maxTry = 100; while (!recieved || maxTry == 0) { Thread.sleep(200); maxTry--; } session.close(); connection.close(); }
From source file:biz.fstechnology.micro.common.jms.SyncSessionCallbackImpl.java
protected MessageConsumer createConsumer(Session session, Destination responseDestination) { try {/*ww w . j a v a2 s .c o m*/ return session.createConsumer(responseDestination); } catch (JMSException ex) { throw new RuntimeException(ex); } }
From source file:com.nesscomputing.jms.activemq.ServiceDiscoveryTransportFactoryTest.java
private void consumeTestMessage() throws Exception { final Connection connection = factory.createConnection(); connection.start();//w w w . ja va 2s . c om try { 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:org.openbaton.common.vnfm_sdk.amqp.VnfmSpringHelper.java
/** * This method should be used for receiving text message from EMS * * resp = { 'output': out, // the output of the command 'err': err, // the error outputs of the * commands 'status': status // the exit status of the command } * * @param queueName/*from w ww . jav a 2 s . c o m*/ * @return * @throws JMSException */ public String receiveTextFromQueue(String queueName) throws JMSException, ExecutionException, InterruptedException, VnfmSdkException { String res; Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(session.createQueue(queueName)); connection.start(); String scriptMaxTime = properties.getProperty("script-max-time"); if (scriptMaxTime != null) { TextMessage textMessage = (TextMessage) consumer.receive(Long.parseLong(scriptMaxTime)); if (textMessage != null) res = textMessage.getText(); else throw new VnfmSdkException("No message got from queue " + queueName + " after " + scriptMaxTime); } else res = ((TextMessage) consumer.receive()).getText(); log.debug("Received Text from " + queueName + ": " + res); consumer.close(); session.close(); connection.close(); return res; }
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();/*w ww . j av a 2 s. co m*/ // 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 { 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(); }