Example usage for javax.jms Session CLIENT_ACKNOWLEDGE

List of usage examples for javax.jms Session CLIENT_ACKNOWLEDGE

Introduction

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

Prototype

int CLIENT_ACKNOWLEDGE

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

Click Source Link

Document

With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method.

Usage

From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java

public void testAdaptrisMessageMetadataToJmsCorrelationId_NoMetadataKey() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    JmsConnection conn = broker.getJmsConnection();
    try {//w w w  .  j  a  v  a  2  s .co  m
        broker.start();
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        adpMsg.addMetadata(CORRELATIONID_KEY, TEXT2);
        TextMessage jmsMsg = session.createTextMessage();
        MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource();
        mcs.processCorrelationId(adpMsg, jmsMsg);
        assertNotSame(adpMsg.getMetadataValue(CORRELATIONID_KEY), jmsMsg.getJMSCorrelationID());
        session.close();
    } finally {
        stop(conn);
        broker.destroy();
    }
}

From source file:com.adaptris.core.jms.activemq.BlobMessageTranslatorTest.java

public void testMoveMetadataJmsMessageToAdaptrisMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    EmbeddedActiveMq activeMqBroker = new EmbeddedActiveMq();
    JmsConnection conn = null;/* w  w  w  . j a  v a  2  s .c om*/
    try {
        activeMqBroker.start();
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);

        addProperties(jmsMsg);
        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        start(trans);
        AdaptrisMessage msg = trans.translate(jmsMsg);

        assertMetadata(msg);
    } finally {
        stop(trans);
        stop(conn);
        activeMqBroker.destroy();
    }
}

From source file:com.alibaba.napoli.client.async.impl.DefaultAsyncReceiver.java

public void setAcknownedgeMode(int acknownedgeMode) {
    if (acknownedgeMode == Session.AUTO_ACKNOWLEDGE || acknownedgeMode == Session.CLIENT_ACKNOWLEDGE
            || acknownedgeMode == Session.DUPS_OK_ACKNOWLEDGE) {
        if (connectionParam != null) {
            connectionParam.setAcknowledgeMode(acknownedgeMode);
        }/*from w ww.  j  ava2  s .  c  o  m*/
    }
}

From source file:org.jbpm.bpel.tutorial.shipping.ShippingPT_Impl.java

protected void sendShippingMessage(String customerId) throws JMSException {
    // create a session
    Session jmsSession = jmsConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    try {//  w w  w  .  j a  v  a2s . c om
        // create the message
        MapMessage message = jmsSession.createMapMessage();
        message.setString("customerId", customerId);

        // send it!
        MessageProducer producer = jmsSession.createProducer(shippingDestination);
        producer.send(message);

        log.debug("Sent shipping message: customerId=" + customerId);
    } finally {
        jmsSession.close();
    }
}

From source file:org.apache.storm.jms.spout.JmsSpoutTest.java

public Message sendMessage(ConnectionFactory connectionFactory, Destination destination) throws JMSException {
    Session mySess = connectionFactory.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
    MessageProducer producer = mySess.createProducer(destination);
    TextMessage msg = mySess.createTextMessage();
    msg.setText("Hello World");
    log.debug("Sending Message: " + msg.getText());
    producer.send(msg);/*from   w w w  .j a v a 2s .c om*/
    return msg;
}

From source file:org.apache.camel.component.jms.JmsComponent.java

/**
 * Static builder method/*  ww  w  .  ja v  a  2  s  . c o  m*/
 */
public static JmsComponent jmsComponentClientAcknowledge(ConnectionFactory connectionFactory) {
    JmsConfiguration template = new JmsConfiguration(connectionFactory);
    template.setAcknowledgementMode(Session.CLIENT_ACKNOWLEDGE);
    return jmsComponent(template);
}

From source file:com.icesoft.net.messaging.jms.JMSSubscriberConnection.java

public JMSSubscriberConnection(final Topic topic, final JMSAdapter jmsAdapter) throws IllegalArgumentException {
    super(topic, jmsAdapter, Session.CLIENT_ACKNOWLEDGE);
}

From source file:org.jbpm.bpel.tutorial.invoice.ComputePricePT_Impl.java

protected void sendInvoiceMessage(float shippingPrice) throws JMSException {
    ServletContext servletContext = endpointContext.getServletContext();
    Integer orderId = (Integer) servletContext.getAttribute(ORDER_ID_ATTR);
    Float linePrice = (Float) servletContext.getAttribute(LINE_PRICE_ATTR);
    float amount = linePrice.floatValue() + shippingPrice;

    // create a session
    Session jmsSession = jmsConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    try {//from   w  ww . ja v a2s . com
        // create the message
        MapMessage invoiceMessage = jmsSession.createMapMessage();
        invoiceMessage.setInt("orderId", orderId.intValue());
        invoiceMessage.setFloat("amount", amount);

        // send it!
        MessageProducer producer = jmsSession.createProducer(invoiceDestination);
        producer.send(invoiceMessage);

        log.debug("Sent invoice message: orderId=" + orderId + ", amount=" + amount);
    } finally {
        jmsSession.close();
    }
}

From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java

public void testAdaptrisMessageMetadataToJmsCorrelationId_EmptyValue() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    JmsConnection conn = broker.getJmsConnection();
    try {//from w w  w  . j  a v a2 s  .co m
        broker.start();
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        adpMsg.addMetadata(CORRELATIONID_KEY, "");
        TextMessage jmsMsg = session.createTextMessage();
        MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(CORRELATIONID_KEY);
        mcs.processCorrelationId(adpMsg, jmsMsg);
        assertTrue(StringUtils.isEmpty(jmsMsg.getJMSCorrelationID()));
        session.close();
    } finally {
        stop(conn);
        broker.destroy();
    }
}

From source file:com.adaptris.core.jms.activemq.BlobMessageTranslatorTest.java

public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    EmbeddedActiveMq activeMqBroker = new EmbeddedActiveMq();
    JmsConnection conn = null;//w ww.  j  a v a  2  s.  c  om
    try {
        activeMqBroker.start();
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);

        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);
        jmsMsg.setJMSCorrelationID("ABC");
        jmsMsg.setJMSDeliveryMode(1);
        jmsMsg.setJMSPriority(4);
        addProperties(jmsMsg);
        long timestamp = System.currentTimeMillis();
        jmsMsg.setJMSTimestamp(timestamp);

        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        trans.setMoveJmsHeaders(true);
        start(trans);

        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertMetadata(msg);
        assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID));
        assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE));
        assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY));
        assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP));
    } finally {
        stop(trans);
        stop(conn);
        activeMqBroker.destroy();
    }

}