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:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java

public ResponseDispatcher(InitialContext initConn, TopicConnectionFactory connectionFact,
        HashMap<Object, ConsumerProfile> requestMap) {

    ResponseDispatcher.requestMap = requestMap;
    ResponseDispatcher.initConn = initConn;
    try {/*  w w  w  . j ava2  s . com*/
        connection = connectionFact.createTopicConnection();
        publishSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
        e.printStackTrace();
    }
}

From source file:org.jbpm.jms.JmsConnectorService.java

final void sendMessage(Job job) throws JMSException {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {//from w  w w  .  ja  v a 2  s . c  o m
        Message message = session.createMessage();
        populateMessage(message, job);

        MessageProducer messageProducer = session.createProducer(serviceFactory.getDestination());
        messageProducer.send(message);
    } finally {
        // there is no need to close the producers of a closed session
        session.close();
    }
}

From source file:nl.han.dare2date.jms.JMSSubscriber.java

public boolean connect() {
    try {//  w  ww.  j a v  a 2 s. c  om
        context = JMSUtil.getContext();
    } catch (NamingException e) {
        logger.error("Can't create context", e);
        return false;
    } catch (IOException e) {
        logger.error("Can't create context", e);
        return false;
    }

    if (clientID == null) {
        connection = JMSUtil.getConnection();
    } else {
        connection = JMSUtil.getConnection(clientID);
    }

    try {
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
        logger.error("Can't create session", e);
        return false;
    }

    return true;
}

From source file:org.apache.axis2.transport.jms.MockEchoEndpoint.java

@Setup
@SuppressWarnings("unused")
private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception {
    Destination destination = channel.getDestination();
    Destination replyDestination = channel.getReplyDestination();
    connection = env.getConnectionFactory().createConnection();
    connection.setExceptionListener(this);
    connection.start();/*from  ww w  .ja v a  2  s .  com*/
    replyConnection = env.getConnectionFactory().createConnection();
    replyConnection.setExceptionListener(this);
    final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final MessageProducer producer = replySession.createProducer(replyDestination);
    MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
            .createConsumer(destination);
    consumer.setMessageListener(new MessageListener() {
        public void onMessage(Message message) {
            try {
                log.info("Message received: ID = " + message.getJMSMessageID());
                Message reply;
                if (message instanceof BytesMessage) {
                    reply = replySession.createBytesMessage();
                    IOUtils.copy(new BytesMessageInputStream((BytesMessage) message),
                            new BytesMessageOutputStream((BytesMessage) reply));
                } else if (message instanceof TextMessage) {
                    reply = replySession.createTextMessage();
                    ((TextMessage) reply).setText(((TextMessage) message).getText());
                } else {
                    // TODO
                    throw new UnsupportedOperationException("Unsupported message type");
                }
                reply.setJMSCorrelationID(message.getJMSMessageID());
                reply.setStringProperty(BaseConstants.CONTENT_TYPE,
                        message.getStringProperty(BaseConstants.CONTENT_TYPE));
                producer.send(reply);
                log.info("Message sent: ID = " + reply.getJMSMessageID());
            } catch (Throwable ex) {
                fireEndpointError(ex);
            }
        }
    });
}

From source file:com.jim.im.group.config.GatewayUserRegisterConfig.java

@Bean
public MessageListenerContainer hornetQMessageListenerContainer() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(TransportConstants.HOST_PROP_NAME, hornetq_host);
    map.put(TransportConstants.PORT_PROP_NAME, hornetq_port);
    TransportConfiguration transportConfiguration = new TransportConfiguration(
            NettyConnectorFactory.class.getName(), map);

    HornetQConnectionFactory hornetQConnectionFactory = HornetQJMSClient
            .createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);

    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    container.setConnectionFactory((ConnectionFactory) hornetQConnectionFactory);
    container.setDestination(HornetQJMSClient.createTopic(IMConstant.GATEWAY_USERREGISTER_TOPIC));
    container.setPubSubDomain(true);/*ww  w.  ja  va 2  s  . c  o  m*/
    container.setPubSubNoLocal(true);
    container.setMessageListener(userRegisterListener);
    container.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
    return container;
}

From source file:org.wso2.carbon.automation.extensions.servers.jmsserver.client.JMSTopicMessageConsumer.java

/**
 * This will subscribe with a given topic and started to listen messages from the topic
 *
 * @param topicName name of the topic/*w  ww  . j a  v a 2  s .  c  o m*/
 * @throws JMSException
 * @throws javax.naming.NamingException
 */
public void subscribe(String topicName) throws JMSException, NamingException {
    // Create a Connection
    connection = connectionFactory.createTopicConnection();
    // Create a Session
    session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create a MessageConsumer from the Session to the Topic or Queue
    topic = session.createTopic(topicName);
    consumer = session.createSubscriber(topic);
    consumer.setMessageListener(this);
    connection.start();
}

From source file:com.jaliansystems.activeMQLite.impl.RepositoryClient.java

/**
 * Instantiates a new repository client.
 * /*from ww  w.  ja v  a  2  s .  c om*/
 * @param connection
 *            the connection
 * @param brokerURL
 *            the broker url
 * @param objectRepository
 *            the object repository
 * @throws Exception
 *             the exception
 */
public RepositoryClient(Connection connection, String brokerURL, ObjectRepository objectRepository)
        throws Exception {
    this.objectRepository = objectRepository;

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

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

    responseQueue = session.createTemporaryQueue();
    responseConsumer = session.createConsumer(responseQueue);
    responseConsumer.setMessageListener(this);
}

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  www  .  j av  a2  s .co m
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createConsumer(dest);
}

From source file:org.eclipse.smila.connectivity.queue.worker.internal.task.impl.Send.java

/**
 * {@inheritDoc}/*w ww . j av a 2  s.  co  m*/
 * 
 */
@Override
public String[] executeInternal(final TaskExecutionEnv env, final SendType config,
        final Map<String, Properties> idPropertyMap)
        throws TaskExecutionException, BlackboardAccessException, RecordFilterNotFoundException {
    Connection connection = null;
    Session session = null;
    try {
        // get cached connection, if do not cache connections -> socket error when many records pushed
        connection = env.getServices().getBrokerConnections().getConnection(config, true);
        connection.start();
        session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        final Destination destination = session.createQueue(config.getQueue());
        final MessageProducer producer = session.createProducer(destination);
        if (config.isPersistentDelivery()) {
            producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        } else {
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        }

        final Iterator<Entry<String, Properties>> entries = idPropertyMap.entrySet().iterator();
        while (entries.hasNext()) {
            final Entry<String, Properties> entry = entries.next();
            // get message record, optionally a filtered copy.
            final Record record = createMessageRecord(entry.getKey(), config, env);
            // prepare queue message. messages are actually sent on session.commit() below.
            producer.send(createMessage(config, record, entry.getValue(), session));
        }

        // we must commit here so that the message consumer find the correct record version in storages.
        env.getBlackboard().commit();
        env.setCommitRequired(false);
        // finally send the messages.
        session.commit();

        return idPropertyMap.keySet().toArray(new String[idPropertyMap.size()]);
    } catch (final Throwable e) {
        _log.error(msg("Error"), e);
        rollbackQuietly(session);
        throw new TaskExecutionException(e);
    } finally {
        closeQuietly(session);
        closeQuietly(connection);
    }
}

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 .  java2s .c  o  m
    }
}