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:net.blogracy.services.StoreService.java

public StoreService(Connection connection, PluginInterface plugin) {
    this.plugin = plugin;
    try {/*from w ww.jav  a  2 s  .c om*/
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer(null);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        queue = session.createQueue("store");
        consumer = session.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (JMSException e) {
        Logger.error("JMS error: creating store service");
    }
}

From source file:org.apache.activemq.store.kahadb.MultiKahaDBTopicDeletionTest.java

@Override
protected void createConsumer(ActiveMQDestination dest) throws JMSException {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerConnectURI);
    Connection connection = factory.createConnection();
    connection.setClientID("client1");
    connection.start();/*from   w  w w  .  j  a  v a  2s.co  m*/
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber((Topic) dest, "sub1");
}

From source file:org.ct.amq.jdbc.security.JdbcAuthenticationPluginTest.java

public void testTempDestinations() throws Exception {
    Connection conn = factory.createConnection("guest", "password");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    String name = "org.apache.activemq:BrokerName=localhost,Type=TempTopic";
    try {/*from   ww w .j  a  va2s.c om*/
        conn.start();
        TemporaryTopic temp = sess.createTemporaryTopic();
        name += ",Destination=" + temp.getTopicName().replaceAll(":", "_");
        fail("Should have failed creating a temp topic");
    } catch (Exception ignore) {
    }

    ObjectName objName = new ObjectName(name);
    TopicViewMBean mbean = (TopicViewMBean) broker.getManagementContext().newProxyInstance(objName,
            TopicViewMBean.class, true);
    try {
        System.out.println(mbean.getName());
        fail("Shouldn't have created a temp topic");
    } catch (Exception ignore) {
    }
}

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();/*from w  w w  .  ja  v a2s  . c  o  m*/
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createConsumer(dest);
}

From source file:net.blogracy.services.DownloadService.java

public DownloadService(Connection connection, PluginInterface plugin) {
    this.plugin = plugin;
    try {//  w  ww  .  j  av  a  2  s.co m
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer(null);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        queue = session.createQueue("download");
        consumer = session.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (JMSException e) {
        Logger.error("JMS error: creating download service");
    }
}

From source file:Retailer.java

public void run() {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url);
    try {//from  w w w .  j a  v a 2s. c o  m
        Connection connection = connectionFactory.createConnection();

        // The Retailer's session is non-trasacted.
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination vendorOrderQueue = session.createQueue("VendorOrderQueue");
        TemporaryQueue retailerConfirmQueue = session.createTemporaryQueue();

        MessageProducer producer = session.createProducer(vendorOrderQueue);
        MessageConsumer replyConsumer = session.createConsumer(retailerConfirmQueue);

        connection.start();

        for (int i = 0; i < 5; i++) {
            MapMessage message = session.createMapMessage();
            message.setString("Item", "Computer(s)");
            int quantity = (int) (Math.random() * 4) + 1;
            message.setInt("Quantity", quantity);
            message.setJMSReplyTo(retailerConfirmQueue);
            producer.send(message);
            System.out.println("Retailer: Ordered " + quantity + " computers.");

            MapMessage reply = (MapMessage) replyConsumer.receive();
            if (reply.getBoolean("OrderAccepted")) {
                System.out.println("Retailer: Order Filled");
            } else {
                System.out.println("Retailer: Order Not Filled");
            }
        }

        // Send a non-MapMessage to signal the end
        producer.send(session.createMessage());

        replyConsumer.close();
        connection.close();

    } catch (JMSException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.camel.component.sjms.it.ConnectionResourceIT.java

/**
 * Test method for/*from   w w  w  . j  a va2 s. c o m*/
 * {@link org.apache.commons.pool.ObjectPool#returnObject(java.lang.Object)}
 * .
 * 
 * @throws Exception
 */
@Test
public void testCreateConnections() throws Exception {
    ConnectionResource pool = new AMQConnectionResource("tcp://localhost:33333", 1);
    assertNotNull(pool);
    Connection connection = pool.borrowConnection();
    assertNotNull(connection);
    assertNotNull(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
    pool.returnConnection(connection);
    Connection connection2 = pool.borrowConnection();
    assertNotNull(connection2);
}

From source file:biz.fstechnology.micro.server.jms.AbstractJmsService.java

/**
 * @see biz.fstechnology.micro.server.Service#init()
 *//* www  .  ja  v a 2  s.  com*/
@Override
public void init() throws Exception {
    Connection connection = createJmsTemplate().getConnectionFactory().createConnection();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(session.createTopic(getListenTopic()));
    consumer.setMessageListener(this);

    replyProducer = session.createProducer(null);
    replyProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

    connection.start();
}

From source file:net.blogracy.services.LookupService.java

public LookupService(Connection connection, PluginInterface plugin) {
    this.plugin = plugin;
    try {//  w w w.  ja  v  a 2  s .  c o m
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer(null);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        queue = session.createQueue("lookup");
        consumer = session.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (JMSException e) {
        Logger.error("JMS error: creating lookup service");
    }
}

From source file:net.blogracy.services.SeedService.java

public SeedService(Connection connection, PluginInterface plugin) {
    this.plugin = plugin;
    try {/* w  w w.  j a va  2s.c  o  m*/
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer(null);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        queue = session.createQueue("seed");
        consumer = session.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (JMSException e) {
        Logger.error("JMS error: creating seed service");
    }
}