Example usage for javax.jms Connection createSession

List of usage examples for javax.jms Connection createSession

Introduction

In this page you can find the example usage for javax.jms Connection createSession.

Prototype


Session createSession(boolean transacted, int acknowledgeMode) throws JMSException;

Source Link

Document

Creates a Session object, specifying transacted and acknowledgeMode .

Usage

From source file:org.soitoolkit.commons.studio.components.logger.impl.DefaultLogEventSender.java

protected Session getSession() throws JMSException {
    JmsConnector jmsConn = (JmsConnector) MuleUtil.getSpringBean(getMuleContext(), "soitoolkit-jms-connector");
    Connection c = jmsConn.getConnection();
    Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
    return s;//from   w  w  w .  j a  v  a 2  s  .  c o  m
}

From source file:unic.mentoring.jms.ctrl.MessageCtrl.java

protected void sendMessage(String message, String topicName) throws JMSException {
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    Connection connection = connectionFactory.createConnection();
    connection.start();/*w ww.j  a v  a2 s  .c om*/

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = session.createTopic(topicName);
    MessageProducer producer = session.createProducer(topic);
    TextMessage jmsMessage = session.createTextMessage();
    jmsMessage.setText(message);

    producer.send(jmsMessage);
    connection.close();
}

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 a  va2 s  . 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.logicblaze.lingo.jmx.remote.jms.activemq.MBeanJmsServerConnectionImpl.java

/**
 * Construct this thing/* ww w  .  jav  a2s  . co  m*/
 * @param connection
 * @param jmsConnection
 * @throws JMSException
 */
public MBeanJmsServerConnectionImpl(MBeanServerConnection connection, Connection jmsConnection)
        throws JMSException {
    super(connection);
    this.jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}

From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueReceiveTest.java

@Test
public void testReceive() throws Exception {
    Connection connection = activeMQConnectionFactory.createConnection();
    connection.start();/*w w  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);
    assertTrue(rawMessage instanceof TextMessage);

    TextMessage message = (TextMessage) rawMessage;
    assertEquals("test text", message.getText());
    connection.close();
}

From source file:com.nesscomputing.jms.activemq.ServiceDiscoveryTransportFactoryTest.java

private void sendTestMessage(final Connection directConnection) throws Exception {
    final Session session = directConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final MessageProducer producer = session.createProducer(session.createQueue(QNAME));
    producer.send(session.createTextMessage(uniqueId));
    session.close();//  ww  w.j  av  a 2  s  .  c  om
}

From source file:sk.seges.test.jms.multiple.QueueSendReceiveTest.java

@Test
public void testReceive() throws Exception {
    Connection connection = testConnectionFactory.createConnection();
    connection.start();//from  ww  w.  java 2s . c o  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:sk.seges.test.jms.activemq.SimpleActiveMQQueueSendReceiveTest.java

@Test
public void testReceive() throws Exception {
    Connection connection = activeMQConnectionFactory.createConnection();
    connection.start();//from w  w  w.  ja v a2s.c  o 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:Supplier.java

public void run() {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url);
    Session session = null;/*from   w  w w .jav a  2  s  .  c  o m*/
    Destination orderQueue;
    try {
        Connection connection = connectionFactory.createConnection();

        session = connection.createSession(true, Session.SESSION_TRANSACTED);
        orderQueue = session.createQueue(QUEUE);
        MessageConsumer consumer = session.createConsumer(orderQueue);

        connection.start();

        while (true) {
            Message message = consumer.receive();
            MessageProducer producer = session.createProducer(message.getJMSReplyTo());
            MapMessage orderMessage;
            if (message instanceof MapMessage) {
                orderMessage = (MapMessage) message;
            } else {
                // End of Stream
                producer.send(session.createMessage());
                session.commit();
                producer.close();
                break;
            }

            int quantity = orderMessage.getInt("Quantity");
            System.out.println(
                    ITEM + " Supplier: Vendor ordered " + quantity + " " + orderMessage.getString("Item"));

            MapMessage outMessage = session.createMapMessage();
            outMessage.setInt("VendorOrderNumber", orderMessage.getInt("VendorOrderNumber"));
            outMessage.setString("Item", ITEM);

            quantity = Math.min(orderMessage.getInt("Quantity"),
                    new Random().nextInt(orderMessage.getInt("Quantity") * 10));
            outMessage.setInt("Quantity", quantity);

            producer.send(outMessage);
            System.out.println(ITEM + " Supplier: Sent " + quantity + " " + ITEM + "(s)");
            session.commit();
            System.out.println(ITEM + " Supplier: committed transaction");
            producer.close();
        }
        connection.close();
    } catch (JMSException e) {
        e.printStackTrace();
    }
}

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();/*from   w  w  w  . j  a  v  a  2s. 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();

}