Example usage for javax.jms Session AUTO_ACKNOWLEDGE

List of usage examples for javax.jms Session AUTO_ACKNOWLEDGE

Introduction

In this page you can find the example usage for javax.jms Session AUTO_ACKNOWLEDGE.

Prototype

int AUTO_ACKNOWLEDGE

To view the source code for javax.jms Session AUTO_ACKNOWLEDGE.

Click Source Link

Document

With this acknowledgment mode, the session automatically acknowledges a client's receipt of a message either when the session has successfully returned from a call to receive or when the message listener the session has called to process the message successfully returns.

Usage

From source file:org.sakaiproject.kernel.messaging.email.EmailMessagingService.java

public String send(Email email) throws MessagingException, JMSException {
    try {// ww  w . jav a2 s . co m
        email.buildMimeMessage();
    } catch (Exception e) {
        // this is a lossy cast. This would be a commons EmailException
        // this up cast is to keep commons-email out of our direct bindings
        throw new MessagingException(e);
    }

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        email.getMimeMessage().writeTo(os);
    } catch (javax.mail.MessagingException e) {
        throw new MessagingException(e);

    } catch (IOException e) {
        throw new MessagingException(e);
    }

    String content = os.toString();
    Connection conn = connectionFactory.createTopicConnection();
    conn.setClientID(getNextId());
    Session clientSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination emailTopic = clientSession.createTopic(emailQueueName);
    MessageProducer client = clientSession.createProducer(emailTopic);
    ObjectMessage mesg = clientSession.createObjectMessage(content);
    mesg.setJMSType(emailJmsType);
    client.send(mesg);
    // TODO finish this
    return null;

}

From source file:org.apache.qpid.client.ssl.SSLTest.java

public void testCreateSSLConnectionUsingSystemProperties() throws Exception {
    if (shouldPerformTest()) {
        //Start the broker (NEEDing client certificate authentication)
        configureJavaBrokerIfNecessary(true, true, true, false);
        super.setUp();

        String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s?ssl='true''";

        url = String.format(url, QpidBrokerTestCase.DEFAULT_SSL_PORT);

        Connection con = getConnection(new AMQConnectionURL(url));
        assertNotNull("connection should be successful", con);
        Session ssn = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
        assertNotNull("create session should be successful", ssn);
    }//w w  w.  j a  va2s. c o m
}

From source file:org.wso2.carbon.transport.jms.factory.PooledJMSConnectionFactory.java

/**
 * Validates a connection object and verifies it can be used further.
 *
 * @param key                    The connection key
 * @param pooledConnectionObject The wrapped connection object
 * @return True if the object is valid/*w  w  w.  j  av a 2s  .  c  o m*/
 */
@Override
public boolean validateObject(PooledConnectionKey key, PooledObject<Connection> pooledConnectionObject) {

    boolean valid = false;

    try {
        Session session = pooledConnectionObject.getObject().createSession(false, Session.AUTO_ACKNOWLEDGE);

        session.close();

        valid = true;
    } catch (JMSException e) {
        log.warn("Connection with key " + key.hashCode() + " is not valid anymore");
    }

    return valid;
}

From source file:au.com.redboxresearchdata.fascinator.plugins.JsonHarvestQueueConsumer.java

public void run() {
    try {/*from   w  w w. j  a  v a2  s .  c o m*/
        // Get a connection to the broker
        String brokerUrl = globalConfig.getString(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL,
                "messaging", "url");
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
        connection = connectionFactory.createConnection();

        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        consumer = session.createConsumer(session.createQueue(QUEUE_ID));
        consumer.setMessageListener(this);

        producer = session.createProducer(session.createTopic(EVENT_TOPIC_ID));
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);

        connection.start();

        toolChainEntry = globalConfig.getString(DEFAULT_TOOL_CHAIN_QUEUE, "messaging", "toolChainQueue");

        failedJsonMap = new HashMap<String, HarvestItem>();
        failedJsonList = new ArrayList<String>();
        harvestRequests = new HashMap<String, HarvestRequest>();
        // registering managed bean...
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mxbeanName = new ObjectName(
                "au.com.redboxresearchdata.fascinator.plugins:type=JsonHarvestQueue");
        mbs.registerMBean(this, mxbeanName);
        log.info("'{}' is running...", name);
    } catch (JMSException ex) {
        log.error("Error starting message thread!", ex);
    } catch (MalformedObjectNameException e) {
        log.error("Error configuring MBean, invalid name", e);
    } catch (InstanceAlreadyExistsException e) {
        log.error("Error configuring MBean, instance exists.", e);
    } catch (MBeanRegistrationException e) {
        log.error("Error registering MBean. ", e);
    } catch (NotCompliantMBeanException e) {
        log.error("Error configuring Mbean, non-compliant!", e);
    }
}

From source file:org.fao.geonet.jms.ClusterConfig.java

private static void initJMSConnection() throws ClusterException {
    try {/*from  w  w  w . ja  v a2 s.c o m*/
        // Getting JMS connection from the server
        System.out.println("Getting JMS Connection");
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ClusterConfig.getBrokerURL());
        connection = connectionFactory.createConnection();
        connection.setClientID(ClusterConfig.getClientID());
        connection.start();

        // Creating session for sending and receiving messages
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        // Set connection and session for all JMSActors
        JMSActor.connection = connection;
        JMSActor.session = session;
        System.out.println("Getiing JMS Connection successfull");
    } catch (JMSException x) {
        System.out.println("Getiing JMS Connection failed");
        System.err.println(x.getMessage());
        x.printStackTrace();
        throw new ClusterException(x.getMessage(), x);
    }
}

From source file:org.rhq.enterprise.server.drift.DriftManagerBean.java

@Override
@TransactionAttribute(REQUIRES_NEW)/*w  w w  .j  a v a  2  s. co m*/
public void addChangeSet(Subject subject, int resourceId, long zipSize, InputStream zipStream)
        throws Exception {

    Connection connection = factory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(changesetQueue);
    ObjectMessage msg = session.createObjectMessage(new DriftUploadRequest(resourceId, zipSize, zipStream));
    producer.send(msg);
    connection.close();
}

From source file:org.codice.pubsub.stomp.SubscriptionQueryMessageListener.java

private void execute() {

    StompJmsConnectionFactory factory = new StompJmsConnectionFactory();

    factory.setBrokerURI("tcp://" + stompHost + ":" + stompPort);

    try {// www.ja va 2  s . co m
        connection = factory.createConnection(user, password);
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination dest = new StompJmsDestination(destTopicName);
        consumer = session.createConsumer(dest);

        while (!Thread.currentThread().isInterrupted()) {
            Message msg = consumer.receive();
            if (msg instanceof TextMessage) {
                String body = ((TextMessage) msg).getText();
                processMessage(body);

            } else if (msg instanceof StompJmsBytesMessage) {
                //Non-ActiveMQ STOMP client implementations end up here
                StompJmsBytesMessage byteMsg = (StompJmsBytesMessage) msg;

                long len = ((StompJmsBytesMessage) msg).getBodyLength();

                byte[] byteArr = new byte[(int) byteMsg.getBodyLength()];

                for (int i = 0; i < (int) byteMsg.getBodyLength(); i++) {
                    byteArr[i] = byteMsg.readByte();
                }
                String msgStr = new String(byteArr);
                processMessage(msgStr);
            } else {
            }
        }

        //stop the connection
        destroy();
    } catch (JMSException e) {
        LOGGER.error(e.getMessage());
    }
}

From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterSpringTest.java

@Before
public void before() throws Exception {
    connection = connectionFactory.createConnection();
    connection.start();/*w  ww .  ja va2 s  .  co m*/
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

}

From source file:org.apache.activemq.network.MQTTNetworkOfBrokersFailoverTest.java

private CountDownLatch listenForConsumersOn(BrokerService broker) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);

    URI brokerUri = broker.getVmConnectorURI();

    final ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerUri.toASCIIString());
    final Connection connection = cf.createConnection();
    connection.start();//  ww w  .  j av a2s.  c  om
    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination dest = session
            .createTopic("ActiveMQ.Advisory.Consumer.Queue.Consumer.foo:AT_LEAST_ONCE.VirtualTopic.foo.bar");
    MessageConsumer consumer = session.createConsumer(dest);
    consumer.setMessageListener(new MessageListener() {
        @Override
        public void onMessage(Message message) {
            latch.countDown();
            // shutdown this connection
            Dispatch.getGlobalQueue().execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        session.close();
                        connection.close();
                    } catch (JMSException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    });

    return latch;
}

From source file:org.mot.common.mq.ActiveMQFactory.java

/**
 * @param sessionID//  w ww  . j  a v  a  2 s  .  co m
 * @return
 * @throws JMSException
 */
private Session createSession() throws JMSException {

    // Create a Session
    return connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}